Coverage for tests/tests_api/organizations/organization.py: 32%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.2, created at 2024-10-10 03:02 +0300

1import pytest 

2from sotrans_models.models.organizations import OrganizationDBModel 

3from sotrans_models.models.responses import ( 

4 GenericGetListResponse, 

5 ProfileCompletionResponse, 

6) 

7 

8from ...conftest import APIDataStorage 

9from ...tests_api.auth import test_client, token 

10from ..fixtures import tmp_org 

11 

12 

13@pytest.mark.skip # seems like http client bug, try mock dadata? 

14async def test_create_org_positive(existing_inn, test_client): 

15 response = test_client.post( 

16 "/organizations", 

17 json={"inn": existing_inn}, 

18 ) 

19 assert response.status_code == 201 

20 

21 APIDataStorage.org = OrganizationDBModel(**response.json()) 

22 

23 

24def test_get_org(test_client, tmp_org): 

25 response = test_client.get( 

26 f"/organizations/{tmp_org.id}", 

27 ) 

28 assert response.status_code == 200 

29 assert OrganizationDBModel(**response.json()).inn == tmp_org.inn 

30 

31 

32def test_update_org(test_client, tmp_org): 

33 response = test_client.patch( 

34 f"/organizations/{tmp_org.id}", 

35 json={"short_name": "APITest"}, 

36 ) 

37 assert response.status_code == 200 

38 updated = OrganizationDBModel(**response.json()) 

39 assert updated.short_name == "APITest" 

40 

41 

42def test_org_completion(test_client, tmp_org): 

43 response = test_client.get(f"/organizations/{tmp_org.id}/completion") 

44 assert response.status_code == 200 

45 ProfileCompletionResponse(**response.json()) 

46 

47 

48def test_orgs_list(test_client, tmp_org): 

49 response = test_client.get("/organizations") 

50 assert response.status_code == 200 

51 received = GenericGetListResponse[OrganizationDBModel](**response.json()) 

52 assert received.total > 0 

53 for o in received.items: 

54 if o.id == tmp_org.id: 

55 return 

56 assert False