TestChatOllamaUrlAuth Class — langchain Architecture
Architecture documentation for the TestChatOllamaUrlAuth class in test_auth.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6e62971c_d6df_2bdd_2586_c755947c90ab["TestChatOllamaUrlAuth"] 24ba4b1a_1f94_bed7_6c96_5631284214c2["test_auth.py"] 6e62971c_d6df_2bdd_2586_c755947c90ab -->|defined in| 24ba4b1a_1f94_bed7_6c96_5631284214c2 107ba097_78f8_bd04_b4aa_a5819e5aec8c["test_chat_ollama_url_auth_integration()"] 6e62971c_d6df_2bdd_2586_c755947c90ab -->|method| 107ba097_78f8_bd04_b4aa_a5819e5aec8c 25314da0_96ec_5aea_beef_9c14daa5685e["test_chat_ollama_url_auth_with_existing_headers()"] 6e62971c_d6df_2bdd_2586_c755947c90ab -->|method| 25314da0_96ec_5aea_beef_9c14daa5685e
Relationship Graph
Source Code
libs/partners/ollama/tests/unit_tests/test_auth.py lines 90–142
class TestChatOllamaUrlAuth:
"""Test URL authentication integration with ChatOllama."""
@patch("langchain_ollama.chat_models.Client")
@patch("langchain_ollama.chat_models.AsyncClient")
def test_chat_ollama_url_auth_integration(
self, mock_async_client: MagicMock, mock_client: MagicMock
) -> None:
"""Test that ChatOllama properly handles URL authentication."""
url_with_auth = "https://user:password@ollama.example.com:11434"
ChatOllama(
model=MODEL_NAME,
base_url=url_with_auth,
)
# Verify the clients were called with cleaned URL and auth headers
expected_url = "https://ollama.example.com:11434"
expected_credentials = base64.b64encode(b"user:password").decode()
expected_headers = {"Authorization": f"Basic {expected_credentials}"}
mock_client.assert_called_once_with(host=expected_url, headers=expected_headers)
mock_async_client.assert_called_once_with(
host=expected_url, headers=expected_headers
)
@patch("langchain_ollama.chat_models.Client")
@patch("langchain_ollama.chat_models.AsyncClient")
def test_chat_ollama_url_auth_with_existing_headers(
self, mock_async_client: MagicMock, mock_client: MagicMock
) -> None:
"""Test that URL auth headers merge with existing headers."""
url_with_auth = "https://user:password@ollama.example.com:11434"
existing_headers = {"User-Agent": "test-agent", "X-Custom": "value"}
ChatOllama(
model=MODEL_NAME,
base_url=url_with_auth,
client_kwargs={"headers": existing_headers},
)
# Verify headers are merged
expected_url = "https://ollama.example.com:11434"
expected_credentials = base64.b64encode(b"user:password").decode()
expected_headers = {
**existing_headers,
"Authorization": f"Basic {expected_credentials}",
}
mock_client.assert_called_once_with(host=expected_url, headers=expected_headers)
mock_async_client.assert_called_once_with(
host=expected_url, headers=expected_headers
)
Source
Frequently Asked Questions
What is the TestChatOllamaUrlAuth class?
TestChatOllamaUrlAuth is a class in the langchain codebase, defined in libs/partners/ollama/tests/unit_tests/test_auth.py.
Where is TestChatOllamaUrlAuth defined?
TestChatOllamaUrlAuth is defined in libs/partners/ollama/tests/unit_tests/test_auth.py at line 90.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free