1- import filecmp
21import os
3- import tempfile
2+ from unittest . mock import patch
43from os .path import dirname
5- import pytest
64
75import src .superannotate as sa
8- from tests .integration .base import BaseTestCase
96from src .superannotate import AppException
7+ from src .superannotate .lib .core import UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE
8+ from src .superannotate .lib .core import UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE
9+ from src .superannotate .lib .core import UPLOAD_USER_LIMIT_ERROR_MESSAGE
10+ from src .superannotate .lib .core import COPY_FOLDER_LIMIT_ERROR_MESSAGE
11+ from src .superannotate .lib .core import COPY_PROJECT_LIMIT_ERROR_MESSAGE
12+ from src .superannotate .lib .core import COPY_SUPER_LIMIT_ERROR_MESSAGE
13+ from tests .integration .base import BaseTestCase
14+ from tests .moks .limitatoins import folder_limit_response
15+ from tests .moks .limitatoins import project_limit_response
16+ from tests .moks .limitatoins import user_limit_response
17+
18+
19+ class TestLimitsUploadImagesFromFolderToProject (BaseTestCase ):
20+ PROJECT_NAME = "TestLimitsUploadImagesFromFolderToProject"
21+ PROJECT_DESCRIPTION = "Desc"
22+ PROJECT_TYPE = "Vector"
23+ TEST_FOLDER_PTH = "data_set"
24+ TEST_FOLDER_PATH = "data_set/sample_project_vector"
25+ EXAMPLE_IMAGE_1 = "example_image_1.jpg"
26+
27+ @property
28+ def folder_path (self ):
29+ return os .path .join (dirname (dirname (__file__ )), self .TEST_FOLDER_PATH )
30+
31+ @patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" , return_value = folder_limit_response )
32+ def test_folder_limitations (self , * _ ):
33+ with self .assertRaisesRegexp (AppException , UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE ):
34+ _ , _ , __ = sa .upload_images_from_folder_to_project (
35+ project = self ._project ["name" ], folder_path = self .folder_path
36+ )
37+
38+ @patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" , return_value = project_limit_response )
39+ def test_project_limitations (self , * _ ):
40+ with self .assertRaisesRegexp (AppException , UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE ):
41+ _ , _ , __ = sa .upload_images_from_folder_to_project (
42+ project = self ._project ["name" ], folder_path = self .folder_path
43+ )
44+
45+ @patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" , return_value = user_limit_response )
46+ def test_user_limitations (self , * _ ):
47+ with self .assertRaisesRegexp (AppException , UPLOAD_USER_LIMIT_ERROR_MESSAGE ):
48+ _ , _ , __ = sa .upload_images_from_folder_to_project (
49+ project = self ._project ["name" ], folder_path = self .folder_path
50+ )
1051
1152
12- class TestImageQuality (BaseTestCase ):
13- PROJECT_NAME = "Limitation Test "
53+ class TestLimitsMoveImage (BaseTestCase ):
54+ PROJECT_NAME = "TestLimitsUploadImagesFromFolderToProject "
1455 PROJECT_DESCRIPTION = "Desc"
1556 PROJECT_TYPE = "Vector"
1657 TEST_FOLDER_PTH = "data_set"
@@ -21,10 +62,69 @@ class TestImageQuality(BaseTestCase):
2162 def folder_path (self ):
2263 return os .path .join (dirname (dirname (__file__ )), self .TEST_FOLDER_PATH )
2364
24- def test_image_quality_setting1 (self ):
25- uploaded , _ , __ = sa .upload_images_from_folder_to_project (
26- project = self ._project ["name" ], folder_path = self .folder_path
27- )
28- uploaded , _ , __ = sa .upload_images_from_folder_to_project (
29- project = self ._project ["name" ], folder_path = os .path .join (dirname (dirname (__file__ )), "data_set" )
30- )
65+ def test_folder_limitations (self ):
66+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
67+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
68+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
69+ limit_response .return_value = folder_limit_response
70+ with self .assertRaisesRegexp (AppException , COPY_FOLDER_LIMIT_ERROR_MESSAGE ):
71+ _ , _ , __ = sa .move_image (
72+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
73+
74+ def test_project_limitations (self , ):
75+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
76+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
77+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
78+ limit_response .return_value = project_limit_response
79+ with self .assertRaisesRegexp (AppException , COPY_PROJECT_LIMIT_ERROR_MESSAGE ):
80+ _ , _ , __ = sa .move_image (
81+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
82+
83+ def test_user_limitations (self , ):
84+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
85+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
86+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
87+ limit_response .return_value = user_limit_response
88+ with self .assertRaisesRegexp (AppException , COPY_SUPER_LIMIT_ERROR_MESSAGE ):
89+ _ , _ , __ = sa .move_image (
90+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
91+
92+
93+ class TestLimitsCopyImage (BaseTestCase ):
94+ PROJECT_NAME = "TestLimitsUploadImagesFromFolderToProject"
95+ PROJECT_DESCRIPTION = "Desc"
96+ PROJECT_TYPE = "Vector"
97+ TEST_FOLDER_PTH = "data_set"
98+ TEST_FOLDER_PATH = "data_set/sample_project_vector"
99+ EXAMPLE_IMAGE_1 = "example_image_1.jpg"
100+
101+ @property
102+ def folder_path (self ):
103+ return os .path .join (dirname (dirname (__file__ )), self .TEST_FOLDER_PATH )
104+
105+ def test_folder_limitations (self ):
106+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
107+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
108+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
109+ limit_response .return_value = folder_limit_response
110+ with self .assertRaisesRegexp (AppException , COPY_FOLDER_LIMIT_ERROR_MESSAGE ):
111+ _ , _ , __ = sa .copy_image (
112+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
113+
114+ def test_project_limitations (self , ):
115+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
116+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
117+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
118+ limit_response .return_value = project_limit_response
119+ with self .assertRaisesRegexp (AppException , COPY_PROJECT_LIMIT_ERROR_MESSAGE ):
120+ _ , _ , __ = sa .copy_image (
121+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
122+
123+ def test_user_limitations (self , ):
124+ sa .upload_image_to_project (self ._project ["name" ], os .path .join (self .folder_path , self .EXAMPLE_IMAGE_1 ))
125+ sa .create_folder (self ._project ["name" ], self ._project ["name" ])
126+ with patch ("lib.infrastructure.services.SuperannotateBackendService.get_limitations" ) as limit_response :
127+ limit_response .return_value = user_limit_response
128+ with self .assertRaisesRegexp (AppException , COPY_SUPER_LIMIT_ERROR_MESSAGE ):
129+ _ , _ , __ = sa .copy_image (
130+ self ._project ["name" ], self .folder_path , f"{ self .PROJECT_NAME } /{ self .PROJECT_NAME } " )
0 commit comments