Skip to content

Commit cf0c0d3

Browse files
wip mock ffs
1 parent 882c08a commit cf0c0d3

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

label_studio/io_storages/tests/test_multitask_import.py

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
import boto3
4+
import mock
45
import pytest
56
from io_storages.models import S3ImportStorage
67
from io_storages.s3.models import S3ImportStorageLink
@@ -14,13 +15,55 @@
1415
from moto import mock_s3
1516
from projects.tests.factories import ProjectFactory
1617
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+
1862

1963
#
2064
# Integration tests for storage.sync()
2165
#
2266

23-
2467
pytestmark = pytest.mark.django_db
2568

2669

@@ -66,7 +109,7 @@ def _test_storage_import(project, storage_class, task_data, **storage_kwargs):
66109
assert task['data'] == expected_data['data']
67110

68111

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
70113
def test_import_multiple_tasks_s3(project, common_task_data):
71114
with mock_s3():
72115
# Setup S3 bucket and test data
@@ -88,7 +131,7 @@ def test_import_multiple_tasks_s3(project, common_task_data):
88131
)
89132

90133

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
92135
def test_import_multiple_tasks_gcs(project, common_task_data):
93136
# initialize mock with sample data
94137
with gcs_client_mock():
@@ -102,7 +145,7 @@ def test_import_multiple_tasks_gcs(project, common_task_data):
102145
)
103146

104147

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
106149
def test_import_multiple_tasks_azure(project, common_task_data):
107150
# initialize mock with sample data
108151
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):
114157
)
115158

116159

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
118161
def test_import_multiple_tasks_redis(project, common_task_data):
119162
with redis_client_mock() as redis:
120163
redis.set('test.json', json.dumps(common_task_data))
@@ -128,7 +171,7 @@ def test_import_multiple_tasks_redis(project, common_task_data):
128171
)
129172

130173

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
132175
def test_storagelink_fields(project, common_task_data):
133176
# use an actual storage and storagelink to test this, since factories aren't connected properly
134177
with mock_s3():
@@ -313,7 +356,7 @@ def test_list_jsonl(storage):
313356
create_tasks(storage, output)
314357

315358

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
317360
def test_list_jsonl_with_preds_and_annots(storage):
318361
task_data = annots_preds_task_list
319362

@@ -331,7 +374,7 @@ def test_list_jsonl_with_preds_and_annots(storage):
331374
create_tasks(storage, output)
332375

333376

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
335378
def test_ff_blocks_jsonl():
336379
with pytest.raises(ValueError):
337380
load_tasks_json(b'{"text": "Test task 1"}\n{"text": "Test task 2"}', 'test.jsonl')

0 commit comments

Comments
 (0)