From f53b2917ea5bc009c83f53a754a159e7d672d453 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Mon, 4 Aug 2025 14:00:02 +0100 Subject: [PATCH] Updated generic resource and tests --- tests/http/models/test_genric_resource.py | 20 ++++++-------------- tests/http/models/test_meta.py | 8 -------- tests/http/models/test_pagination.py | 6 ++++-- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/tests/http/models/test_genric_resource.py b/tests/http/models/test_genric_resource.py index 321ce560..1754c51d 100644 --- a/tests/http/models/test_genric_resource.py +++ b/tests/http/models/test_genric_resource.py @@ -11,6 +11,7 @@ def meta_data(): def test_generic_resource_empty(): resource = GenericResource() + assert resource.meta is None assert resource.to_dict() == {} @@ -26,23 +27,14 @@ def test_from_response(meta_data): assert resource.meta == expected_meta -def test_attribute_access(): +def test_attribute_getter(mocker, meta_data): resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}} - meta = Meta.from_response(Response(200, json={"$meta": {}})) - resource = GenericResource(resource_data=resource_data, meta=meta) + response = Response(200, json={"data": resource_data, "$meta": meta_data}) - assert resource.meta == meta + resource = GenericResource.from_response(response) assert resource.id == 1 - - with pytest.raises(AttributeError, match=r"'Box' object has no attribute 'address'"): - resource.address # noqa: B018 - - with pytest.raises(AttributeError, match=r"'Box' object has no attribute 'surname'"): - resource.name.surname # noqa: B018 - assert resource.name.given == "Albert" - assert resource.name.to_dict() == resource_data["name"] def test_attribute_setter(): @@ -50,9 +42,9 @@ def test_attribute_setter(): resource = GenericResource(resource_data) resource.id = 2 - assert resource.id == 2 - resource.name.given = "John" + + assert resource.id == 2 assert resource.name.given == "John" diff --git a/tests/http/models/test_meta.py b/tests/http/models/test_meta.py index d31effdf..c558ff3a 100644 --- a/tests/http/models/test_meta.py +++ b/tests/http/models/test_meta.py @@ -31,11 +31,3 @@ def test_meta_from_response(responses_fixture): def test_invalid_meta_from_response(invalid_response_fixture): with pytest.raises(TypeError, match=r"Response \$meta must be a dict."): Meta.from_response(invalid_response_fixture) - - -def test_meta_with_pagination_object(): - response = Response(status_code=200, json={}) - pagination = Pagination(limit=10, offset=0, total=100) - meta = Meta(response=response, pagination=pagination) - - assert meta.pagination == Pagination(limit=10, offset=0, total=100) diff --git a/tests/http/models/test_pagination.py b/tests/http/models/test_pagination.py index d165dbf9..67db71d4 100644 --- a/tests/http/models/test_pagination.py +++ b/tests/http/models/test_pagination.py @@ -37,7 +37,9 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next): mocker.patch.object(pagination, "num_page", return_value=num_page) mocker.patch.object(pagination, "total_pages", return_value=total_pages) - assert pagination.has_next() == expected_has_next + has_next = pagination.has_next() + + assert has_next == expected_has_next @pytest.mark.parametrize( @@ -47,7 +49,7 @@ def test_has_next(mocker, num_page, total_pages, expected_has_next): (1, 0, 0), (5, 5, 1), (10, 990, 99), - (245, 238, 0) + (245, 238, 0), ], ) def test_num_page(limit, offset, expected_page):