Skip to content

Commit 34659a9

Browse files
committed
Updated generic resource and tests
1 parent f7e44cd commit 34659a9

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

tests/http/models/test_genric_resource.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def meta_data():
1111

1212
def test_generic_resource_empty():
1313
resource = GenericResource()
14+
1415
assert resource.meta is None
1516
assert resource.to_dict() == {}
1617

@@ -26,23 +27,13 @@ def test_from_response(meta_data):
2627
assert resource.meta == expected_meta
2728

2829

29-
def test_attribute_access():
30+
def test_attribute_getter(mocker, meta_data):
3031
resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}}
31-
meta = Meta.from_response(Response(200, json={"$meta": {}}))
32-
resource = GenericResource(resource_data=resource_data, meta=meta)
33-
34-
assert resource.meta == meta
32+
response = Response(200, json={"data": resource_data, "$meta": meta_data})
33+
resource = GenericResource.from_response(response)
3534

3635
assert resource.id == 1
37-
38-
with pytest.raises(AttributeError, match=r"'Box' object has no attribute 'address'"):
39-
resource.address # noqa: B018
40-
41-
with pytest.raises(AttributeError, match=r"'Box' object has no attribute 'surname'"):
42-
resource.name.surname # noqa: B018
43-
4436
assert resource.name.given == "Albert"
45-
assert resource.name.to_dict() == resource_data["name"]
4637

4738

4839
def test_attribute_setter():

tests/http/models/test_pagination.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,14 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next):
3737
mocker.patch.object(pagination, "num_page", return_value=num_page)
3838
mocker.patch.object(pagination, "total_pages", return_value=total_pages)
3939

40-
assert pagination.has_next() == expected_has_next
40+
has_next = pagination.has_next()
41+
42+
assert has_next == expected_has_next
4143

4244

4345
@pytest.mark.parametrize(
4446
("limit", "offset", "expected_page"),
45-
[
46-
(0, 0, 0),
47-
(1, 0, 0),
48-
(5, 5, 1),
49-
(10, 990, 99),
50-
(245, 238, 0)
51-
],
47+
[(0, 0, 0), (1, 0, 0), (5, 5, 1), (10, 990, 99), (245, 238, 0)], # noqa: WPS221
5248
)
5349
def test_num_page(limit, offset, expected_page):
5450
pagination = Pagination(limit=limit, offset=offset, total=5)

0 commit comments

Comments
 (0)