api_client = <rest_framework.test.APIClient object at 0x7f45de1c0550>
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f45de1c05f8>
def test_api_origin_search_ql_syntax_error(api_client, mocker):
mock_archive_search = mocker.patch("swh.web.common.archive.search")
mock_archive_search.origin_search.side_effect = SearchQuerySyntaxError(
"Invalid syntax"
)
query = "this is not a valid query"
url = reverse(
"api-1-origin-search",
url_args={"url_pattern": query},
query_params={"visit_type": "git", "use_ql": "true"},
)
> rv = check_api_get_responses(api_client, url, status_code=400)
.tox/py3/lib/python3.7/site-packages/swh/web/tests/api/views/test_origin.py:622:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/web/tests/utils.py:131: in check_api_get_responses
check_http_get_response(api_client, url, status_code, content_type="text/html")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
client = <rest_framework.test.APIClient object at 0x7f45de1c0550>
url = '/api/1/origin/search/this%20is%20not%20a%20valid%20query/?use_ql=true&visit_type=git'
status_code = 400, content_type = 'text/html', http_origin = None
server_name = None
def check_http_get_response(
client: Client,
url: str,
status_code: int,
content_type: str = "*/*",
http_origin: Optional[str] = None,
server_name: Optional[str] = None,
) -> HttpResponse:
"""Helper function to check HTTP response for a GET request.
Args:
client: Django test client
url: URL to check response
status_code: expected HTTP status code
content_type: expected response content type
http_origin: optional HTTP_ORIGIN header value
Returns:
The HTTP response
"""
actual_response = client.get(
url,
HTTP_ACCEPT=content_type,
HTTP_ORIGIN=http_origin,
SERVER_NAME=server_name if server_name else "testserver",
)
> assert isinstance(actual_response, Response)
E assert False
E + where False = isinstance(<HttpResponse status_code=400, "text/html; charset=utf-8">, Response)
.tox/py3/lib/python3.7/site-packages/swh/web/tests/utils.py:66: AssertionError
TEST RESULT
TEST RESULT
- Run At
- May 25 2022, 4:46 PM