Coverage for tests\test_get_api_projects.py: 100.00%

16 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.py 

5* Description: Unittests for `app` module on the `GET /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_ok_empty 

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

22 

23 

24@pytest.mark.asyncio() 

25async def test_ok_empty(async_client): 

26 """ 

27 Test the `GET /api/projects` route with no projects. 

28 

29 Arguments: 

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

31 """ 

32 # Assert HTTP client is created. 

33 assert async_client 

34 

35 # Assert route `GET /api/projects` works. 

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

37 assert response_get.status_code == 200 

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

39 

40 

41# ============================================================================== 

42# test_ok_not_empty 

43# ============================================================================== 

44 

45 

46@pytest.mark.asyncio() 

47async def test_ok_not_empty(async_client, tmp_path): 

48 """ 

49 Test the `GET /api/projects` route with some projects. 

50 

51 Arguments: 

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

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

54 """ 

55 # Assert HTTP client is created. 

56 assert async_client 

57 

58 # Create dummy projects. 

59 create_dummy_projects( 

60 tmp_path=tmp_path, 

61 list_of_dummy_project_ids=[ 

62 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

63 "0e_CLUSTERING_PENDING", 

64 "1a_SAMPLING_TODO", 

65 "1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS", 

66 "archive-1d_ANNOTATION_WITH_UPTODATE_MODELIZATION.zip", 

67 ], 

68 ) 

69 

70 # Assert route `GET /api/projects` works. 

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

72 assert response_get.status_code == 200 

73 assert sorted(response_get.json()) == [ 

74 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

75 "0e_CLUSTERING_PENDING", 

76 "1a_SAMPLING_TODO", 

77 "1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS", 

78 ]