Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_raw.py
- This file was added.
# Copyright (C) 2015-2019 The Software Heritage developers | ||||||||||||||||||||||||||
vlorentz: ditto | ||||||||||||||||||||||||||
# 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 | ||||||||||||||||||||||||||
import hashlib | ||||||||||||||||||||||||||
# from swh.model.git_objects import content_git_object | ||||||||||||||||||||||||||
from swh.web.common.utils import reverse | ||||||||||||||||||||||||||
# from swh.web.tests.data import random_content | ||||||||||||||||||||||||||
from swh.web.tests.utils import ( | ||||||||||||||||||||||||||
# check_api_get_responses, | ||||||||||||||||||||||||||
check_http_get_response, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
# def test_api_raw_content_ko_not_found(api_client): | ||||||||||||||||||||||||||
# unknown_content_ = random_content() | ||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||
# url = reverse( | ||||||||||||||||||||||||||
# "api-1-raw-object", url_args={"q": "sha1_git:%s" % unknown_content_["sha1_git"]} | ||||||||||||||||||||||||||
# ) | ||||||||||||||||||||||||||
# rv = check_api_get_responses(api_client, url, status_code=404) | ||||||||||||||||||||||||||
# assert rv.data == { | ||||||||||||||||||||||||||
# "exception": "NotFoundExc", | ||||||||||||||||||||||||||
Done Inline Actions
Could you make this test run for all SWHID types? vlorentz: Could you make this test run for all SWHID types? | ||||||||||||||||||||||||||
Done Inline ActionsI have made a fixture that does this. Ericson2314: I have made a fixture that does this. | ||||||||||||||||||||||||||
# "reason": "Content with sha1 checksum equals to %s not found!" | ||||||||||||||||||||||||||
# % unknown_content_["sha1_git"], | ||||||||||||||||||||||||||
# } | ||||||||||||||||||||||||||
# def test_api_raw_content(api_client, archive_data, content): | ||||||||||||||||||||||||||
# object_id = content["sha1_git"] | ||||||||||||||||||||||||||
# object_ty = "cnt" | ||||||||||||||||||||||||||
# url = reverse( | ||||||||||||||||||||||||||
# "api-1-raw-object", url_args={"swhid": f"swh:1:{object_ty}:{object_id}"} | ||||||||||||||||||||||||||
# ) | ||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||
# rv = check_http_get_response(api_client, url, status_code=200) | ||||||||||||||||||||||||||
# assert rv["Content-Type"] == "application/octet-stream" | ||||||||||||||||||||||||||
# assert ( | ||||||||||||||||||||||||||
# rv["Content-disposition"] | ||||||||||||||||||||||||||
# == f"attachment; filename=swh_1_{object_ty}_{object_id}_raw" | ||||||||||||||||||||||||||
# ) | ||||||||||||||||||||||||||
# expected_data = archive_data.content_get_data(object_id) | ||||||||||||||||||||||||||
# assert rv.content == content_git_object(expected_data) | ||||||||||||||||||||||||||
def test_api_raw_directory(api_client, archive_data, directory): | ||||||||||||||||||||||||||
object_id = directory | ||||||||||||||||||||||||||
object_ty = "dir" | ||||||||||||||||||||||||||
url = reverse( | ||||||||||||||||||||||||||
"api-1-raw-object", url_args={"swhid": f"swh:1:{object_ty}:{object_id}"} | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
rv = check_http_get_response(api_client, url, status_code=200) | ||||||||||||||||||||||||||
assert rv["Content-Type"] == "application/octet-stream" | ||||||||||||||||||||||||||
assert ( | ||||||||||||||||||||||||||
rv["Content-disposition"] | ||||||||||||||||||||||||||
== f"attachment; filename=swh_1_{object_ty}_{object_id}_raw" | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
sha1_git = hashlib.new("sha1", rv.content).digest() | ||||||||||||||||||||||||||
assert sha1_git == object_id |
ditto