Skip to content

Commit d2b15c9

Browse files
committed
fix patched tests
1 parent 2e4c65d commit d2b15c9

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

posthog/storage/test/test_object_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def teardown_method(self, method) -> None:
4040
bucket = s3.Bucket(OBJECT_STORAGE_BUCKET)
4141
bucket.objects.filter(Prefix=TEST_BUCKET).delete()
4242

43-
@patch("posthog.storage.object_storage.client")
43+
@patch("boto3.client")
4444
def test_does_not_create_client_if_storage_is_disabled(self, patched_s3_client) -> None:
4545
with self.settings(OBJECT_STORAGE_ENABLED=False):
4646
assert not health_check()

posthog/storage/test/test_session_recording_v2_object_storage.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestSessionRecordingV2Storage(APIBaseTest):
3030
def teardown_method(self, method) -> None:
3131
pass
3232

33-
@patch("posthog.storage.session_recording_v2_object_storage.boto3_client")
33+
@patch("boto3.client")
3434
def test_client_constructor_uses_correct_settings(self, patched_boto3_client) -> None:
3535
# Reset the global client to ensure we test client creation
3636
import posthog.storage.session_recording_v2_object_storage as storage_module
@@ -78,7 +78,7 @@ def test_client_constructor_uses_correct_settings(self, patched_boto3_client) ->
7878
),
7979
]
8080
)
81-
@patch("posthog.storage.session_recording_v2_object_storage.boto3_client")
81+
@patch("boto3.client")
8282
def test_does_not_create_client_if_required_settings_missing(self, settings_override, patched_s3_client) -> None:
8383
with self.settings(**settings_override):
8484
storage_client = client()
@@ -285,16 +285,16 @@ class TestAsyncSessionRecordingV2Storage(APIBaseTest):
285285
def teardown_method(self, method) -> None:
286286
pass
287287

288-
@patch("posthog.storage.session_recording_v2_object_storage.aioboto3")
289-
async def test_client_constructor_uses_correct_settings(self, patched_aioboto3) -> None:
288+
@patch("aioboto3.Session")
289+
async def test_client_constructor_uses_correct_settings(self, patched_aioboto3_session) -> None:
290290
# Reset the global client to ensure we test client creation
291291
import posthog.storage.session_recording_v2_object_storage as storage_module
292292

293293
client_mock = MagicMock(AsyncContextManager)
294-
patched_aioboto3.Session.return_value.client = client_mock
294+
patched_aioboto3_session.return_value.client = client_mock
295295

296296
async with storage_module.async_client() as client:
297-
assert patched_aioboto3.Session.call_count == 1
297+
assert patched_aioboto3_session.call_count == 1
298298
assert client_mock.call_count == 1
299299

300300
call_args = client_mock.call_args[0]
@@ -329,11 +329,13 @@ async def test_client_constructor_uses_correct_settings(self, patched_aioboto3)
329329
),
330330
]
331331
)
332-
@patch("posthog.storage.session_recording_v2_object_storage.aioboto3")
333-
async def test_throws_runtimeerror_if_required_settings_missing(self, settings_override, patched_aioboto3) -> None:
332+
@patch("aioboto3.Session")
333+
async def test_throws_runtimeerror_if_required_settings_missing(
334+
self, settings_override, patched_aioboto3_session
335+
) -> None:
334336
with self.settings(**settings_override):
335337
client_mock = MagicMock(AsyncContextManager)
336-
patched_aioboto3.Session.return_value.client = client_mock
338+
patched_aioboto3_session.return_value.client = client_mock
337339

338340
with self.assertRaises(RuntimeError) as _:
339341
async with async_client() as _:

products/llm_analytics/backend/providers/test/test_gemini.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_supported_models(self):
3535

3636
class TestGeminiProvider(BaseTest):
3737
@override_settings(GEMINI_API_KEY="test-api-key")
38-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
38+
@patch("posthoganalytics.ai.gemini.genai.Client")
3939
@patch("posthoganalytics.default_client")
4040
def test_provider_initialization(self, mock_posthog_client, mock_genai_client):
4141
mock_posthog_client.return_value = MagicMock()
@@ -57,7 +57,7 @@ def test_missing_posthog_client_raises_error(self):
5757
GeminiProvider("gemini-2.0-flash")
5858

5959
@override_settings(GEMINI_API_KEY="test-api-key")
60-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
60+
@patch("posthoganalytics.ai.gemini.genai.Client")
6161
@patch("posthoganalytics.default_client")
6262
def test_invalid_model_raises_error(self, mock_posthog_client, mock_genai_client):
6363
mock_posthog_client.return_value = MagicMock()
@@ -74,7 +74,7 @@ def setUp(self):
7474
self.messages = cast(list[MessageParam], [{"role": "user", "content": "Test message"}])
7575

7676
@override_settings(GEMINI_API_KEY="test-api-key")
77-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
77+
@patch("posthoganalytics.ai.gemini.genai.Client")
7878
@patch("posthoganalytics.default_client")
7979
def test_basic_text_streaming(self, mock_posthog, mock_genai):
8080
mock_posthog.return_value = self.mock_posthog_client
@@ -106,7 +106,7 @@ def mock_stream():
106106
assert json.loads(responses[1].replace("data: ", "").strip()) == {"type": "text", "text": "world!"}
107107

108108
@override_settings(GEMINI_API_KEY="test-api-key")
109-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
109+
@patch("posthoganalytics.ai.gemini.genai.Client")
110110
@patch("posthoganalytics.default_client")
111111
def test_streaming_with_none_parts(self, mock_posthog, mock_genai):
112112
mock_posthog.return_value = self.mock_posthog_client
@@ -136,7 +136,7 @@ def mock_stream():
136136
assert json.loads(responses[0].replace("data: ", "").strip()) == {"type": "text", "text": "Test text"}
137137

138138
@override_settings(GEMINI_API_KEY="test-api-key")
139-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
139+
@patch("posthoganalytics.ai.gemini.genai.Client")
140140
@patch("posthoganalytics.default_client")
141141
def test_streaming_with_empty_parts(self, mock_posthog, mock_genai):
142142
mock_posthog.return_value = self.mock_posthog_client
@@ -165,7 +165,7 @@ def mock_stream():
165165
assert len(responses) == 0
166166

167167
@override_settings(GEMINI_API_KEY="test-api-key")
168-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
168+
@patch("posthoganalytics.ai.gemini.genai.Client")
169169
@patch("posthoganalytics.default_client")
170170
def test_streaming_with_function_calls(self, mock_posthog, mock_genai):
171171
mock_posthog.return_value = self.mock_posthog_client
@@ -216,7 +216,7 @@ def mock_stream():
216216
assert json.loads(tool_response["function"]["arguments"]) == {"location": "San Francisco"}
217217

218218
@override_settings(GEMINI_API_KEY="test-api-key")
219-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
219+
@patch("posthoganalytics.ai.gemini.genai.Client")
220220
@patch("posthoganalytics.default_client")
221221
def test_streaming_with_text_in_parts(self, mock_posthog, mock_genai):
222222
mock_posthog.return_value = self.mock_posthog_client
@@ -252,7 +252,7 @@ def mock_stream():
252252
assert json.loads(responses[0].replace("data: ", "").strip()) == {"type": "text", "text": "Text from parts"}
253253

254254
@override_settings(GEMINI_API_KEY="test-api-key")
255-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
255+
@patch("posthoganalytics.ai.gemini.genai.Client")
256256
@patch("posthoganalytics.default_client")
257257
def test_streaming_with_mixed_parts(self, mock_posthog, mock_genai):
258258
mock_posthog.return_value = self.mock_posthog_client
@@ -305,7 +305,7 @@ def mock_stream():
305305
assert tool_response["function"]["name"] == "get_weather"
306306

307307
@override_settings(GEMINI_API_KEY="test-api-key")
308-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
308+
@patch("posthoganalytics.ai.gemini.genai.Client")
309309
@patch("posthoganalytics.default_client")
310310
def test_streaming_with_usage_metadata(self, mock_posthog, mock_genai):
311311
mock_posthog.return_value = self.mock_posthog_client
@@ -345,7 +345,7 @@ def setUp(self):
345345
self.messages = cast(list[MessageParam], [{"role": "user", "content": "Test message"}])
346346

347347
@override_settings(GEMINI_API_KEY="test-api-key")
348-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
348+
@patch("posthoganalytics.ai.gemini.genai.Client")
349349
@patch("posthoganalytics.default_client")
350350
def test_api_error_handling(self, mock_posthog, mock_genai):
351351
mock_posthog.return_value = self.mock_posthog_client
@@ -366,7 +366,7 @@ def test_api_error_handling(self, mock_posthog, mock_genai):
366366
assert error_response["error"] == "Gemini API error"
367367

368368
@override_settings(GEMINI_API_KEY="test-api-key")
369-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
369+
@patch("posthoganalytics.ai.gemini.genai.Client")
370370
@patch("posthoganalytics.default_client")
371371
def test_generic_exception_handling(self, mock_posthog, mock_genai):
372372
mock_posthog.return_value = self.mock_posthog_client
@@ -385,7 +385,7 @@ def test_generic_exception_handling(self, mock_posthog, mock_genai):
385385
assert error_response["error"] == "Unexpected error"
386386

387387
@override_settings(GEMINI_API_KEY="test-api-key")
388-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
388+
@patch("posthoganalytics.ai.gemini.genai.Client")
389389
@patch("posthoganalytics.default_client")
390390
def test_missing_candidates_attribute(self, mock_posthog, mock_genai):
391391
mock_posthog.return_value = self.mock_posthog_client
@@ -409,7 +409,7 @@ def mock_stream():
409409
assert json.loads(responses[0].replace("data: ", "").strip()) == {"type": "text", "text": "Text response"}
410410

411411
@override_settings(GEMINI_API_KEY="test-api-key")
412-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
412+
@patch("posthoganalytics.ai.gemini.genai.Client")
413413
@patch("posthoganalytics.default_client")
414414
def test_candidate_without_content(self, mock_posthog, mock_genai):
415415
mock_posthog.return_value = self.mock_posthog_client
@@ -438,7 +438,7 @@ def mock_stream():
438438

439439
class TestGeminiIntegration(BaseTest):
440440
@override_settings(GEMINI_API_KEY="test-api-key")
441-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
441+
@patch("posthoganalytics.ai.gemini.genai.Client")
442442
@patch("posthoganalytics.default_client")
443443
@patch("products.llm_analytics.backend.providers.gemini.uuid.uuid4")
444444
def test_trace_id_generation(self, mock_uuid, mock_posthog, mock_genai):
@@ -471,7 +471,7 @@ def mock_stream():
471471
assert call_kwargs["posthog_trace_id"] == test_uuid
472472

473473
@override_settings(GEMINI_API_KEY="test-api-key")
474-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
474+
@patch("posthoganalytics.ai.gemini.genai.Client")
475475
@patch("posthoganalytics.default_client")
476476
def test_properties_include_ai_product(self, mock_posthog, mock_genai):
477477
mock_posthog.return_value = MagicMock()
@@ -508,7 +508,7 @@ def mock_stream():
508508
]
509509
)
510510
@override_settings(GEMINI_API_KEY="test-api-key")
511-
@patch("products.llm_analytics.backend.providers.gemini.genai.Client")
511+
@patch("posthoganalytics.ai.gemini.genai.Client")
512512
@patch("posthoganalytics.default_client")
513513
def test_temperature_and_max_tokens_handling(
514514
self, input_temp, input_max_tokens, expected_temp, expected_max_tokens, mock_posthog, mock_genai

products/workflows/backend/test/test_ses_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestSESProvider(TestCase):
1818
@classmethod
1919
def setUpClass(cls):
2020
# Patch boto3.client for all tests in this class
21-
patcher = patch("products.workflows.backend.providers.ses.boto3.client")
21+
patcher = patch("boto3.client")
2222
cls.boto3_client_patcher = patcher
2323
cls.mock_boto3_client = patcher.start()
2424

@@ -84,7 +84,7 @@ def test_create_email_domain_success(self):
8484

8585
provider.create_email_domain(TEST_DOMAIN, team_id=1)
8686

87-
@patch("products.workflows.backend.providers.ses.boto3.client")
87+
@patch("boto3.client")
8888
def test_create_email_domain_invalid_domain(self, mock_boto_client):
8989
with override_settings(
9090
SES_ACCESS_KEY_ID="test_access_key", SES_SECRET_ACCESS_KEY="test_secret_key", SES_REGION="us-east-1"

0 commit comments

Comments
 (0)