api_client = <rest_framework.test.APIClient object at 0x7f45ddecb518>
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f45df2fcef0>
directory = '04046f0d4da224462a9eff42b42dbf91d56c99cc'
revision = 'd7c52cd81010768c4a51b6ad468fc95cb84e2858'
def test_api_vault_cook_legacy(api_client, mocker, directory, revision):
mock_archive = mocker.patch("swh.web.api.views.vault.archive")
for obj_type, bundle_type, response_obj_type, obj_id in (
("directory", "flat", "directory", directory),
("revision_gitfast", "gitfast", "revision", revision),
):
swhid = CoreSWHID.from_string(f"swh:1:{obj_type[:3]}:{obj_id}")
fetch_url = reverse(
f"api-1-vault-fetch-{bundle_type}",
url_args={"swhid": str(swhid)},
)
stub_cook = {
"type": obj_type,
"progress_msg": None,
"task_id": 1,
"task_status": "done",
"swhid": swhid,
"obj_type": response_obj_type,
"obj_id": obj_id,
}
stub_fetch = b"content"
mock_archive.vault_cook.return_value = stub_cook
mock_archive.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},
query_params={"email": email},
)
rv = check_api_post_responses(api_client, url, data=None, status_code=200)
assert rv.data == {
"fetch_url": rv.wsgi_request.build_absolute_uri(fetch_url),
"progress_message": None,
"id": 1,
"status": "done",
"swhid": str(swhid),
"obj_type": response_obj_type,
"obj_id": obj_id,
}
mock_archive.vault_cook.assert_called_with(bundle_type, swhid, email)
> rv = check_http_get_response(api_client, fetch_url, status_code=200)
.tox/py3/lib/python3.7/site-packages/swh/web/tests/api/views/test_vault.py:231:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
client = <rest_framework.test.APIClient object at 0x7f45ddecb518>
url = '/api/1/vault/flat/swh:1:dir:04046f0d4da224462a9eff42b42dbf91d56c99cc/raw/'
status_code = 200, content_type = '*/*', 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=200, "application/gzip">, 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