Skip to content

Commit 0313974

Browse files
committed
fix unit test errors
1 parent 7c760a2 commit 0313974

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

tests/unit/synapseclient/services/unit_test_migration_and_types_async.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def _make_mock_client():
246246
client.rest_get_async = AsyncMock()
247247
client.rest_put_async = AsyncMock()
248248
client.logger = MagicMock()
249+
client._get_parallel_file_transfer_semaphore.return_value = asyncio.Semaphore(10)
249250
return client
250251

251252

@@ -1185,17 +1186,23 @@ class TestVerifyStorageLocationOwnershipAsync:
11851186
@pytest.mark.asyncio
11861187
async def test_success(self):
11871188
client = _make_mock_client()
1188-
client.rest_get_async.return_value = {"storageLocationId": "99"}
1189-
# Should not raise
1190-
await _verify_storage_location_ownership_async("99", synapse_client=client)
1191-
client.rest_get_async.assert_awaited_once_with("/storageLocation/99")
1189+
mock_get = AsyncMock(return_value={"storageLocationId": "99"})
1190+
with patch(f"{MODULE}.get_storage_location_setting", mock_get):
1191+
# Should not raise
1192+
await _verify_storage_location_ownership_async("99", synapse_client=client)
1193+
mock_get.assert_awaited_once_with(
1194+
storage_location_id="99", synapse_client=client
1195+
)
11921196

11931197
@pytest.mark.asyncio
11941198
async def test_synapse_error_raises_value_error(self):
11951199
client = _make_mock_client()
1196-
client.rest_get_async.side_effect = SynapseError("forbidden")
1197-
with pytest.raises(ValueError, match="Unable to verify ownership"):
1198-
await _verify_storage_location_ownership_async("99", synapse_client=client)
1200+
mock_get = AsyncMock(side_effect=SynapseError("forbidden"))
1201+
with patch(f"{MODULE}.get_storage_location_setting", mock_get):
1202+
with pytest.raises(ValueError, match="Unable to verify ownership"):
1203+
await _verify_storage_location_ownership_async(
1204+
"99", synapse_client=client
1205+
)
11991206

12001207

12011208
# =============================================================================
@@ -2176,7 +2183,7 @@ async def test_sends_transaction(self):
21762183

21772184
class TestTrackMigrationResultsAsync:
21782185
def _make_db(self, from_fh="fh_src", entity_id="syn3", version=1):
2179-
conn = sqlite3.connect(":memory:")
2186+
conn = sqlite3.connect(":memory:", check_same_thread=False)
21802187
cursor = conn.cursor()
21812188
_ensure_schema(cursor)
21822189
cursor.execute(
@@ -2375,7 +2382,7 @@ async def test_returns_migration_result_on_success(self, db_file_with_settings):
23752382

23762383
class TestExecuteMigrationAsync:
23772384
def _make_db_with_indexed_file(self, from_fh="fh_src", entity_id="syn3", version=1):
2378-
conn = sqlite3.connect(":memory:")
2385+
conn = sqlite3.connect(":memory:", check_same_thread=False)
23792386
cursor = conn.cursor()
23802387
_ensure_schema(cursor)
23812388
cursor.execute(
@@ -2431,7 +2438,7 @@ async def _mock_migrate_item(
24312438

24322439
@pytest.mark.asyncio
24332440
async def test_empty_db_completes_without_error(self):
2434-
conn = sqlite3.connect(":memory:")
2441+
conn = sqlite3.connect(":memory:", check_same_thread=False)
24352442
cursor = conn.cursor()
24362443
_ensure_schema(cursor)
24372444
conn.commit()

0 commit comments

Comments
 (0)