Skip to content

Commit f53b291

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

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

tests/http/models/test_genric_resource.py

Lines changed: 6 additions & 14 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,33 +27,24 @@ 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)
32+
response = Response(200, json={"data": resource_data, "$meta": meta_data})
3333

34-
assert resource.meta == meta
34+
resource = GenericResource.from_response(response)
3535

3636
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-
4437
assert resource.name.given == "Albert"
45-
assert resource.name.to_dict() == resource_data["name"]
4638

4739

4840
def test_attribute_setter():
4941
resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}}
5042
resource = GenericResource(resource_data)
5143

5244
resource.id = 2
53-
assert resource.id == 2
54-
5545
resource.name.given = "John"
46+
47+
assert resource.id == 2
5648
assert resource.name.given == "John"
5749

5850

tests/http/models/test_meta.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,3 @@ def test_meta_from_response(responses_fixture):
3131
def test_invalid_meta_from_response(invalid_response_fixture):
3232
with pytest.raises(TypeError, match=r"Response \$meta must be a dict."):
3333
Meta.from_response(invalid_response_fixture)
34-
35-
36-
def test_meta_with_pagination_object():
37-
response = Response(status_code=200, json={})
38-
pagination = Pagination(limit=10, offset=0, total=100)
39-
meta = Meta(response=response, pagination=pagination)
40-
41-
assert meta.pagination == Pagination(limit=10, offset=0, total=100)

tests/http/models/test_pagination.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ 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(
@@ -47,7 +49,7 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next):
4749
(1, 0, 0),
4850
(5, 5, 1),
4951
(10, 990, 99),
50-
(245, 238, 0)
52+
(245, 238, 0),
5153
],
5254
)
5355
def test_num_page(limit, offset, expected_page):

0 commit comments

Comments
 (0)