diff --git a/swh/web/api/apidoc.py b/swh/web/api/apidoc.py --- a/swh/web/api/apidoc.py +++ b/swh/web/api/apidoc.py @@ -288,7 +288,6 @@ def api_doc( route: str, noargs: bool = False, - need_params: bool = False, tags: List[str] = [], handle_response: bool = False, api_version: str = "1", @@ -305,9 +304,6 @@ noargs: set to True if the route has no arguments, and its result should be displayed anytime its documentation is requested. Default to False - need_params: specify the route requires query parameters - otherwise errors will occur. It enables to avoid displaying the - invalid response in its HTML documentation. Default to False. tags: Further information on api endpoints. Two values are possibly expected: @@ -353,19 +349,11 @@ @wraps(f) def documented_view(request, **kwargs): doc_data = get_doc_data(f, route, noargs) - try: response = f(request, **kwargs) except Exception as exc: sentry_sdk.capture_exception(exc) - if ( - request.accepted_media_type == "text/html" - and need_params - and not request.query_params - ): - response = None - else: - return error_response(request, exc, doc_data) + return error_response(request, exc, doc_data) if handle_response: return response diff --git a/swh/web/api/views/origin.py b/swh/web/api/views/origin.py --- a/swh/web/api/views/origin.py +++ b/swh/web/api/views/origin.py @@ -218,7 +218,7 @@ @api_route(r"/origin/metadata-search/", "api-1-origin-metadata-search") -@api_doc("/origin/metadata-search/", noargs=True, need_params=True) +@api_doc("/origin/metadata-search/", noargs=True) @format_docstring(return_origin_array=DOC_RETURN_ORIGIN_ARRAY) def api_origin_metadata_search(request): """ @@ -248,7 +248,6 @@ """ fulltext = request.query_params.get("fulltext", None) limit = min(int(request.query_params.get("limit", "70")), 100) - if not fulltext: content = '"fulltext" must be provided and non-empty.' raise BadInputExc(content) diff --git a/swh/web/tests/api/views/__init__.py b/swh/web/tests/api/views/__init__.py --- a/swh/web/tests/api/views/__init__.py +++ b/swh/web/tests/api/views/__init__.py @@ -0,0 +1,71 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from typing import Any, Dict, Optional + +from rest_framework.test import APIClient +from rest_framework.response import Response + + +def check_api_get_responses( + api_client: APIClient, url: str, status_code: int +) -> Response: + """Helper function to check Web API responses to GET requests + for all accepted content types. + + Args: + api_client: DRF test client + url: Web API URL to check responses + status_code: expected HTTP status code + + Returns: + The Web API JSON response + """ + # check API Web UI + html_content_type = "text/html" + resp = api_client.get(url, HTTP_ACCEPT=html_content_type) + assert resp.status_code == status_code, resp.content + assert resp["Content-Type"] == html_content_type + + # check YAML response + yaml_content_type = "application/yaml" + resp = api_client.get(url, HTTP_ACCEPT=yaml_content_type) + assert resp.status_code == status_code, resp.data + assert resp["Content-Type"] == yaml_content_type + + # check JSON response + resp = api_client.get(url) + assert resp.status_code == status_code, resp.data + assert resp["Content-Type"] == "application/json" + + return resp + + +def check_api_post_responses( + api_client: APIClient, url: str, data: Optional[Dict[str, Any]], status_code: int +) -> Response: + """Helper function to check Web API responses to POST requests + for all accepted content types. + + Args: + api_client: DRF test client + url: Web API URL to check responses + status_code: expected HTTP status code + + Returns: + The Web API JSON response + """ + # check YAML response + yaml_content_type = "application/yaml" + resp = api_client.post(url, data=data, format="json", HTTP_ACCEPT=yaml_content_type) + assert resp.status_code == status_code, resp.data + assert resp["Content-Type"] == yaml_content_type + + # check JSON response + resp = api_client.post(url, data=data, format="json") + assert resp.status_code == status_code, resp.data + assert resp["Content-Type"] == "application/json" + + return resp diff --git a/swh/web/tests/api/views/test_content.py b/swh/web/tests/api/views/test_content.py --- a/swh/web/tests/api/views/test_content.py +++ b/swh/web/tests/api/views/test_content.py @@ -8,6 +8,7 @@ from hypothesis import given from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses, check_api_post_responses from swh.web.tests.data import random_content from swh.web.tests.strategies import content, contents_with_ctags from swh.web.tests.conftest import ctags_json_missing, fossology_missing @@ -19,10 +20,8 @@ url = reverse( "api-1-content-filetype", url_args={"q": "sha1_git:%s" % content["sha1_git"]} ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" content_url = reverse( "api-1-content", url_args={"q": "sha1:%s" % content["sha1"]}, @@ -39,10 +38,8 @@ url = reverse( "api-1-content-filetype", url_args={"q": "sha1:%s" % unknown_content_["sha1"]} ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=404) - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == { "exception": "NotFoundExc", "reason": "No filetype information found for content " @@ -57,10 +54,8 @@ url = reverse( "api-1-content-language", url_args={"q": "sha1_git:%s" % content["sha1_git"]} ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" content_url = reverse( "api-1-content", url_args={"q": "sha1:%s" % content["sha1"]}, @@ -77,10 +72,7 @@ url = reverse( "api-1-content-language", url_args={"q": "sha1:%s" % unknown_content_["sha1"]} ) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "No language information found for content " @@ -106,10 +98,8 @@ url_args={"q": contents_with_ctags["symbol_name"]}, query_params={"per_page": 100}, ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" for entry in rv.data: content_sha1 = entry["sha1"] expected_entry = expected_data[content_sha1] @@ -135,7 +125,8 @@ url_args={"q": contents_with_ctags["symbol_name"]}, query_params={"per_page": 2}, ) - rv = api_client.get(url) + + rv = check_api_get_responses(api_client, url, status_code=200) next_url = ( reverse( @@ -150,10 +141,7 @@ def test_api_content_symbol_not_found(api_client): url = reverse("api-1-content-symbol", url_args={"q": "bar"}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "No indexed raw content match expression 'bar'.", @@ -170,10 +158,7 @@ url = reverse( "api-1-content-ctags", url_args={"q": "sha1_git:%s" % content["sha1_git"]} ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) content_url = reverse( "api-1-content", url_args={"q": "sha1:%s" % content["sha1"]}, @@ -192,10 +177,7 @@ url = reverse( "api-1-content-license", url_args={"q": "sha1_git:%s" % content["sha1_git"]} ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) content_url = reverse( "api-1-content", url_args={"q": "sha1:%s" % content["sha1"]}, @@ -212,10 +194,7 @@ url = reverse( "api-1-content-license", url_args={"q": "sha1:%s" % unknown_content_["sha1"]} ) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "No license information found for content " @@ -226,10 +205,7 @@ @given(content()) def test_api_content_metadata(api_client, archive_data, content): url = reverse("api-1-content", {"q": "sha1:%s" % content["sha1"]}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_data = archive_data.content_get(content["sha1"]) for key, view_name in ( ("data_url", "api-1-content-raw"), @@ -245,13 +221,11 @@ assert rv.data == expected_data -def test_api_content_not_found_as_json(api_client): +def test_api_content_not_found(api_client): unknown_content_ = random_content() url = reverse("api-1-content", url_args={"q": "sha1:%s" % unknown_content_["sha1"]}) - rv = api_client.get(url) - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Content with sha1 checksum equals to %s not found!" @@ -259,34 +233,13 @@ } -def test_api_content_not_found_as_yaml(api_client): - unknown_content_ = random_content() - - url = reverse( - "api-1-content", url_args={"q": "sha256:%s" % unknown_content_["sha256"]} - ) - rv = api_client.get(url, HTTP_ACCEPT="application/yaml") - - assert rv.status_code == 404, rv.data - assert "application/yaml" in rv["Content-Type"] - - assert rv.data == { - "exception": "NotFoundExc", - "reason": "Content with sha256 checksum equals to %s not found!" - % unknown_content_["sha256"], - } - - def test_api_content_raw_ko_not_found(api_client): unknown_content_ = random_content() url = reverse( "api-1-content-raw", url_args={"q": "sha1:%s" % unknown_content_["sha1"]} ) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Content with sha1 checksum equals to %s not found!" @@ -331,25 +284,7 @@ @given(content()) def test_api_check_content_known(api_client, content): url = reverse("api-1-content-known", url_args={"q": content["sha1"]}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" - - assert rv.data == { - "search_res": [{"found": True, "sha1": content["sha1"]}], - "search_stats": {"nbfiles": 1, "pct": 100.0}, - } - - -@given(content()) -def test_api_check_content_known_as_yaml(api_client, content): - url = reverse("api-1-content-known", url_args={"q": content["sha1"]}) - rv = api_client.get(url, HTTP_ACCEPT="application/yaml") - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/yaml" - + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == { "search_res": [{"found": True, "sha1": content["sha1"]}], "search_stats": {"nbfiles": 1, "pct": 100.0}, @@ -357,14 +292,12 @@ @given(content()) -def test_api_check_content_known_post_as_yaml(api_client, content): +def test_api_check_content_known_post(api_client, content): url = reverse("api-1-content-known") - rv = api_client.post( - url, data={"q": content["sha1"]}, HTTP_ACCEPT="application/yaml" + rv = check_api_post_responses( + api_client, url, data={"q": content["sha1"]}, status_code=200 ) - assert rv.status_code == 200, rv.data - assert "application/yaml" in rv["Content-Type"] assert rv.data == { "search_res": [{"found": True, "sha1": content["sha1"]}], "search_stats": {"nbfiles": 1, "pct": 100.0}, @@ -375,10 +308,7 @@ unknown_content_ = random_content() url = reverse("api-1-content-known", url_args={"q": unknown_content_["sha1"]}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == { "search_res": [{"found": False, "sha1": unknown_content_["sha1"]}], "search_stats": {"nbfiles": 1, "pct": 0.0}, diff --git a/swh/web/tests/api/views/test_directory.py b/swh/web/tests/api/views/test_directory.py --- a/swh/web/tests/api/views/test_directory.py +++ b/swh/web/tests/api/views/test_directory.py @@ -9,6 +9,7 @@ from swh.web.api.utils import enrich_directory from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import directory @@ -17,10 +18,7 @@ def test_api_directory(api_client, archive_data, directory): url = reverse("api-1-directory", url_args={"sha1_git": directory}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) dir_content = list(archive_data.directory_ls(directory)) expected_data = list( @@ -34,10 +32,7 @@ unknown_directory_ = random_sha1() url = reverse("api-1-directory", url_args={"sha1_git": unknown_directory_}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Directory with sha1_git %s not found" % unknown_directory_, @@ -53,10 +48,7 @@ url = reverse( "api-1-directory", url_args={"sha1_git": directory, "path": path["name"]} ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == enrich_directory(path, rv.wsgi_request) @@ -65,10 +57,7 @@ path = "some/path/to/nonexistent/dir/" url = reverse("api-1-directory", url_args={"sha1_git": directory, "path": path}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": ( diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py --- a/swh/web/tests/api/views/test_identifiers.py +++ b/swh/web/tests/api/views/test_identifiers.py @@ -9,6 +9,7 @@ from swh.web.common.identifiers import gen_swhid from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses, check_api_post_responses from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import ( content, @@ -41,7 +42,7 @@ swhid = gen_swhid(obj_type, obj_id, metadata={"origin": origin["url"]}) url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid}) - resp = api_client.get(url) + resp = check_api_get_responses(api_client, url, status_code=200) if obj_type == CONTENT: url_args = {"query_string": "sha1_git:%s" % obj_id} @@ -66,23 +67,14 @@ "scheme_version": 1, } - assert resp.status_code == 200, resp.data assert resp.data == expected_result - # also checks endpoint documented view - # TODO: remove that check once T2529 is implemented - resp = client.get(url, HTTP_ACCEPT="text/html") - assert resp.status_code == 200, resp.content - def test_swhid_resolve_invalid(api_client): rev_id_invalid = "96db9023b8_foo_50d6c108e9a3" swhid = "swh:1:rev:%s" % rev_id_invalid url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid}) - - resp = api_client.get(url) - - assert resp.status_code == 400, resp.data + check_api_get_responses(api_client, url, status_code=400) @given( @@ -113,16 +105,13 @@ url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid}) - resp = api_client.get(url) - - assert resp.status_code == 404, resp.data + check_api_get_responses(api_client, url, status_code=404) def test_swh_origin_id_not_resolvable(api_client): ori_swhid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb" url = reverse("api-1-resolve-swhid", url_args={"swhid": ori_swhid}) - resp = api_client.get(url) - assert resp.status_code == 400, resp.data + check_api_get_responses(api_client, url, status_code=400) @given(content(), directory()) @@ -143,12 +132,8 @@ url = reverse("api-1-known") - resp = api_client.post( - url, data=input_swhids, format="json", HTTP_ACCEPT="application/json" - ) + resp = check_api_post_responses(api_client, url, data=input_swhids, status_code=200) - assert resp.status_code == 200, resp.data - assert resp["Content-Type"] == "application/json" assert resp.data == { content_: {"known": True}, directory_: {"known": True}, @@ -164,17 +149,9 @@ url = reverse("api-1-known") - resp = api_client.post( - url, data=invalid_swhid_sha1, format="json", HTTP_ACCEPT="application/json" - ) - - assert resp.status_code == 400, resp.data - - resp2 = api_client.post( - url, data=invalid_swhid_type, format="json", HTTP_ACCEPT="application/json" - ) + check_api_post_responses(api_client, url, data=invalid_swhid_sha1, status_code=400) - assert resp2.status_code == 400, resp.data + check_api_post_responses(api_client, url, data=invalid_swhid_type, status_code=400) def test_api_known_raises_large_payload_error(api_client): @@ -185,10 +162,6 @@ swhids = [random_swhid for i in range(limit)] url = reverse("api-1-known") - resp = api_client.post( - url, data=swhids, format="json", HTTP_ACCEPT="application/json" - ) + resp = check_api_post_responses(api_client, url, data=swhids, status_code=413) - assert resp.status_code == 413, resp.data - assert resp["Content-Type"] == "application/json" assert resp.data == {"exception": "LargePayloadExc", "reason": err_msg} diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -18,6 +18,7 @@ from swh.web.common.exc import BadInputExc from swh.web.common.utils import reverse from swh.web.common.origin_visits import get_origin_visits +from swh.web.tests.api.views import check_api_get_responses from swh.web.tests.strategies import origin, new_origin, visit_dates, new_snapshots @@ -55,10 +56,7 @@ mock_get_origin_visits.side_effect = BadInputExc(err_msg) url = reverse("api-1-origin-visits", url_args={"origin_url": "http://foo"}) - rv = api_client.get(url) - - assert rv.status_code == 400, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=400) assert rv.data == {"exception": "BadInputExc", "reason": err_msg} @@ -69,10 +67,7 @@ mock_get_origin_visits.side_effect = StorageDBError(err_msg) url = reverse("api-1-origin-visits", url_args={"origin_url": "http://foo"}) - rv = api_client.get(url) - - assert rv.status_code == 503, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=503) assert rv.data == { "exception": "StorageDBError", "reason": "An unexpected error occurred in the backend: %s" % err_msg, @@ -86,10 +81,7 @@ mock_get_origin_visits.side_effect = StorageAPIError(err_msg) url = reverse("api-1-origin-visits", url_args={"origin_url": "http://foo"}) - rv = api_client.get(url) - - assert rv.status_code == 503, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=503) assert rv.data == { "exception": "StorageAPIError", "reason": "An unexpected error occurred in the api backend: %s" % err_msg, @@ -129,10 +121,7 @@ query_params={"per_page": 2, "last_visit": last_visit}, ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) for i in range(len(expected_visits)): expected_visits[i] = enrich_origin_visit( @@ -177,10 +166,7 @@ query_params={"per_page": 2, "last_visit": last_visit}, ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) for i in range(len(expected_visits)): expected_visits[i] = enrich_origin_visit( @@ -217,9 +203,7 @@ url_args={"origin_url": new_origin.url, "visit_id": visit_id}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_visit = archive_data.origin_visit_get_by(new_origin.url, visit_id) @@ -239,8 +223,7 @@ url = reverse("api-1-origin-visit-latest", url_args={"origin_url": new_origin.url}) - rv = api_client.get(url) - assert rv.status_code == 404, rv.data + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "No visit for origin %s found" % new_origin.url, @@ -273,10 +256,7 @@ url = reverse("api-1-origin-visit-latest", url_args={"origin_url": new_origin.url}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_visit = archive_data.origin_visit_get_by(new_origin.url, visit_ids[1]) @@ -322,10 +302,7 @@ query_params={"require_snapshot": True}, ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_visit = archive_data.origin_visit_status_get_latest( new_origin.url, type="git", require_snapshot=True @@ -353,10 +330,7 @@ url_args={"origin_url": origin["url"], "visit_id": max_visit_id + 1}, ) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Origin %s or its visit with id %s not found!" @@ -370,10 +344,7 @@ """ # fail if wrong input url = reverse("api-1-origins", query_params={"origin_from": 1}) - rv = api_client.get(url) - - assert rv.status_code == 400, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=400) assert rv.data == { "exception": "BadInputExc", @@ -388,26 +359,19 @@ # Get only one url = reverse("api-1-origins", query_params={"origin_count": 1}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 assert {origin["url"] for origin in rv.data} <= origin_urls # Get all url = reverse("api-1-origins", query_params={"origin_count": len(origins)}) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == len(origins) assert {origin["url"] for origin in rv.data} == origin_urls # Get "all + 10" url = reverse("api-1-origins", query_params={"origin_count": len(origins) + 10}) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == len(origins) assert {origin["url"] for origin in rv.data} == origin_urls @@ -430,13 +394,10 @@ def test_api_origin_by_url(api_client, archive_data, origin): origin_url = origin["url"] url = reverse("api-1-origin", url_args={"origin_url": origin_url}) - rv = api_client.get(url) - + rv = check_api_get_responses(api_client, url, status_code=200) expected_origin = archive_data.origin_get([origin_url])[0] expected_origin = enrich_origin(expected_origin, rv.wsgi_request) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_origin @@ -444,10 +405,7 @@ def test_api_origin_not_found(api_client, new_origin): url = reverse("api-1-origin", url_args={"origin_url": new_origin.url}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Origin with url %s not found!" % new_origin.url, @@ -471,9 +429,7 @@ url_args={"url_pattern": "github.com"}, query_params={"limit": 1}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 assert {origin["url"] for origin in rv.data} <= expected_origins @@ -483,9 +439,7 @@ url_args={"url_pattern": "github.com"}, query_params={"limit": 2}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert {origin["url"] for origin in rv.data} == expected_origins # Search for 'github.com', get more than available @@ -494,9 +448,7 @@ url_args={"url_pattern": "github.com"}, query_params={"limit": 10}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert {origin["url"] for origin in rv.data} == expected_origins @@ -516,9 +468,7 @@ url_args={"url_pattern": "github com"}, query_params={"limit": 2}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert {origin["url"] for origin in rv.data} == expected_origins url = reverse( @@ -526,9 +476,7 @@ url_args={"url_pattern": "com github"}, query_params={"limit": 2}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert {origin["url"] for origin in rv.data} == expected_origins url = reverse( @@ -536,9 +484,7 @@ url_args={"url_pattern": "memononen libtess2"}, query_params={"limit": 2}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 assert {origin["url"] for origin in rv.data} == { "https://github.com/memononen/libtess2" @@ -549,9 +495,7 @@ url_args={"url_pattern": "libtess2 memononen"}, query_params={"limit": 2}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 assert {origin["url"] for origin in rv.data} == { "https://github.com/memononen/libtess2" @@ -601,9 +545,7 @@ url_args={"url_pattern": "foobar"}, query_params={"limit": 1050}, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1000 @@ -631,10 +573,7 @@ ] url = reverse("api-1-origin-metadata-search", query_params={"fulltext": "Jane Doe"}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.content - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_data = [ { "url": origin["url"], @@ -683,10 +622,7 @@ ] url = reverse("api-1-origin-metadata-search", query_params={"fulltext": "Jane Doe"}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.content - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 oimsft.assert_called_with(conjunction=["Jane Doe"], limit=70) @@ -694,10 +630,7 @@ "api-1-origin-metadata-search", query_params={"fulltext": "Jane Doe", "limit": 10}, ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.content - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 oimsft.assert_called_with(conjunction=["Jane Doe"], limit=10) @@ -705,10 +638,7 @@ "api-1-origin-metadata-search", query_params={"fulltext": "Jane Doe", "limit": 987}, ) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.content - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert len(rv.data) == 1 oimsft.assert_called_with(conjunction=["Jane Doe"], limit=100) @@ -739,11 +669,10 @@ url = reverse( "api-origin-intrinsic-metadata", url_args={"origin_url": origin["url"]} ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) + + oimg.assert_called_with([origin["url"]]) - oimg.assert_called_once_with([origin["url"]]) - assert rv.status_code == 200, rv.content - assert rv["Content-Type"] == "application/json" expected_data = {"author": "Jane Doe"} assert rv.data == expected_data @@ -751,7 +680,5 @@ def test_api_origin_metadata_search_invalid(api_client, mocker): mock_idx_storage = mocker.patch("swh.web.common.service.idx_storage") url = reverse("api-1-origin-metadata-search") - rv = api_client.get(url) - - assert rv.status_code == 400, rv.content + check_api_get_responses(api_client, url, status_code=400) mock_idx_storage.assert_not_called() diff --git a/swh/web/tests/api/views/test_origin_save.py b/swh/web/tests/api/views/test_origin_save.py --- a/swh/web/tests/api/views/test_origin_save.py +++ b/swh/web/tests/api/views/test_origin_save.py @@ -15,14 +15,13 @@ SAVE_REQUEST_ACCEPTED, SAVE_REQUEST_REJECTED, SAVE_REQUEST_PENDING, -) -from swh.web.common.models import ( SAVE_TASK_NOT_CREATED, SAVE_TASK_NOT_YET_SCHEDULED, SAVE_TASK_SCHEDULED, SAVE_TASK_FAILED, SAVE_TASK_SUCCEED, ) +from swh.web.tests.api.views import check_api_get_responses, check_api_post_responses pytestmark = pytest.mark.django_db @@ -41,18 +40,14 @@ "origin_url": "https://github.com/torvalds/linux", }, ) - - response = api_client.post(url) - assert response.status_code == 400 + check_api_get_responses(api_client, url, status_code=400) def test_invalid_origin_url(api_client): url = reverse( "api-1-save-origin", url_args={"visit_type": "git", "origin_url": "bar"} ) - - response = api_client.post(url) - assert response.status_code == 400 + check_api_get_responses(api_client, url, status_code=400) def check_created_save_request_status( @@ -99,14 +94,13 @@ ("swh.web.common.origin_save." "_get_visit_info_for_save_request") ) mock_visit_date.return_value = (visit_date, None) - response = api_client.post(url) if expected_request_status != SAVE_REQUEST_REJECTED: - assert response.status_code == 200, response.data + response = check_api_post_responses(api_client, url, data=None, status_code=200) assert response.data["save_request_status"] == expected_request_status assert response.data["save_task_status"] == expected_task_status else: - assert response.status_code == 403, response.data + check_api_post_responses(api_client, url, data=None, status_code=403) def check_save_request_status( @@ -138,8 +132,7 @@ ("swh.web.common.origin_save." "_get_visit_info_for_save_request") ) mock_visit_date.return_value = (visit_date, None) - response = api_client.get(url) - assert response.status_code == 200, response.data + response = check_api_get_responses(api_client, url, status_code=200) save_request_data = response.data[0] assert save_request_data["save_request_status"] == expected_request_status @@ -148,8 +141,7 @@ # Check that save task status is still available when # the scheduler task has been archived mock_scheduler.get_tasks.return_value = [] - response = api_client.get(url) - assert response.status_code == 200 + response = check_api_get_responses(api_client, url, status_code=200) save_request_data = response.data[0] assert save_request_data["save_task_status"] == expected_task_status @@ -295,7 +287,8 @@ sors = list( SaveOriginRequest.objects.filter(visit_type="git", origin_url=origin_url) ) - assert len(sors) == 2 + # check_api_post_responses sends two POST requests to check YAML and JSON response + assert len(sors) == 3 check_created_save_request_status( api_client, @@ -308,7 +301,7 @@ sors = list( SaveOriginRequest.objects.filter(visit_type="git", origin_url=origin_url) ) - assert len(sors) == 3 + assert len(sors) == 5 def test_get_save_requests_unknown_origin(api_client): @@ -317,8 +310,7 @@ "api-1-save-origin", url_args={"visit_type": "git", "origin_url": unknown_origin_url}, ) - response = api_client.get(url) - assert response.status_code == 404 + response = check_api_get_responses(api_client, url, status_code=404) assert response.data == { "exception": "NotFoundExc", "reason": ( diff --git a/swh/web/tests/api/views/test_ping.py b/swh/web/tests/api/views/test_ping.py --- a/swh/web/tests/api/views/test_ping.py +++ b/swh/web/tests/api/views/test_ping.py @@ -4,13 +4,10 @@ # See top-level LICENSE file for more information from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses def test_api_1_ping(api_client): url = reverse("api-1-ping") - - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == "pong" diff --git a/swh/web/tests/api/views/test_release.py b/swh/web/tests/api/views/test_release.py --- a/swh/web/tests/api/views/test_release.py +++ b/swh/web/tests/api/views/test_release.py @@ -15,6 +15,7 @@ TimestampWithTimezone, ) from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import release, content, directory @@ -23,7 +24,7 @@ def test_api_release(api_client, archive_data, release): url = reverse("api-1-release", url_args={"sha1_git": release}) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) expected_release = archive_data.release_get(release) target_revision = expected_release["target"] @@ -34,8 +35,6 @@ ) expected_release["target_url"] = target_url - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_release @@ -78,7 +77,7 @@ url = reverse("api-1-release", url_args={"sha1_git": new_release_id}) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) expected_release = archive_data.release_get(new_release_id) @@ -92,8 +91,6 @@ ) expected_release["target_url"] = target_url - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_release @@ -102,10 +99,7 @@ url = reverse("api-1-release", url_args={"sha1_git": unknown_release_}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Release with sha1_git %s not found." % unknown_release_, diff --git a/swh/web/tests/api/views/test_revision.py b/swh/web/tests/api/views/test_revision.py --- a/swh/web/tests/api/views/test_revision.py +++ b/swh/web/tests/api/views/test_revision.py @@ -8,6 +8,7 @@ from swh.web.api.utils import enrich_revision from swh.web.common.exc import NotFoundExc from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import revision @@ -15,14 +16,12 @@ @given(revision()) def test_api_revision(api_client, archive_data, revision): url = reverse("api-1-revision", url_args={"sha1_git": revision}) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) expected_revision = archive_data.revision_get(revision) enrich_revision(expected_revision, rv.wsgi_request) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_revision @@ -30,10 +29,7 @@ unknown_revision_ = random_sha1() url = reverse("api-1-revision", url_args={"sha1_git": unknown_revision_}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Revision with sha1_git %s not found." % unknown_revision_, @@ -49,6 +45,7 @@ assert rv.status_code == 200 assert rv["Content-Type"] == "application/octet-stream" + assert rv.content == expected_message.encode() @@ -58,10 +55,7 @@ url = reverse( "api-1-revision-raw-message", url_args={"sha1_git": unknown_revision_} ) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Revision with sha1_git %s not found." % unknown_revision_, @@ -78,15 +72,13 @@ query_params={"limit": limit}, ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) expected_log = archive_data.revision_log(revision, limit=limit) expected_log = list( map(enrich_revision, expected_log, [rv.wsgi_request] * len(expected_log)) ) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_log @@ -95,10 +87,7 @@ url = reverse("api-1-revision-log", url_args={"sha1_git": unknown_revision_}) - rv = api_client.get(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data == { "exception": "NotFoundExc", "reason": "Revision with sha1_git %s not found." % unknown_revision_, @@ -110,17 +99,13 @@ mock_rev_dir = mocker.patch("swh.web.api.views.revision._revision_directory_by") mock_rev_dir.side_effect = NotFoundExc("Not found") - rv = api_client.get("/api/1/revision/999/directory/some/path/to/dir/") + url = "/api/1/revision/999/directory/some/path/to/dir/" + rv = check_api_get_responses(api_client, url, status_code=404) - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == {"exception": "NotFoundExc", "reason": "Not found"} - mock_rev_dir.assert_called_once_with( - {"sha1_git": "999"}, - "some/path/to/dir", - "/api/1/revision/999/directory/some/path/to/dir/", - with_data=False, + mock_rev_dir.assert_called_with( + {"sha1_git": "999"}, "some/path/to/dir", url, with_data=False, ) @@ -150,8 +135,8 @@ } mock_rev_dir.return_value = stub_dir - - rv = api_client.get("/api/1/revision/999/directory/some/path/") + url = "/api/1/revision/999/directory/some/path/" + rv = check_api_get_responses(api_client, url, status_code=200) stub_dir["content"][0]["target_url"] = rv.wsgi_request.build_absolute_uri( stub_dir["content"][0]["target_url"] @@ -166,15 +151,10 @@ stub_dir["content"][1]["dir_url"] ) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == stub_dir - mock_rev_dir.assert_called_once_with( - {"sha1_git": "999"}, - "some/path", - "/api/1/revision/999/directory/some/path/", - with_data=False, + mock_rev_dir.assert_called_with( + {"sha1_git": "999"}, "some/path", url, with_data=False, ) @@ -193,17 +173,15 @@ mock_rev_dir.return_value = stub_content url = "/api/1/revision/666/directory/some/other/path/" - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) stub_content["content"]["data_url"] = rv.wsgi_request.build_absolute_uri( stub_content["content"]["data_url"] ) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == stub_content - mock_rev_dir.assert_called_once_with( + mock_rev_dir.assert_called_with( {"sha1_git": "666"}, "some/other/path", url, with_data=False ) diff --git a/swh/web/tests/api/views/test_snapshot.py b/swh/web/tests/api/views/test_snapshot.py --- a/swh/web/tests/api/views/test_snapshot.py +++ b/swh/web/tests/api/views/test_snapshot.py @@ -11,6 +11,7 @@ from swh.model.model import Snapshot from swh.web.api.utils import enrich_snapshot from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import snapshot, new_snapshot @@ -19,10 +20,7 @@ def test_api_snapshot(api_client, archive_data, snapshot): url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_data = {**archive_data.snapshot_get(snapshot), "next_branch": None} expected_data = enrich_snapshot(expected_data, rv.wsgi_request) assert rv.data == expected_data @@ -53,9 +51,7 @@ "branches_count": branches_count, }, ) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) expected_data = archive_data.snapshot_get_branches( snapshot, branches_from, branches_count ) @@ -88,10 +84,7 @@ assert not rv.has_header("Link") url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == whole_snapshot @@ -112,15 +105,13 @@ url_args={"snapshot_id": snapshot}, query_params={"target_types": target_type}, ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=200) expected_data = archive_data.snapshot_get_branches( snapshot, target_types=target_type ) expected_data = enrich_snapshot(expected_data, rv.wsgi_request) - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data == expected_data @@ -128,12 +119,10 @@ unknown_snapshot_ = random_sha1() url = reverse("api-1-snapshot", url_args={"snapshot_id": "63ce369"}) - rv = api_client.get(url) - assert rv.status_code == 400, rv.data + check_api_get_responses(api_client, url, status_code=400) url = reverse("api-1-snapshot", url_args={"snapshot_id": unknown_snapshot_}) - rv = api_client.get(url) - assert rv.status_code == 404, rv.data + check_api_get_responses(api_client, url, status_code=404) @given(snapshot()) @@ -161,5 +150,4 @@ break archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) url = reverse("api-1-snapshot", url_args={"snapshot_id": snp_id}) - rv = api_client.get(url) - assert rv.status_code == 200, rv.data + check_api_get_responses(api_client, url, status_code=200) diff --git a/swh/web/tests/api/views/test_stat.py b/swh/web/tests/api/views/test_stat.py --- a/swh/web/tests/api/views/test_stat.py +++ b/swh/web/tests/api/views/test_stat.py @@ -7,6 +7,7 @@ from swh.web.common.exc import BadInputExc from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses def test_api_1_stat_counters_raise_error(api_client, mocker): @@ -16,10 +17,7 @@ ) url = reverse("api-1-stat-counters") - rv = api_client.get(url) - - assert rv.status_code == 400, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=400) assert rv.data == { "exception": "BadInputExc", "reason": "voluntary error to check the bad request middleware.", @@ -33,10 +31,7 @@ ) url = reverse("api-1-stat-counters") - rv = api_client.get(url) - - assert rv.status_code == 503, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=503) assert rv.data == { "exception": "StorageDBError", "reason": "An unexpected error occurred in the backend: " @@ -51,10 +46,7 @@ ) url = reverse("api-1-stat-counters") - rv = api_client.get(url) - - assert rv.status_code == 503, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=503) assert rv.data == { "exception": "StorageAPIError", "reason": "An unexpected error occurred in the api backend: " @@ -64,9 +56,5 @@ def test_api_1_stat_counters(api_client, archive_data): url = reverse("api-1-stat-counters") - - rv = api_client.get(url) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, url, status_code=200) assert rv.data == archive_data.stat_counters() diff --git a/swh/web/tests/api/views/test_vault.py b/swh/web/tests/api/views/test_vault.py --- a/swh/web/tests/api/views/test_vault.py +++ b/swh/web/tests/api/views/test_vault.py @@ -8,6 +8,7 @@ from swh.model import hashutil from swh.vault.exc import NotFoundExc from swh.web.common.utils import reverse +from swh.web.tests.api.views import check_api_get_responses, check_api_post_responses from swh.web.tests.strategies import ( directory, revision, @@ -41,14 +42,14 @@ mock_service.vault_cook.return_value = stub_cook mock_service.vault_fetch.return_value = stub_fetch + email = "test@test.mail" url = reverse( - f"api-1-vault-cook-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id} + f"api-1-vault-cook-{obj_type}", + url_args={f"{obj_type[:3]}_id": obj_id}, + query_params={"email": email}, ) - rv = api_client.post(url, {"email": "test@test.mail"}) - - assert rv.status_code == 200, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_post_responses(api_client, url, data=None, status_code=200) stub_cook["fetch_url"] = rv.wsgi_request.build_absolute_uri( stub_cook["fetch_url"] @@ -56,7 +57,7 @@ assert rv.data == stub_cook mock_service.vault_cook.assert_called_with( - obj_type, hashutil.hash_to_bytes(obj_id), "test@test.mail" + obj_type, hashutil.hash_to_bytes(obj_id), email ) rv = api_client.get(fetch_url) @@ -127,10 +128,8 @@ f"api-1-vault-cook-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, ) - rv = api_client.get(url) + rv = check_api_get_responses(api_client, url, status_code=404) - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" assert rv.data["exception"] == "NotFoundExc" assert ( rv.data["reason"] @@ -147,10 +146,7 @@ url = reverse( f"api-1-vault-cook-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id} ) - rv = api_client.post(url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_post_responses(api_client, url, data=None, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"{obj_name.title()} '{obj_id}' not found." @@ -162,10 +158,7 @@ f"api-1-vault-fetch-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, ) - rv = api_client.get(fetch_url) - - assert rv.status_code == 404, rv.data - assert rv["Content-Type"] == "application/json" + rv = check_api_get_responses(api_client, fetch_url, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert ( rv.data["reason"] == f"Cooked archive for {obj_name} '{obj_id}' not found."