Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 6 additions & 14 deletions tests/http/models/test_genric_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def meta_data():

def test_generic_resource_empty():
resource = GenericResource()

assert resource.meta is None
assert resource.to_dict() == {}

Expand All @@ -26,33 +27,24 @@ 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():
resource_data = {"id": 1, "name": {"given": "Albert", "family": "Einstein"}}
resource = GenericResource(resource_data)

resource.id = 2
assert resource.id == 2

resource.name.given = "John"

assert resource.id == 2
assert resource.name.given == "John"


Expand Down
8 changes: 0 additions & 8 deletions tests/http/models/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions tests/http/models/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down