Coverage for tests\test_delete_api_projects.py: 100.00%

26 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-22 23:23 +0100

1# -*- coding: utf-8 -*- 

2 

3""" 

4* Name: interactive-clustering-gui/tests/test_delete_api_projects.py 

5* Description: Unittests for `app` module on the `DELETE /api/projects` route. 

6* Author: Erwan Schild 

7* Created: 22/02/2022 

8* Licence: CeCILL (https://cecill.info/licences.fr.html) 

9""" 

10 

11# ============================================================================== 

12# IMPORT PYTHON DEPENDENCIES 

13# ============================================================================== 

14 

15import pytest 

16 

17from tests.dummies_utils import create_dummy_projects 

18 

19# ============================================================================== 

20# test_delete_api_projects_ok 

21# ============================================================================== 

22 

23 

24@pytest.mark.asyncio() 

25async def test_ok(async_client, tmp_path): 

26 """ 

27 Test the `DELETE /api/projects` route. 

28 

29 Arguments: 

30 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

31 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

32 """ 

33 # Assert HTTP client is created. 

34 assert async_client 

35 

36 # Create dummy projects. 

37 create_dummy_projects( 

38 tmp_path=tmp_path, 

39 list_of_dummy_project_ids=[ 

40 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

41 "0e_CLUSTERING_PENDING", 

42 ], 

43 ) 

44 

45 # Assert route `DELETE /api/projects` works. 

46 response_delete = await async_client.delete( 

47 url="/api/projects/0e_CLUSTERING_PENDING", 

48 ) 

49 assert response_delete.status_code == 202 

50 assert list(response_delete.json().keys()) == ["project_id", "detail"] 

51 assert response_delete.json()["project_id"] == "0e_CLUSTERING_PENDING" 

52 assert response_delete.json()["detail"] == "The deletion of project with id '0e_CLUSTERING_PENDING' is accepted." 

53 

54 # Assert route `GET /api/projects` is now smaller. 

55 response_get = await async_client.get(url="/api/projects") 

56 assert response_get.status_code == 200 

57 assert response_get.json() == [ 

58 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

59 ] 

60 

61 

62# ============================================================================== 

63# test_ok_not_existing 

64# ============================================================================== 

65 

66 

67@pytest.mark.asyncio() 

68async def test_ok_not_existing(async_client): 

69 """ 

70 Test the `DELETE /api/projects` route. 

71 

72 Arguments: 

73 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

74 """ 

75 # Assert HTTP client is created. 

76 assert async_client 

77 

78 # Assert route `DELETE /api/projects` works. 

79 response_delete = await async_client.delete( 

80 url="/api/projects/UNKNOWN_PROJECT", 

81 ) 

82 assert response_delete.status_code == 202 

83 assert list(response_delete.json().keys()) == ["project_id", "detail"] 

84 assert response_delete.json()["project_id"] == "UNKNOWN_PROJECT" 

85 assert response_delete.json()["detail"] == "The deletion of project with id 'UNKNOWN_PROJECT' is accepted." 

86 

87 # Assert route `GET /api/projects` is kept empty. 

88 response_get = await async_client.get(url="/api/projects") 

89 assert response_get.status_code == 200 

90 assert response_get.json() == [] # noqa: WPS520