Skip to content

Commit 0e77310

Browse files
committed
coverage for disable_collection_count and default_collection_count
1 parent 46df5de commit 0e77310

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_sqlalchemy_data_layer.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,23 @@ class ComputerList(ResourceList):
437437
yield ComputerList
438438

439439

440+
@pytest.fixture(scope="module")
441+
def fixed_count_for_collection_count():
442+
return 42
443+
444+
445+
@pytest.fixture(scope="module")
446+
def computer_list_resource_with_disable_collection_count(
447+
session, computer_model, computer_schema, fixed_count_for_collection_count
448+
):
449+
class ComputerList(ResourceList):
450+
disable_collection_count = True, fixed_count_for_collection_count
451+
schema = computer_schema
452+
data_layer = {"model": computer_model, "session": session}
453+
454+
yield ComputerList
455+
456+
440457
@pytest.fixture(scope="module")
441458
def computer_detail(session, computer_model, dummy_decorator, computer_schema):
442459
class ComputerDetail(ResourceDetail):
@@ -496,6 +513,7 @@ def register_routes(
496513
person_list_without_schema,
497514
computer_list,
498515
computer_detail,
516+
computer_list_resource_with_disable_collection_count,
499517
computer_owner,
500518
string_json_attribute_person_detail,
501519
string_json_attribute_person_list,
@@ -510,6 +528,12 @@ def register_routes(
510528
api.route(person_list_raise_exception, "person_list_exception", "/persons_exception")
511529
api.route(person_list_response, "person_list_response", "/persons_response")
512530
api.route(person_list_without_schema, "person_list_without_schema", "/persons_without_schema")
531+
api.route(
532+
computer_list_resource_with_disable_collection_count,
533+
"computer_list_with_disabled_count",
534+
"/computers_with_disabled_count",
535+
"/persons/<int:person_id>/computers_with_disabled_count",
536+
)
513537
api.route(computer_list, "computer_list", "/computers", "/persons/<int:person_id>/computers")
514538
api.route(computer_detail, "computer_detail", "/computers/<int:id>")
515539
api.route(computer_owner, "computer_owner", "/computers/<int:id>/relationships/owner")
@@ -1684,3 +1708,15 @@ def test_relationship_containing_hyphens(client, register_routes, person_compute
16841708
f"/persons/{person.person_id}/relationships/computers-owned", content_type="application/vnd.api+json"
16851709
)
16861710
assert response.status_code == 200
1711+
1712+
1713+
def test__sqlalchemy_data_layer__disable_collection_count(client, fixed_count_for_collection_count):
1714+
"""
1715+
:param client:
1716+
:param fixed_count_for_collection_count:
1717+
:return:
1718+
"""
1719+
response = client.get(f"/computers_with_disabled_count", content_type="application/vnd.api+json")
1720+
assert response.status_code == 200
1721+
assert response.json
1722+
assert response.json["meta"]["count"] == fixed_count_for_collection_count

0 commit comments

Comments
 (0)