Coverage for tests\test_get_api_projects_download.py: 100.00%

23 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_get_api_projects_download.py 

5* Description: Unittests for `app` module on the `GET /api/projects/{project_id}/download` 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# from zipp import zipfile 

20 

21 

22# ============================================================================== 

23# test_ko_not_found 

24# ============================================================================== 

25 

26 

27@pytest.mark.asyncio() 

28async def test_ko_not_found(async_client): 

29 """ 

30 Test the `GET /api/projects/{project_id}/download` route with not existing project. 

31 

32 Arguments: 

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

34 """ 

35 # Assert HTTP client is created. 

36 assert async_client 

37 

38 # Assert route `GET /api/projects/{project_id}/download` works. 

39 response_get = await async_client.get(url="/api/projects/UNKNOWN_PROJECT/download") 

40 assert response_get.status_code == 404 

41 assert response_get.json() == { 

42 "detail": "The project with id 'UNKNOWN_PROJECT' doesn't exist.", 

43 } 

44 

45 

46# ============================================================================== 

47# test_ok_without_modelization 

48# ============================================================================== 

49 

50 

51@pytest.mark.asyncio() 

52async def test_ok_without_modelization(async_client, tmp_path): 

53 """ 

54 Test the `GET /api/projects/{project_id}/download` route. 

55 

56 Arguments: 

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

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

59 """ 

60 

61 # Create dummy projects. 

62 create_dummy_projects( 

63 tmp_path=tmp_path, 

64 list_of_dummy_project_ids=[ 

65 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

66 ], 

67 ) 

68 

69 # Assert route `GET /api/projects/{project_id}/download` works. 

70 response_get = await async_client.get(url="/api/projects/0a_INITIALIZATION_WITHOUT_MODELIZATION/download") 

71 assert response_get.status_code == 200 

72 assert response_get.headers["content-type"] == "application/x-zip-compressed" 

73 assert ( 

74 response_get.headers["content-disposition"] 

75 == 'attachment; filename="archive-0a_INITIALIZATION_WITHOUT_MODELIZATION.zip"' 

76 ) 

77 

78 # TODO: explore content 

79 # with zipfile.ZipFile(import_archive_path, "r") as import_archive_file: 

80 # import_archive_file.namelist() 

81 

82 

83# ============================================================================== 

84# test_ok_with_modelization 

85# ============================================================================== 

86 

87 

88@pytest.mark.asyncio() 

89async def test_ok_with_modelization(async_client, tmp_path): 

90 """ 

91 Test the `GET /api/projects/{project_id}/download` route. 

92 

93 Arguments: 

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

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

96 """ 

97 

98 # Create dummy projects. 

99 create_dummy_projects( 

100 tmp_path=tmp_path, 

101 list_of_dummy_project_ids=[ 

102 "1c_SAMPLING_WORKING", 

103 ], 

104 ) 

105 

106 # Assert route `GET /api/projects/{project_id}/download` works. 

107 response_get = await async_client.get(url="/api/projects/1c_SAMPLING_WORKING/download") 

108 assert response_get.status_code == 200 

109 assert response_get.headers["content-type"] == "application/x-zip-compressed" 

110 assert response_get.headers["content-disposition"] == 'attachment; filename="archive-1c_SAMPLING_WORKING.zip"' 

111 

112 # TODO: explore content 

113 # with zipfile.ZipFile(import_archive_path, "r") as import_archive_file: 

114 # import_archive_file.namelist()