|
| 1 | +import pytest |
| 2 | +from unittest.mock import patch, MagicMock |
| 3 | +from src.meilisearch_mcp.client import MeilisearchClient |
| 4 | +from src.meilisearch_mcp.__version__ import __version__ |
| 5 | + |
| 6 | + |
| 7 | +def test_meilisearch_client_sets_custom_user_agent(): |
| 8 | + """Test that MeilisearchClient initializes with custom user agent""" |
| 9 | + with patch("src.meilisearch_mcp.client.Client") as mock_client: |
| 10 | + # Create a MeilisearchClient instance |
| 11 | + client = MeilisearchClient(url="http://localhost:7700", api_key="test_key") |
| 12 | + |
| 13 | + # Verify that Client was called with the correct parameters |
| 14 | + mock_client.assert_called_once_with( |
| 15 | + "http://localhost:7700", |
| 16 | + "test_key", |
| 17 | + client_agents=("meilisearch-mcp", f"v{__version__}"), |
| 18 | + ) |
| 19 | + |
| 20 | + |
| 21 | +def test_user_agent_includes_correct_version(): |
| 22 | + """Test that the user agent includes the correct version from __version__.py""" |
| 23 | + with patch("src.meilisearch_mcp.client.Client") as mock_client: |
| 24 | + client = MeilisearchClient() |
| 25 | + |
| 26 | + # Extract the client_agents parameter from the call |
| 27 | + call_args = mock_client.call_args |
| 28 | + client_agents = call_args[1]["client_agents"] |
| 29 | + |
| 30 | + # Verify format and version |
| 31 | + assert client_agents[0] == "meilisearch-mcp" |
| 32 | + assert client_agents[1] == "v0.5.0" |
| 33 | + assert client_agents[1] == f"v{__version__}" |
0 commit comments