api_client = <rest_framework.test.APIClient object at 0x7f45dde2f358>
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f45dde2f400>
directory = 'cd19126d815470b28919d64b2a8e6a3e37f900dd'
revision = '1cf33c85d52fc849216a838a7b2a087486ee9bef'
def test_api_vault_cook(api_client, mocker, directory, revision):
mock_archive = mocker.patch("swh.web.api.views.vault.archive")
for bundle_type, swhid, content_type, in (
("flat", f"swh:1:dir:{directory}", "application/gzip"),
("gitfast", f"swh:1:rev:{revision}", "application/gzip"),
("git_bare", f"swh:1:rev:{revision}", "application/x-tar"),
):
swhid = CoreSWHID.from_string(swhid)
fetch_url = reverse(
f"api-1-vault-fetch-{bundle_type.replace('_', '-')}",
url_args={"swhid": str(swhid)},
)
stub_cook = {
"type": bundle_type,
"progress_msg": None,
"task_id": 1,
"task_status": "done",
"swhid": swhid,
}
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-{bundle_type.replace('_', '-')}",
url_args={"swhid": str(swhid)},
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),
}
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:67:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
client = <rest_framework.test.APIClient object at 0x7f45dde2f358>
url = '/api/1/vault/flat/swh:1:dir:cd19126d815470b28919d64b2a8e6a3e37f900dd/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