Skip to content

Commit

Permalink
Add tests for quick search functionality in test_QuickSearch.py"
Browse files Browse the repository at this point in the history
  • Loading branch information
maxachis committed Jun 2, 2024
1 parent 24a9a57 commit dcacd66
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/resources/test_QuickSearch.py
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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L1 <100>

Missing docstring in public module
Raw output
./tests/resources/test_QuickSearch.py:1:1: D100 Missing docstring in public module

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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L8 <401>

'tests.fixtures.client_with_mock_db' imported but unused
Raw output
./tests/resources/test_QuickSearch.py:8:1: F401 'tests.fixtures.client_with_mock_db' imported but unused

Check failure on line 8 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L8 <402>

module level import not at top of file
Raw output
./tests/resources/test_QuickSearch.py:8:1: E402 module level import not at top of file

@pytest.fixture

Check failure on line 10 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L10 <302>

expected 2 blank lines, found 1
Raw output
./tests/resources/test_QuickSearch.py:10:1: E302 expected 2 blank lines, found 1
def mock_quick_search_query(monkeypatch):

Check warning on line 11 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L11 <103>

Missing docstring in public function
Raw output
./tests/resources/test_QuickSearch.py:11:1: D103 Missing docstring in public function
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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L17 <103>

Missing docstring in public function
Raw output
./tests/resources/test_QuickSearch.py:17:1: D103 Missing docstring in public function

Check warning on line 17 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L17 <811>

redefinition of unused 'client_with_mock_db' from line 8
Raw output
./tests/resources/test_QuickSearch.py:17:41: F811 redefinition of unused 'client_with_mock_db' from line 8
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

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L29 <103>

Missing docstring in public function
Raw output
./tests/resources/test_QuickSearch.py:29:1: D103 Missing docstring in public function

Check failure on line 29 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L29 <302>

expected 2 blank lines, found 1
Raw output
./tests/resources/test_QuickSearch.py:29:1: E302 expected 2 blank lines, found 1

Check warning on line 29 in tests/resources/test_QuickSearch.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/resources/test_QuickSearch.py#L29 <811>

redefinition of unused 'client_with_mock_db' from line 8
Raw output
./tests/resources/test_QuickSearch.py:29:45: F811 redefinition of unused 'client_with_mock_db' from line 8
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."

0 comments on commit dcacd66

Please sign in to comment.