mirror of
https://github.com/ollama/ollama-python.git
synced 2026-01-13 21:57:16 +08:00
updated tests
This commit is contained in:
parent
d3ddff329f
commit
9d051dccae
@ -652,7 +652,7 @@ class Client(BaseClient):
|
||||
return self._request(
|
||||
WebSearchResponse,
|
||||
'POST',
|
||||
'http://localhost:8080/api/web_search',
|
||||
'https://ollama.com/api/web_search',
|
||||
json=WebSearchRequest(
|
||||
query=query,
|
||||
max_results=max_results,
|
||||
@ -675,7 +675,7 @@ class Client(BaseClient):
|
||||
return self._request(
|
||||
WebFetchResponse,
|
||||
'POST',
|
||||
'http://localhost:8080/api/web_fetch',
|
||||
'https://ollama.com/api/web_fetch',
|
||||
json=WebFetchRequest(
|
||||
url=url,
|
||||
).model_dump(exclude_none=True),
|
||||
|
||||
@ -1203,29 +1203,29 @@ def test_client_web_search_requires_bearer_auth_header(monkeypatch: pytest.Monke
|
||||
client = Client()
|
||||
|
||||
with pytest.raises(ValueError, match='Authorization header with Bearer token is required for web search'):
|
||||
client.web_search(['test query'])
|
||||
client.web_search('test query')
|
||||
|
||||
|
||||
def test_client_web_crawl_requires_bearer_auth_header(monkeypatch: pytest.MonkeyPatch):
|
||||
def test_client_web_fetch_requires_bearer_auth_header(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.delenv('OLLAMA_API_KEY', raising=False)
|
||||
|
||||
client = Client()
|
||||
|
||||
with pytest.raises(ValueError, match='Authorization header with Bearer token is required for web fetch'):
|
||||
client.web_crawl(['https://example.com'])
|
||||
client.web_fetch('https://example.com')
|
||||
|
||||
|
||||
def _mock_request_web_search(self, cls, method, url, json=None, **kwargs):
|
||||
assert method == 'POST'
|
||||
assert url == 'https://ollama.com/api/web_search'
|
||||
assert json is not None and 'queries' in json and 'max_results' in json
|
||||
assert json is not None and 'query' in json and 'max_results' in json
|
||||
return httpxResponse(status_code=200, content='{"results": {}, "success": true}')
|
||||
|
||||
|
||||
def _mock_request_web_crawl(self, cls, method, url, json=None, **kwargs):
|
||||
def _mock_request_web_fetch(self, cls, method, url, json=None, **kwargs):
|
||||
assert method == 'POST'
|
||||
assert url == 'https://ollama.com/api/web_crawl'
|
||||
assert json is not None and 'urls' in json
|
||||
assert url == 'https://ollama.com/api/web_fetch'
|
||||
assert json is not None and 'url' in json
|
||||
return httpxResponse(status_code=200, content='{"results": {}, "success": true}')
|
||||
|
||||
|
||||
@ -1234,15 +1234,15 @@ def test_client_web_search_with_env_api_key(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_search)
|
||||
|
||||
client = Client()
|
||||
client.web_search(['what is ollama?'], max_results=2)
|
||||
client.web_search('what is ollama?', max_results=2)
|
||||
|
||||
|
||||
def test_client_web_crawl_with_env_api_key(monkeypatch: pytest.MonkeyPatch):
|
||||
def test_client_web_fetch_with_env_api_key(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv('OLLAMA_API_KEY', 'test-key')
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_crawl)
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_fetch)
|
||||
|
||||
client = Client()
|
||||
client.web_crawl(['https://example.com'])
|
||||
client.web_fetch('https://example.com')
|
||||
|
||||
|
||||
def test_client_web_search_with_explicit_bearer_header(monkeypatch: pytest.MonkeyPatch):
|
||||
@ -1250,15 +1250,15 @@ def test_client_web_search_with_explicit_bearer_header(monkeypatch: pytest.Monke
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_search)
|
||||
|
||||
client = Client(headers={'Authorization': 'Bearer custom-token'})
|
||||
client.web_search(['what is ollama?'], max_results=1)
|
||||
client.web_search('what is ollama?', max_results=1)
|
||||
|
||||
|
||||
def test_client_web_crawl_with_explicit_bearer_header(monkeypatch: pytest.MonkeyPatch):
|
||||
def test_client_web_fetch_with_explicit_bearer_header(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.delenv('OLLAMA_API_KEY', raising=False)
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_crawl)
|
||||
monkeypatch.setattr(Client, '_request', _mock_request_web_fetch)
|
||||
|
||||
client = Client(headers={'Authorization': 'Bearer custom-token'})
|
||||
client.web_crawl(['https://example.com'])
|
||||
client.web_fetch('https://example.com')
|
||||
|
||||
|
||||
def test_client_bearer_header_from_env(monkeypatch: pytest.MonkeyPatch):
|
||||
@ -1274,4 +1274,4 @@ def test_client_explicit_bearer_header_overrides_env(monkeypatch: pytest.MonkeyP
|
||||
|
||||
client = Client(headers={'Authorization': 'Bearer explicit-token'})
|
||||
assert client._client.headers['authorization'] == 'Bearer explicit-token'
|
||||
client.web_search(['override check'])
|
||||
client.web_search('override check')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user