-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import patch, MagicMock | ||
Check warning on line 1 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L1 <100>
Raw output
|
||
|
||
import pytest | ||
|
||
from tests.helper_functions import check_response_status | ||
|
||
patch("middleware.security.api_required", lambda x: x).start() | ||
from tests.fixtures import client_with_mock_db | ||
Check warning on line 8 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L8 <401>
Raw output
Check failure on line 8 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L8 <402>
Raw output
|
||
|
||
@pytest.fixture | ||
Check failure on line 10 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L10 <302>
Raw output
|
||
def mock_quick_search_query(monkeypatch): | ||
Check warning on line 11 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L11 <103>
Raw output
|
||
mock = MagicMock() | ||
monkeypatch.setattr("resources.QuickSearch.quick_search_query", mock) | ||
return mock | ||
|
||
|
||
def test_get_quick_search_results_found(client_with_mock_db, mock_quick_search_query): | ||
Check warning on line 17 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L17 <103>
Raw output
Check warning on line 17 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L17 <811>
Raw output
|
||
mock_quick_search_query.return_value = { | ||
"count": "1", | ||
"data": [{"id": "test_id", "name": "test_name"}], | ||
} | ||
response = client_with_mock_db.client.get("/quick-search/test_search/test_location") | ||
check_response_status(response, 200) | ||
response_json = response.json | ||
assert response_json["data"]["data"] == [{'id': 'test_id', 'name': 'test_name'}] | ||
assert response_json["data"]["count"] == '1' | ||
assert response_json["message"] == "Results for search successfully retrieved" | ||
|
||
def test_get_quick_search_results_not_found(client_with_mock_db, mock_quick_search_query): | ||
Check warning on line 29 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L29 <103>
Raw output
Check failure on line 29 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L29 <302>
Raw output
Check warning on line 29 in tests/resources/test_QuickSearch.py GitHub Actions / flake8[flake8] tests/resources/test_QuickSearch.py#L29 <811>
Raw output
|
||
mock_quick_search_query.return_value = { | ||
"count": 0, | ||
"data": [], | ||
} | ||
response = client_with_mock_db.client.get("/quick-search/test_search/test_location") | ||
check_response_status(response, 404) | ||
response_json = response.json | ||
assert response_json["count"] == 0 | ||
assert response_json["message"] == "No results found. Please considering requesting a new data source." |