1
1
import logging
2
2
import threading
3
- import time
4
3
from unittest .mock import Mock , patch
5
- import pytest
6
4
7
5
from template_langgraph .llms .azure_openais import AzureOpenAiWrapper , Settings
8
6
@@ -26,8 +24,7 @@ def test_lazy_initialization_api_key(self, caplog):
26
24
with caplog .at_level (logging .INFO ):
27
25
# Creating instances should not trigger authentication
28
26
wrapper1 = AzureOpenAiWrapper (settings )
29
- wrapper2 = AzureOpenAiWrapper (settings )
30
-
27
+
31
28
# No authentication logs yet
32
29
assert "Using API key for authentication" not in caplog .text
33
30
@@ -49,7 +46,7 @@ def test_lazy_initialization_api_key(self, caplog):
49
46
# Should still be only one authentication log per model type
50
47
assert caplog .text .count ("Using API key for authentication" ) >= 1
51
48
52
- @patch (' template_langgraph.llms.azure_openais.DefaultAzureCredential' )
49
+ @patch (" template_langgraph.llms.azure_openais.DefaultAzureCredential" )
53
50
def test_singleton_credential_entra_id (self , mock_credential_class , caplog ):
54
51
"""Test that Microsoft Entra ID credentials are reused across instances."""
55
52
# Mock the credential and token
@@ -85,7 +82,7 @@ def test_singleton_credential_entra_id(self, mock_credential_class, caplog):
85
82
assert caplog .text .count ("Initializing Microsoft Entra ID authentication" ) == 1
86
83
assert caplog .text .count ("Getting authentication token" ) == 1
87
84
88
- @patch (' template_langgraph.llms.azure_openais.DefaultAzureCredential' )
85
+ @patch (" template_langgraph.llms.azure_openais.DefaultAzureCredential" )
89
86
def test_thread_safety (self , mock_credential_class ):
90
87
"""Test that authentication is thread-safe."""
91
88
mock_credential = Mock ()
@@ -174,10 +171,10 @@ def test_create_embedding_method_compatibility(self):
174
171
pass # Expected due to dummy credentials
175
172
176
173
# Verify the method exists and is callable
177
- assert hasattr (wrapper , ' create_embedding' )
178
- assert callable (getattr (wrapper , ' create_embedding' ))
174
+ assert hasattr (wrapper , " create_embedding" )
175
+ assert callable (getattr (wrapper , " create_embedding" ))
179
176
180
- @patch (' template_langgraph.llms.azure_openais.DefaultAzureCredential' )
177
+ @patch (" template_langgraph.llms.azure_openais.DefaultAzureCredential" )
181
178
def test_mixed_authentication_methods (self , mock_credential_class , caplog ):
182
179
"""Test using both authentication methods in different instances."""
183
180
mock_credential = Mock ()
@@ -212,4 +209,4 @@ def test_mixed_authentication_methods(self, mock_credential_class, caplog):
212
209
213
210
# Should see both authentication methods being used
214
211
assert "Using API key for authentication" in caplog .text
215
- assert "Initializing Microsoft Entra ID authentication" in caplog .text
212
+ assert "Initializing Microsoft Entra ID authentication" in caplog .text
0 commit comments