forked from Roslovets-Inc/strapi-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): test get_entry and get_entries
- Loading branch information
Showing
13 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ jobs: | |
- name: Test | ||
run: | | ||
python -m pytest | ||
python -m pytest test/unittests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
asyncio_mode = auto |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
from typing import Any, Type | ||
|
||
from test.types import AnyStrapiClient | ||
from pystrapi.strapi_client import StrapiClient | ||
from pystrapi.strapi_client_sync import StrapiClientSync | ||
|
||
|
||
@pytest.fixture(params=[StrapiClientSync, StrapiClient]) | ||
def client(request: Any) -> AnyStrapiClient: | ||
client_type: Type[AnyStrapiClient] = request.param | ||
return client_type() | ||
|
||
|
||
@pytest.fixture | ||
def post1() -> dict: | ||
return { | ||
"id": 1, | ||
"attributes": { | ||
"description": "The first post", | ||
"content": "Hello", | ||
"title": "First Post", | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def post2() -> dict: | ||
return { | ||
"id": 2, | ||
"attributes": { | ||
"description": "The second post", | ||
"content": "Hello again", | ||
"title": "Second Post" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from test.types import AnyStrapiClient | ||
from test.utils import asyncutils | ||
from pystrapi.types import StrapiEntriesResponse, StrapiEntryResponse | ||
|
||
from pydash.predicates import is_match # type: ignore | ||
|
||
|
||
async def test_get_entry(client: AnyStrapiClient, post1: dict) -> None: | ||
res: StrapiEntryResponse = await asyncutils.value(client.get_entry('posts', 1)) | ||
assert is_match(res['data'], post1) | ||
|
||
|
||
async def test_get_entries(client: AnyStrapiClient, post1: dict, post2: dict) -> None: | ||
res: StrapiEntriesResponse = await asyncutils.value(client.get_entries('posts')) | ||
assert res['data'] | ||
assert is_match(res['data'][0], post1) | ||
assert is_match(res['data'][1], post2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from typing import Union | ||
|
||
from pystrapi.strapi_client import StrapiClient | ||
from pystrapi.strapi_client_sync import StrapiClientSync | ||
|
||
AnyStrapiClient = Union[StrapiClientSync, StrapiClient] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import inspect | ||
from typing import Any, Coroutine, TypeVar, Union | ||
|
||
|
||
V = TypeVar("V", bound="Any") | ||
|
||
|
||
async def value(val: Union[V, Coroutine[Any, Any, V]]) -> V: | ||
""" | ||
Return the given value. await if it's awaitable. | ||
""" | ||
if inspect.isawaitable(val): | ||
return await val # type: ignore | ||
return val # type: ignore |