-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Police-Data-Accessibility-Project/mc_issu…
…e_290_remove_datetime_of_request Mc issue 290 remove datetime of request
- Loading branch information
Showing
5 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
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 | ||
|
||
@pytest.fixture | ||
def mock_quick_search_query(monkeypatch): | ||
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): | ||
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): | ||
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." |