Skip to content

Commit 0173203

Browse files
committed
fix tests
1 parent 4a45844 commit 0173203

17 files changed

+287
-973
lines changed

bring_api/bring.py

Lines changed: 100 additions & 467 deletions
Large diffs are not rendered by default.

bring_api/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from dataclasses import dataclass, field
44
from datetime import datetime
55
from enum import StrEnum
6-
from typing import Literal, NotRequired, TypedDict
6+
from typing import Literal, NotRequired, TypedDict, TypeVar
77

88
from mashumaro.mixins.orjson import DataClassORJSONMixin
99

10+
BringResponse = TypeVar("BringResponse", bound=DataClassORJSONMixin)
11+
1012

1113
class ActivityType(StrEnum):
1214
"""Activity type."""

tests/test_batch_update_list.py

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
"""Tests for batch_update_list."""
22

3-
import asyncio
4-
from http import HTTPStatus
53
from typing import Any
64

7-
import aiohttp
85
from aioresponses import aioresponses
96
import pytest
107

11-
from bring_api import (
12-
Bring,
13-
BringAuthException,
14-
BringItem,
15-
BringItemOperation,
16-
BringRequestException,
17-
)
8+
from bring_api import Bring, BringItem, BringItemOperation
189

19-
from .conftest import DEFAULT_HEADERS, UUID, load_fixture
10+
from .conftest import DEFAULT_HEADERS, UUID
2011

2112

2213
@pytest.mark.parametrize(
@@ -400,14 +391,12 @@ async def test_batch_update_list_single_item(
400391
) -> None:
401392
"""Test batch_update_list."""
402393
await bring.login()
403-
r = await bring.batch_update_list(UUID, item, operation)
394+
await bring.batch_update_list(UUID, item, operation)
404395

405-
assert r.status == HTTPStatus.OK
406396
mocked.assert_called_with(
407397
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
408398
method="PUT",
409399
headers=DEFAULT_HEADERS,
410-
data=None,
411400
json=payload,
412401
)
413402

@@ -474,78 +463,11 @@ async def test_batch_update_list_multiple_items(
474463
"sender": "",
475464
}
476465
await bring.login()
477-
r = await bring.batch_update_list(UUID, test_items)
466+
await bring.batch_update_list(UUID, test_items)
478467

479-
assert r.status == HTTPStatus.OK
480468
mocked.assert_called_with(
481469
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
482470
method="PUT",
483471
headers=DEFAULT_HEADERS,
484-
data=None,
485472
json=payload,
486473
)
487-
488-
489-
@pytest.mark.parametrize(
490-
"exception",
491-
[
492-
asyncio.TimeoutError,
493-
aiohttp.ClientError,
494-
],
495-
)
496-
async def test_request_exception(
497-
mocked: aioresponses,
498-
bring: Bring,
499-
exception: type[Exception],
500-
) -> None:
501-
"""Test request exceptions."""
502-
await bring.login()
503-
mocked.clear()
504-
mocked.put(
505-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
506-
exception=exception,
507-
)
508-
509-
with pytest.raises(BringRequestException):
510-
await bring.batch_update_list(
511-
UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID)
512-
)
513-
514-
515-
async def test_unauthorized(
516-
mocked: aioresponses,
517-
bring: Bring,
518-
) -> None:
519-
"""Test unauthorized exception."""
520-
await bring.login()
521-
mocked.clear()
522-
mocked.put(
523-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
524-
status=HTTPStatus.UNAUTHORIZED,
525-
body=load_fixture("error_response.json"),
526-
)
527-
528-
with pytest.raises(BringAuthException):
529-
await bring.batch_update_list(
530-
UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID)
531-
)
532-
533-
534-
async def test_parse_exception(
535-
mocked: aioresponses,
536-
bring: Bring,
537-
) -> None:
538-
"""Test parse exceptions."""
539-
await bring.login()
540-
mocked.clear()
541-
mocked.put(
542-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
543-
status=HTTPStatus.UNAUTHORIZED,
544-
body="not json",
545-
content_type="application/json",
546-
)
547-
548-
with pytest.raises(BringAuthException):
549-
await bring.batch_update_list(
550-
UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID)
551-
)

tests/test_complete_item.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ async def test_complete_item(
9393
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items",
9494
method="PUT",
9595
headers=DEFAULT_HEADERS,
96-
data=None,
9796
json=payload,
9897
)
9998

tests/test_get_activity.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
"""Tests for get_activity method."""
22

3-
import asyncio
43
from http import HTTPStatus
54

6-
import aiohttp
75
from aioresponses import aioresponses
86
import pytest
97
from syrupy.assertion import SnapshotAssertion
108

11-
from bring_api import (
12-
Bring,
13-
BringAuthException,
14-
BringParseException,
15-
BringRequestException,
16-
)
9+
from bring_api import Bring, BringAuthException, BringParseException
1710

18-
from .conftest import UUID, load_fixture
11+
from .conftest import UUID
1912

2013

2114
@pytest.mark.usefixtures("mocked")
@@ -30,47 +23,6 @@ async def test_get_activity(
3023
assert activity == snapshot
3124

3225

33-
@pytest.mark.parametrize(
34-
"exception",
35-
[
36-
asyncio.TimeoutError,
37-
aiohttp.ClientError,
38-
],
39-
)
40-
async def test_request_exception(
41-
mocked: aioresponses,
42-
bring: Bring,
43-
exception: type[Exception],
44-
) -> None:
45-
"""Test request exceptions."""
46-
await bring.login()
47-
mocked.clear()
48-
mocked.get(
49-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/activity",
50-
exception=exception,
51-
)
52-
53-
with pytest.raises(BringRequestException):
54-
await bring.get_activity(UUID)
55-
56-
57-
async def test_auth_exception(
58-
mocked: aioresponses,
59-
bring: Bring,
60-
) -> None:
61-
"""Test request exceptions."""
62-
await bring.login()
63-
mocked.clear()
64-
mocked.get(
65-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}/activity",
66-
status=HTTPStatus.UNAUTHORIZED,
67-
body=load_fixture("error_response.json"),
68-
)
69-
70-
with pytest.raises(BringAuthException):
71-
await bring.get_activity(UUID)
72-
73-
7426
@pytest.mark.parametrize(
7527
("status", "exception"),
7628
[

tests/test_get_all_user_settings.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Tests for get_all_user_settings method."""
22

3-
import asyncio
43
from http import HTTPStatus
54
from unittest.mock import patch
65

7-
import aiohttp
86
from aioresponses import aioresponses
97
import pytest
108
from syrupy.assertion import SnapshotAssertion
@@ -17,7 +15,7 @@
1715
BringTranslationException,
1816
)
1917

20-
from .conftest import UUID, load_fixture
18+
from .conftest import UUID
2119

2220

2321
@pytest.mark.usefixtures("mocked")
@@ -32,47 +30,6 @@ async def test_get_all_user_settings(
3230
assert data == snapshot
3331

3432

35-
@pytest.mark.parametrize(
36-
"exception",
37-
[
38-
asyncio.TimeoutError,
39-
aiohttp.ClientError,
40-
],
41-
)
42-
async def test_request_exception(
43-
mocked: aioresponses,
44-
bring: Bring,
45-
exception: type[Exception],
46-
) -> None:
47-
"""Test request exceptions."""
48-
await bring.login()
49-
mocked.clear()
50-
mocked.get(
51-
f"https://api.getbring.com/rest/bringusersettings/{UUID}",
52-
exception=exception,
53-
)
54-
55-
with pytest.raises(BringRequestException):
56-
await bring.get_all_user_settings()
57-
58-
59-
async def test_unauthorized(
60-
mocked: aioresponses,
61-
bring: Bring,
62-
) -> None:
63-
"""Test unauthorized exception."""
64-
await bring.login()
65-
mocked.clear()
66-
mocked.get(
67-
f"https://api.getbring.com/rest/bringusersettings/{UUID}",
68-
status=HTTPStatus.UNAUTHORIZED,
69-
body=load_fixture("error_response.json"),
70-
)
71-
72-
with pytest.raises(BringAuthException):
73-
await bring.get_all_user_settings()
74-
75-
7633
@pytest.mark.parametrize(
7734
("status", "exception"),
7835
[

tests/test_get_list.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
"""Tests for get_list method."""
22

3-
import asyncio
43
from http import HTTPStatus
54

6-
import aiohttp
75
from aioresponses import aioresponses
86
import pytest
97
from syrupy.assertion import SnapshotAssertion
108

11-
from bring_api import (
12-
Bring,
13-
BringAuthException,
14-
BringParseException,
15-
BringRequestException,
16-
)
9+
from bring_api import Bring, BringAuthException, BringParseException
1710

18-
from .conftest import UUID, load_fixture
11+
from .conftest import UUID
1912

2013

2114
@pytest.mark.usefixtures("mocked")
@@ -30,46 +23,6 @@ async def test_get_list(
3023
assert data == snapshot
3124

3225

33-
@pytest.mark.parametrize(
34-
"exception",
35-
[
36-
asyncio.TimeoutError,
37-
aiohttp.ClientError,
38-
],
39-
)
40-
async def test_request_exception(
41-
mocked: aioresponses,
42-
bring: Bring,
43-
exception: type[Exception],
44-
) -> None:
45-
"""Test request exceptions."""
46-
await bring.login()
47-
mocked.clear()
48-
mocked.get(
49-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}",
50-
exception=exception,
51-
)
52-
53-
with pytest.raises(BringRequestException):
54-
await bring.get_list(UUID)
55-
56-
57-
async def test_unauthorized(
58-
mocked: aioresponses,
59-
bring: Bring,
60-
) -> None:
61-
"""Test unauthorized exception."""
62-
await bring.login()
63-
mocked.clear()
64-
mocked.get(
65-
f"https://api.getbring.com/rest/v2/bringlists/{UUID}",
66-
status=HTTPStatus.UNAUTHORIZED,
67-
body=load_fixture("error_response.json"),
68-
)
69-
with pytest.raises(BringAuthException):
70-
await bring.get_list(UUID)
71-
72-
7326
@pytest.mark.parametrize(
7427
("status", "exception"),
7528
[

0 commit comments

Comments
 (0)