Home / File/ test_auth.py — langchain Source File

test_auth.py — langchain Source File

Architecture documentation for test_auth.py, a python file in the langchain codebase. 6 imports, 0 dependents.

File python LangChainCore Runnables 6 imports 5 classes

Entity Profile

Dependency Diagram

graph LR
  24ba4b1a_1f94_bed7_6c96_5631284214c2["test_auth.py"]
  d3750461_97f2_1730_4a69_37dae25b7cb2["base64"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> d3750461_97f2_1730_4a69_37dae25b7cb2
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  a35a9924_b1e5_1c65_4fd9_91d81872f712["langchain_ollama._utils"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> a35a9924_b1e5_1c65_4fd9_91d81872f712
  0c9395d5_1f45_412c_8466_04e26e6299fa["langchain_ollama.chat_models"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> 0c9395d5_1f45_412c_8466_04e26e6299fa
  0fd1a14f_839b_4084_7857_9c7d0106602e["langchain_ollama.embeddings"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> 0fd1a14f_839b_4084_7857_9c7d0106602e
  086e5ea5_bcac_bd46_1b81_e47115d3edf5["langchain_ollama.llms"]
  24ba4b1a_1f94_bed7_6c96_5631284214c2 --> 086e5ea5_bcac_bd46_1b81_e47115d3edf5
  style 24ba4b1a_1f94_bed7_6c96_5631284214c2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test URL authentication parsing functionality."""

import base64
from unittest.mock import MagicMock, patch

from langchain_ollama._utils import parse_url_with_auth
from langchain_ollama.chat_models import ChatOllama
from langchain_ollama.embeddings import OllamaEmbeddings
from langchain_ollama.llms import OllamaLLM

MODEL_NAME = "llama3.1"


class TestParseUrlWithAuth:
    """Test the parse_url_with_auth utility function."""

    def test_parse_url_with_auth_none_input(self) -> None:
        """Test that None input returns None, None."""
        result = parse_url_with_auth(None)
        assert result == (None, None)

    def test_parse_url_with_auth_no_credentials(self) -> None:
        """Test URLs without authentication credentials."""
        url = "https://ollama.example.com:11434/path?query=param"
        result = parse_url_with_auth(url)
        assert result == (url, None)

    def test_parse_url_with_auth_with_credentials(self) -> None:
        """Test URLs with authentication credentials."""
        url = "https://user:password@ollama.example.com:11434"
        cleaned_url, headers = parse_url_with_auth(url)

        expected_url = "https://ollama.example.com:11434"
        expected_credentials = base64.b64encode(b"user:password").decode()
        expected_headers = {"Authorization": f"Basic {expected_credentials}"}

        assert cleaned_url == expected_url
        assert headers == expected_headers

    def test_parse_url_with_auth_with_path_and_query(self) -> None:
        """Test URLs with auth, path, and query parameters."""
        url = "https://user:pass@ollama.example.com:11434/api/v1?timeout=30"
        cleaned_url, headers = parse_url_with_auth(url)

        expected_url = "https://ollama.example.com:11434/api/v1?timeout=30"
        expected_credentials = base64.b64encode(b"user:pass").decode()
        expected_headers = {"Authorization": f"Basic {expected_credentials}"}

        assert cleaned_url == expected_url
        assert headers == expected_headers

    def test_parse_url_with_auth_special_characters(self) -> None:
        """Test URLs with special characters in credentials."""
        url = "https://user%40domain:p%40ssw0rd@ollama.example.com:11434"
        cleaned_url, headers = parse_url_with_auth(url)

        expected_url = "https://ollama.example.com:11434"
        # Note: URL parsing handles percent-encoding automatically
        expected_credentials = base64.b64encode(b"user@domain:p@ssw0rd").decode()
        expected_headers = {"Authorization": f"Basic {expected_credentials}"}
// ... (172 more lines)

Domain

Subdomains

Dependencies

  • base64
  • langchain_ollama._utils
  • langchain_ollama.chat_models
  • langchain_ollama.embeddings
  • langchain_ollama.llms
  • unittest.mock

Frequently Asked Questions

What does test_auth.py do?
test_auth.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What does test_auth.py depend on?
test_auth.py imports 6 module(s): base64, langchain_ollama._utils, langchain_ollama.chat_models, langchain_ollama.embeddings, langchain_ollama.llms, unittest.mock.
Where is test_auth.py in the architecture?
test_auth.py is located at libs/partners/ollama/tests/unit_tests/test_auth.py (domain: LangChainCore, subdomain: Runnables, directory: libs/partners/ollama/tests/unit_tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free