Coverage for src/tests/api/v1/test_presenters.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing the common JSON:API schemas.""" 

2 

3import json 

4 

5from typing import Any 

6 

7from deepdiff import DeepDiff 

8from kwai_api.v1.presenters import JsonApiCountryPresenter 

9from kwai_bc_club.domain.country import CountryEntity 

10 

11 

12def test_country_presenter( 

13 country: CountryEntity, expected_country_json: dict[str, Any] 

14): 

15 """Test the creation of a document with a Country resource.""" 

16 country_presenter = JsonApiCountryPresenter() 

17 country_presenter.present(country) 

18 country_document = country_presenter.get_document() 

19 json_resource = json.loads(country_document.model_dump_json()) 

20 

21 diff = DeepDiff(json_resource, expected_country_json, ignore_order=True) 

22 assert not diff, f"JSON structure is not as expected: {diff}"