Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytests #15

Merged
merged 21 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for get_all_item_details
  • Loading branch information
tr4nt0r committed Apr 5, 2024
commit 25f191a201bb2b6d493bc19969266c5e134345f5
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@
},
}

BRING_GET_ALL_ITEM_DETAILS_RESPONSE = [
{
"uuid": "bfb5634c-d219-4d66-b68e-1388e54f0bb0",
"itemId": "Milchreis",
"listUuid": UUID,
"userIconItemId": "Reis",
"userSectionId": "Getreideprodukte",
"assignedTo": "",
"imageUrl": "",
},
{
"uuid": "0056b23c-7fc3-44da-8c34-426f8b632220",
"itemId": "Zitronensaft",
"listUuid": UUID,
"userIconItemId": "Zitrone",
"userSectionId": "Zutaten & Gewürze",
"assignedTo": "",
"imageUrl": "",
},
]


@pytest.fixture(name="session")
async def aiohttp_client_session():
Expand All @@ -98,12 +119,15 @@ def aioclient_mock():


async def mocked_get_user_account(*args, **kwargs):
"""Mock __get_user_account."""
return {"userLocale": {"language": "de", "country": "DE"}}


async def mocked__load_user_list_settings(*args, **kwargs):
"""Mock __load_user_list_settings."""
return {UUID: {"listArticleLanguage": "de-DE"}}


async def mocked__load_article_translations(*args, **kwargs):
"""Mock __load_article_translations."""
return {}
63 changes: 60 additions & 3 deletions tests/test_bring.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from bring_api.types import BringNotificationType

from .conftest import (
BRING_GET_ALL_ITEM_DETAILS_RESPONSE,
BRING_GET_LIST_RESPONSE,
BRING_LOAD_LISTS_RESPONSE,
BRING_LOGIN_RESPONSE,
Expand Down Expand Up @@ -107,7 +108,7 @@ async def test_parse_exception(self, mocked, bring):
"https://api.getbring.com/rest/v2/bringauth",
status=200,
body="not json",
headers={"content-type": "application/json"},
content_type="application/json",
)

with pytest.raises(BringParseException):
Expand Down Expand Up @@ -177,7 +178,7 @@ async def test_parse_exception(self, mocked, bring, monkeypatch):
f"https://api.getbring.com/rest/bringusers/{UUID}/lists",
status=200,
body="not json",
headers={"content-type": "application/json"},
content_type="application/json",
)
monkeypatch.setattr(bring, "uuid", UUID)

Expand Down Expand Up @@ -312,7 +313,7 @@ async def test_parse_exception(self, mocked, bring, monkeypatch):
f"https://api.getbring.com/rest/v2/bringlists/{UUID}",
status=200,
body="not json",
headers={"content-type": "application/json"},
content_type="application/json",
)
monkeypatch.setattr(bring, "uuid", UUID)

Expand Down Expand Up @@ -340,3 +341,59 @@ def mocked_translate(bring: Bring, item_id: str, *args, **kwargs) -> str:

data = await bring.get_list(UUID)
assert data == BRING_GET_LIST_RESPONSE["items"]


class TestGetAllItemDetails:
"""Test for get_all_item_details method."""

async def test_get_all_item_details(self, mocked, bring):
"""Test get_all_item_details."""
mocked.get(
f"https://api.getbring.com/rest/bringlists/{UUID}/details",
status=200,
payload=BRING_GET_ALL_ITEM_DETAILS_RESPONSE,
)

data = await bring.get_all_item_details(UUID)
assert data == BRING_GET_ALL_ITEM_DETAILS_RESPONSE

async def test_list_not_found(self, mocked, bring):
"""Test get_all_item_details."""
mocked.get(
f"https://api.getbring.com/rest/bringlists/{UUID}/details",
status=404,
reason=f"List with uuid '{UUID}' not found",
)

with pytest.raises(BringRequestException):
await bring.get_all_item_details(UUID)

async def test_parse_exception(self, mocked, bring):
"""Test parse exceptions."""
mocked.get(
f"https://api.getbring.com/rest/bringlists/{UUID}/details",
status=200,
body="not json",
content_type="application/json",
)

with pytest.raises(BringParseException):
await bring.get_all_item_details(UUID)

@pytest.mark.parametrize(
"exception",
[
asyncio.TimeoutError,
aiohttp.ClientError,
],
)
async def test_request_exception(self, mocked, bring, exception):
"""Test request exceptions."""

mocked.get(
f"https://api.getbring.com/rest/v2/bringlists/{UUID}",
exception=exception,
)

with pytest.raises(BringRequestException):
await bring.get_all_item_details(UUID)