1
1
import json
2
2
3
3
import boto3
4
+ import mock
4
5
import pytest
5
6
from io_storages .models import S3ImportStorage
6
7
from io_storages .s3 .models import S3ImportStorageLink
14
15
from moto import mock_s3
15
16
from projects .tests .factories import ProjectFactory
16
17
from rest_framework .test import APIClient
17
- from tests .utils import azure_client_mock , gcs_client_mock , mock_feature_flag , redis_client_mock
18
+
19
+ from tests .utils import azure_client_mock , gcs_client_mock , redis_client_mock
20
+
21
+ # FIXME: mock_feature_flag is not working in this file for some reason
22
+
23
+
24
+ @pytest .fixture (name = 'fflag_feat_dia_2092_multitasks_per_storage_link_on' )
25
+ def fflag_feat_dia_2092_multitasks_per_storage_link_on ():
26
+ from core .feature_flags import flag_set
27
+
28
+ def fake_flag_set (* args , ** kwargs ):
29
+ if args [0 ] == 'fflag_feat_dia_2092_multitasks_per_storage_link' :
30
+ return True
31
+ return flag_set (* args , ** kwargs )
32
+
33
+ with mock .patch ('core.feature_flags.flag_set' , wraps = fake_flag_set ):
34
+ yield
35
+
36
+
37
+ @pytest .fixture (name = 'fflag_feat_root_11_support_jsonl_cloud_storage_on' )
38
+ def fflag_feat_root_11_support_jsonl_cloud_storage_on ():
39
+ from core .feature_flags import flag_set
40
+
41
+ def fake_flag_set (* args , ** kwargs ):
42
+ if args [0 ] == 'fflag_feat_root_11_support_jsonl_cloud_storage' :
43
+ return True
44
+ return flag_set (* args , ** kwargs )
45
+
46
+ with mock .patch ('core.feature_flags.flag_set' , wraps = fake_flag_set ):
47
+ yield
48
+
49
+
50
+ @pytest .fixture (name = 'fflag_feat_root_11_support_jsonl_cloud_storage_off' )
51
+ def fflag_feat_root_11_support_jsonl_cloud_storage_off ():
52
+ from core .feature_flags import flag_set
53
+
54
+ def fake_flag_set (* args , ** kwargs ):
55
+ if args [0 ] == 'fflag_feat_root_11_support_jsonl_cloud_storage' :
56
+ return False
57
+ return flag_set (* args , ** kwargs )
58
+
59
+ with mock .patch ('core.feature_flags.flag_set' , wraps = fake_flag_set ):
60
+ yield
61
+
18
62
19
63
#
20
64
# Integration tests for storage.sync()
21
65
#
22
66
23
-
24
67
pytestmark = pytest .mark .django_db
25
68
26
69
@@ -66,7 +109,7 @@ def _test_storage_import(project, storage_class, task_data, **storage_kwargs):
66
109
assert task ['data' ] == expected_data ['data' ]
67
110
68
111
69
- @mock_feature_flag ( 'fflag_feat_dia_2092_multitasks_per_storage_link' , True )
112
+ @pytest . mark . fflag_feat_dia_2092_multitasks_per_storage_link_on
70
113
def test_import_multiple_tasks_s3 (project , common_task_data ):
71
114
with mock_s3 ():
72
115
# Setup S3 bucket and test data
@@ -88,7 +131,7 @@ def test_import_multiple_tasks_s3(project, common_task_data):
88
131
)
89
132
90
133
91
- @mock_feature_flag ( 'fflag_feat_dia_2092_multitasks_per_storage_link' , True )
134
+ @pytest . mark . fflag_feat_dia_2092_multitasks_per_storage_link_on
92
135
def test_import_multiple_tasks_gcs (project , common_task_data ):
93
136
# initialize mock with sample data
94
137
with gcs_client_mock ():
@@ -102,7 +145,7 @@ def test_import_multiple_tasks_gcs(project, common_task_data):
102
145
)
103
146
104
147
105
- @mock_feature_flag ( 'fflag_feat_dia_2092_multitasks_per_storage_link' , True )
148
+ @pytest . mark . fflag_feat_dia_2092_multitasks_per_storage_link_on
106
149
def test_import_multiple_tasks_azure (project , common_task_data ):
107
150
# initialize mock with sample data
108
151
with azure_client_mock (sample_json_contents = common_task_data , sample_blob_names = ['test.json' ]):
@@ -114,7 +157,7 @@ def test_import_multiple_tasks_azure(project, common_task_data):
114
157
)
115
158
116
159
117
- @mock_feature_flag ( 'fflag_feat_dia_2092_multitasks_per_storage_link' , True )
160
+ @pytest . mark . fflag_feat_dia_2092_multitasks_per_storage_link_on
118
161
def test_import_multiple_tasks_redis (project , common_task_data ):
119
162
with redis_client_mock () as redis :
120
163
redis .set ('test.json' , json .dumps (common_task_data ))
@@ -128,7 +171,7 @@ def test_import_multiple_tasks_redis(project, common_task_data):
128
171
)
129
172
130
173
131
- @mock_feature_flag ( 'fflag_feat_dia_2092_multitasks_per_storage_link' , True )
174
+ @pytest . mark . fflag_feat_dia_2092_multitasks_per_storage_link_on
132
175
def test_storagelink_fields (project , common_task_data ):
133
176
# use an actual storage and storagelink to test this, since factories aren't connected properly
134
177
with mock_s3 ():
@@ -313,7 +356,7 @@ def test_list_jsonl(storage):
313
356
create_tasks (storage , output )
314
357
315
358
316
- @mock_feature_flag ( 'fflag_feat_root_11_support_jsonl_cloud_storage' , True )
359
+ @pytest . mark . fflag_feat_root_11_support_jsonl_cloud_storage_on
317
360
def test_list_jsonl_with_preds_and_annots (storage ):
318
361
task_data = annots_preds_task_list
319
362
@@ -331,7 +374,7 @@ def test_list_jsonl_with_preds_and_annots(storage):
331
374
create_tasks (storage , output )
332
375
333
376
334
- @mock_feature_flag ( 'fflag_feat_root_11_support_jsonl_cloud_storage' , False )
377
+ @pytest . mark . fflag_feat_root_11_support_jsonl_cloud_storage_off
335
378
def test_ff_blocks_jsonl ():
336
379
with pytest .raises (ValueError ):
337
380
load_tasks_json (b'{"text": "Test task 1"}\n {"text": "Test task 2"}' , 'test.jsonl' )
0 commit comments