|
| 1 | +import pytest |
| 2 | +import requests |
| 3 | +from unittest.mock import patch |
| 4 | +from agentops.client.http.http_client import HttpClient |
| 5 | +from agentops.helpers.version import get_agentops_version |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture(autouse=True) |
| 9 | +def reset_http_client_session(): |
| 10 | + # Reset the cached session before each test |
| 11 | + HttpClient._session = None |
| 12 | + |
| 13 | + |
| 14 | +def test_user_agent_header(): |
| 15 | + with patch("requests.Session", wraps=requests.Session): |
| 16 | + session = HttpClient.get_session() |
| 17 | + expected_version = get_agentops_version() or "unknown" |
| 18 | + expected_user_agent = f"agentops-python/{expected_version}" |
| 19 | + # Check the session's headers directly |
| 20 | + assert "User-Agent" in session.headers |
| 21 | + assert session.headers["User-Agent"] == expected_user_agent |
| 22 | + |
| 23 | + |
| 24 | +def test_user_agent_header_content(): |
| 25 | + with patch("requests.Session", wraps=requests.Session): |
| 26 | + session = HttpClient.get_session() |
| 27 | + # Check the session's headers directly |
| 28 | + assert "User-Agent" in session.headers |
| 29 | + assert "Connection" in session.headers |
| 30 | + assert "Keep-Alive" in session.headers |
| 31 | + assert "Content-Type" in session.headers |
| 32 | + assert session.headers["Connection"] == "keep-alive" |
| 33 | + assert session.headers["Keep-Alive"] == "timeout=10, max=1000" |
| 34 | + assert session.headers["Content-Type"] == "application/json" |
0 commit comments