Skip to content

Commit 5d9e0be

Browse files
pavanputhraclaude
andcommitted
Fix stale server.* imports in all test files
All test files under common/ and conserver/ were still importing from the old server.* namespace (server.lib., server.storage., server.links., server.vcon, server.tracers.*). Updated to match the new structure: server.lib. -> lib. server.storage. -> storage. server.links. -> links. server.tracers. -> tracers. server.vcon -> vcon Also fixes patch() target strings so mock paths resolve correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 76f4019 commit 5d9e0be

9 files changed

Lines changed: 117 additions & 117 deletions

File tree

common/storage/dataverse/test_dataverse.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import json
33
from unittest.mock import patch, MagicMock, ANY
44

5-
from server.lib.vcon_redis import VconRedis
6-
from server.vcon import Vcon
7-
from server.storage.dataverse import (
5+
from lib.vcon_redis import VconRedis
6+
from vcon import Vcon
7+
from storage.dataverse import (
88
save,
99
get,
1010
get_access_token,
@@ -55,7 +55,7 @@ def sample_vcon():
5555
# Mock Redis
5656
@pytest.fixture
5757
def mock_vcon_redis(sample_vcon):
58-
with patch('server.lib.vcon_redis.VconRedis') as MockVconRedis:
58+
with patch('lib.vcon_redis.VconRedis') as MockVconRedis:
5959
mock_redis = MagicMock()
6060
mock_redis.get_vcon.return_value = sample_vcon
6161
MockVconRedis.return_value = mock_redis
@@ -65,7 +65,7 @@ def mock_vcon_redis(sample_vcon):
6565
# Mock MSAL
6666
@pytest.fixture
6767
def mock_msal():
68-
with patch('server.storage.dataverse.msal') as mock_msal:
68+
with patch('storage.dataverse.msal') as mock_msal:
6969
mock_client_app = MagicMock()
7070
mock_msal.ConfidentialClientApplication.return_value = mock_client_app
7171

@@ -82,7 +82,7 @@ def mock_msal():
8282
# Mock Requests
8383
@pytest.fixture
8484
def mock_requests():
85-
with patch('server.storage.dataverse.requests') as mock_requests:
85+
with patch('storage.dataverse.requests') as mock_requests:
8686
mock_session = MagicMock()
8787
mock_requests.Session.return_value = mock_session
8888

@@ -169,7 +169,7 @@ def test_create_dataverse_session(mock_msal, mock_requests):
169169
assert session is None
170170

171171

172-
@patch('server.storage.dataverse.create_dataverse_session')
172+
@patch('storage.dataverse.create_dataverse_session')
173173
def test_save_new_entity(mock_create_session, mock_requests, mock_vcon_redis, sample_vcon):
174174
"""Test saving a new vCon entity to Dataverse."""
175175
# Setup mocks
@@ -195,7 +195,7 @@ def test_save_new_entity(mock_create_session, mock_requests, mock_vcon_redis, sa
195195
}
196196

197197
# Call save
198-
with patch('server.storage.dataverse.VconRedis', return_value=mock_instance):
198+
with patch('storage.dataverse.VconRedis', return_value=mock_instance):
199199
save("test-uuid", test_options)
200200

201201
# Verify entity was created (POST request)
@@ -211,7 +211,7 @@ def test_save_new_entity(mock_create_session, mock_requests, mock_vcon_redis, sa
211211
assert "vcon_created_at" in post_data
212212

213213

214-
@patch('server.storage.dataverse.create_dataverse_session')
214+
@patch('storage.dataverse.create_dataverse_session')
215215
def test_save_existing_entity(mock_create_session, mock_requests, mock_vcon_redis, sample_vcon):
216216
"""Test updating an existing vCon entity in Dataverse."""
217217
# Setup mocks
@@ -242,7 +242,7 @@ def test_save_existing_entity(mock_create_session, mock_requests, mock_vcon_redi
242242
}
243243

244244
# Call save
245-
with patch('server.storage.dataverse.VconRedis', return_value=mock_instance):
245+
with patch('storage.dataverse.VconRedis', return_value=mock_instance):
246246
save("test-uuid", test_options)
247247

248248
# Verify entity was updated (PATCH request)
@@ -258,7 +258,7 @@ def test_save_existing_entity(mock_create_session, mock_requests, mock_vcon_redi
258258
assert "vcon_created_at" in patch_data
259259

260260

261-
@patch('server.storage.dataverse.create_dataverse_session')
261+
@patch('storage.dataverse.create_dataverse_session')
262262
def test_get_vcon(mock_create_session, mock_requests):
263263
"""Test retrieving a vCon from Dataverse."""
264264
# Setup mocks
@@ -305,7 +305,7 @@ def test_get_vcon(mock_create_session, mock_requests):
305305
assert result is None
306306

307307

308-
@patch('server.storage.dataverse.create_dataverse_session')
308+
@patch('storage.dataverse.create_dataverse_session')
309309
def test_get_vcon_error_handling(mock_create_session, mock_requests):
310310
"""Test error handling when retrieving a vCon."""
311311
# Setup mocks

common/storage/file/test_file_storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pathlib import Path
1818
from unittest.mock import patch, MagicMock
1919

20-
from server.storage.file import (
20+
from storage.file import (
2121
save,
2222
get,
2323
delete,
@@ -28,7 +28,7 @@
2828
_find_vcon_file,
2929
_cleanup_empty_dirs,
3030
)
31-
from server.vcon import Vcon
31+
from vcon import Vcon
3232

3333

3434
@pytest.fixture
@@ -50,7 +50,7 @@ def sample_vcon():
5050
@pytest.fixture
5151
def mock_vcon_redis(sample_vcon):
5252
"""Mock VconRedis to return sample vCon."""
53-
with patch("server.storage.file.VconRedis") as MockVconRedis:
53+
with patch("storage.file.VconRedis") as MockVconRedis:
5454
mock_redis = MagicMock()
5555
mock_redis.get_vcon.return_value = sample_vcon
5656
MockVconRedis.return_value = mock_redis

common/storage/milvus/test_milvus.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
22
from unittest.mock import patch, MagicMock, mock_open
33

4-
from server.lib.vcon_redis import VconRedis
5-
from server.vcon import Vcon
6-
from server.storage.milvus import (
4+
from lib.vcon_redis import VconRedis
5+
from vcon import Vcon
6+
from storage.milvus import (
77
save,
88
get,
99
extract_text_from_vcon,
@@ -63,7 +63,7 @@ def sample_vcon():
6363
# Mock Redis
6464
@pytest.fixture
6565
def mock_vcon_redis(sample_vcon):
66-
with patch('server.lib.vcon_redis.VconRedis') as MockVconRedis:
66+
with patch('lib.vcon_redis.VconRedis') as MockVconRedis:
6767
mock_redis = MagicMock()
6868
mock_redis.get_vcon.return_value = sample_vcon
6969
MockVconRedis.return_value = mock_redis
@@ -72,9 +72,9 @@ def mock_vcon_redis(sample_vcon):
7272
# Mock Milvus connections and utility
7373
@pytest.fixture
7474
def mock_milvus():
75-
with patch('server.storage.milvus.connections') as mock_connections, \
76-
patch('server.storage.milvus.utility') as mock_utility, \
77-
patch('server.storage.milvus.Collection') as mock_collection_class:
75+
with patch('storage.milvus.connections') as mock_connections, \
76+
patch('storage.milvus.utility') as mock_utility, \
77+
patch('storage.milvus.Collection') as mock_collection_class:
7878

7979
# Setup utility mocks
8080
mock_utility.has_collection.return_value = True
@@ -103,7 +103,7 @@ def mock_openai():
103103
mock_response.data = [mock_data]
104104
mock_client.embeddings.create.return_value = mock_response
105105

106-
with patch('server.storage.milvus.get_openai_client', return_value=mock_client):
106+
with patch('storage.milvus.get_openai_client', return_value=mock_client):
107107
yield mock_client
108108

109109
def test_extract_text_from_vcon(sample_vcon):
@@ -171,9 +171,9 @@ def test_check_vcon_exists(mock_milvus):
171171
mock_milvus['collection'].query.return_value = [{"vcon_uuid": "test-uuid"}]
172172
assert check_vcon_exists(mock_milvus['collection'], "test-uuid") is True
173173

174-
@patch('server.storage.milvus.extract_text_from_vcon')
175-
@patch('server.storage.milvus.extract_party_id')
176-
@patch('server.storage.milvus.get_embedding')
174+
@patch('storage.milvus.extract_text_from_vcon')
175+
@patch('storage.milvus.extract_party_id')
176+
@patch('storage.milvus.get_embedding')
177177
def test_save(mock_get_embedding, mock_extract_party_id, mock_extract_text,
178178
mock_milvus, mock_openai, mock_vcon_redis, sample_vcon):
179179
"""Test saving a vCon to Milvus."""
@@ -187,7 +187,7 @@ def test_save(mock_get_embedding, mock_extract_party_id, mock_extract_text,
187187
mock_instance.get_vcon.return_value = sample_vcon
188188

189189
# Also patch VconRedis to ensure our mock is used
190-
with patch('server.storage.milvus.VconRedis', return_value=mock_instance):
190+
with patch('storage.milvus.VconRedis', return_value=mock_instance):
191191
# Test options
192192
test_options = {
193193
"host": "localhost",
@@ -215,7 +215,7 @@ def test_save(mock_get_embedding, mock_extract_party_id, mock_extract_text,
215215
assert insert_args[0]["text"] == "Extracted text content"
216216
assert len(insert_args[0]["embedding"]) == 1536
217217

218-
@patch('server.storage.milvus.ensure_milvus_connection')
218+
@patch('storage.milvus.ensure_milvus_connection')
219219
def test_get_vcon_from_milvus(mock_ensure_connection, mock_milvus):
220220
"""Test retrieving a vCon from Milvus."""
221221
# Setup mocks

conserver/links/analyze/tests/test_analyze.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import os
1313
import pytest
1414
from unittest.mock import Mock, patch
15-
from server.links.analyze import (
15+
from links.analyze import (
1616
generate_analysis,
1717
run,
1818
default_options,
1919
navigate_dict,
2020
get_analysis_for_type,
2121
)
22-
from server.vcon import Vcon
22+
from vcon import Vcon
2323
from dotenv import load_dotenv
2424

2525
# Load environment variables from .env file for API keys, etc.
@@ -35,7 +35,7 @@
3535
@pytest.fixture
3636
def mock_vcon_redis():
3737
"""Mock the VconRedis class"""
38-
with patch('server.links.analyze.VconRedis', autospec=True) as mock:
38+
with patch('links.analyze.VconRedis', autospec=True) as mock:
3939
yield mock
4040

4141

@@ -140,7 +140,7 @@ def test_get_analysis_for_type_not_found(self):
140140
class TestGenerateAnalysis:
141141
"""Test the generate_analysis function"""
142142

143-
@patch('server.links.analyze.send_ai_usage_data_for_tracking')
143+
@patch('links.analyze.send_ai_usage_data_for_tracking')
144144
def test_generate_analysis_basic(self, mock_send_usage):
145145
"""Test basic analysis generation with mocked client"""
146146
# Setup mock client (injected into generate_analysis)
@@ -170,7 +170,7 @@ def test_generate_analysis_basic(self, mock_send_usage):
170170
assert result == "This is a test analysis."
171171
mock_client.chat.completions.create.assert_called_once()
172172

173-
@patch('server.links.analyze.send_ai_usage_data_for_tracking')
173+
@patch('links.analyze.send_ai_usage_data_for_tracking')
174174
def test_generate_analysis_with_custom_system_prompt(self, mock_send_usage):
175175
"""Test analysis generation with custom system prompt"""
176176
# Setup mock client (injected into generate_analysis)
@@ -209,7 +209,7 @@ def test_generate_analysis_with_custom_system_prompt(self, mock_send_usage):
209209
assert messages[1]['role'] == 'user'
210210
assert 'Analyze this financial data' in messages[1]['content']
211211

212-
@patch('server.links.analyze.send_ai_usage_data_for_tracking')
212+
@patch('links.analyze.send_ai_usage_data_for_tracking')
213213
def test_generate_analysis_with_empty_prompt(self, mock_send_usage):
214214
"""Test analysis generation with empty prompt"""
215215
# Setup mock client (injected into generate_analysis)
@@ -243,7 +243,7 @@ def test_generate_analysis_with_empty_prompt(self, mock_send_usage):
243243
messages = call_args[1]['messages']
244244
assert messages[1]['content'] == "\n\nTest transcript"
245245

246-
@patch('server.links.analyze.send_ai_usage_data_for_tracking')
246+
@patch('links.analyze.send_ai_usage_data_for_tracking')
247247
def test_generate_analysis_with_default_system_prompt(self, mock_send_usage):
248248
"""Test analysis generation uses default system prompt when not provided"""
249249
# Setup mock client (injected into generate_analysis)
@@ -303,10 +303,10 @@ def test_default_options_values(self):
303303
class TestRunFunction:
304304
"""Test the main run function"""
305305

306-
@patch('server.links.analyze.get_openai_client')
307-
@patch('server.links.analyze.generate_analysis')
308-
@patch('server.links.analyze.is_included', return_value=True)
309-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=True)
306+
@patch('links.analyze.get_openai_client')
307+
@patch('links.analyze.generate_analysis')
308+
@patch('links.analyze.is_included', return_value=True)
309+
@patch('links.analyze.randomly_execute_with_sampling', return_value=True)
310310
def test_run_basic(self, mock_sampling, mock_is_included, mock_generate_analysis, mock_get_client, mock_redis_with_vcon, sample_vcon):
311311
"""Test the basic run functionality with mocked analysis generation"""
312312
mock_get_client.return_value = Mock()
@@ -334,10 +334,10 @@ def test_run_basic(self, mock_sampling, mock_is_included, mock_generate_analysis
334334
# Check the vCon has an analysis
335335
sample_vcon.add_analysis.assert_called_once()
336336

337-
@patch('server.links.analyze.get_openai_client')
338-
@patch('server.links.analyze.generate_analysis')
339-
@patch('server.links.analyze.is_included', return_value=True)
340-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=True)
337+
@patch('links.analyze.get_openai_client')
338+
@patch('links.analyze.generate_analysis')
339+
@patch('links.analyze.is_included', return_value=True)
340+
@patch('links.analyze.randomly_execute_with_sampling', return_value=True)
341341
def test_run_with_custom_system_prompt(
342342
self, mock_sampling, mock_is_included, mock_generate_analysis, mock_get_client,
343343
mock_redis_with_vcon, sample_vcon
@@ -369,8 +369,8 @@ def test_run_with_custom_system_prompt(
369369
assert call_args[1]['opts']['system_prompt'] == "You are a specialized customer service analyst."
370370
assert call_args[1]['opts']['prompt'] == "Analyze this customer interaction."
371371

372-
@patch('server.links.analyze.get_openai_client')
373-
@patch('server.links.analyze.is_included', return_value=False)
372+
@patch('links.analyze.get_openai_client')
373+
@patch('links.analyze.is_included', return_value=False)
374374
def test_run_skipped_due_to_filters(self, mock_is_included, mock_get_client, mock_redis_with_vcon):
375375
"""Test that run is skipped when filters exclude the vCon"""
376376
mock_get_client.return_value = Mock()
@@ -386,9 +386,9 @@ def test_run_skipped_due_to_filters(self, mock_is_included, mock_get_client, moc
386386
# Should have called get_vcon but then skipped due to filters
387387
mock_redis_with_vcon.get_vcon.assert_called_once_with("test-uuid")
388388

389-
@patch('server.links.analyze.get_openai_client')
390-
@patch('server.links.analyze.is_included', return_value=True)
391-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=False)
389+
@patch('links.analyze.get_openai_client')
390+
@patch('links.analyze.is_included', return_value=True)
391+
@patch('links.analyze.randomly_execute_with_sampling', return_value=False)
392392
def test_run_skipped_due_to_sampling(self, mock_sampling, mock_is_included, mock_get_client, mock_redis_with_vcon):
393393
"""Test that run is skipped when sampling excludes the vCon"""
394394
mock_get_client.return_value = Mock()
@@ -404,10 +404,10 @@ def test_run_skipped_due_to_sampling(self, mock_sampling, mock_is_included, mock
404404
# Should have called get_vcon but then skipped due to sampling
405405
mock_redis_with_vcon.get_vcon.assert_called_once_with("test-uuid")
406406

407-
@patch('server.links.analyze.get_openai_client')
408-
@patch('server.links.analyze.generate_analysis')
409-
@patch('server.links.analyze.is_included', return_value=True)
410-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=True)
407+
@patch('links.analyze.get_openai_client')
408+
@patch('links.analyze.generate_analysis')
409+
@patch('links.analyze.is_included', return_value=True)
410+
@patch('links.analyze.randomly_execute_with_sampling', return_value=True)
411411
def test_run_with_azure_openai(
412412
self, mock_sampling, mock_is_included, mock_generate_analysis, mock_get_client,
413413
mock_redis_with_vcon, sample_vcon
@@ -439,10 +439,10 @@ def test_run_missing_credentials(self, mock_redis_with_vcon):
439439
with pytest.raises(ValueError, match="LITELLM_PROXY_URL|OPENAI_API_KEY|AZURE_OPENAI"):
440440
run("test-uuid", "analyze", {})
441441

442-
@patch('server.links.analyze.get_openai_client')
443-
@patch('server.links.analyze.generate_analysis')
444-
@patch('server.links.analyze.is_included', return_value=True)
445-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=True)
442+
@patch('links.analyze.get_openai_client')
443+
@patch('links.analyze.generate_analysis')
444+
@patch('links.analyze.is_included', return_value=True)
445+
@patch('links.analyze.randomly_execute_with_sampling', return_value=True)
446446
def test_run_already_has_analysis(
447447
self, mock_sampling, mock_is_included, mock_generate_analysis, mock_get_client,
448448
mock_redis_with_vcon, sample_vcon
@@ -467,10 +467,10 @@ def test_run_already_has_analysis(
467467
assert result == "test-uuid"
468468
mock_generate_analysis.assert_not_called()
469469

470-
@patch('server.links.analyze.get_openai_client')
471-
@patch('server.links.analyze.generate_analysis')
472-
@patch('server.links.analyze.is_included', return_value=True)
473-
@patch('server.links.analyze.randomly_execute_with_sampling', return_value=True)
470+
@patch('links.analyze.get_openai_client')
471+
@patch('links.analyze.generate_analysis')
472+
@patch('links.analyze.is_included', return_value=True)
473+
@patch('links.analyze.randomly_execute_with_sampling', return_value=True)
474474
def test_run_analysis_failure(
475475
self, mock_sampling, mock_is_included, mock_generate_analysis, mock_get_client,
476476
mock_redis_with_vcon, sample_vcon

0 commit comments

Comments
 (0)