Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_graph.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import hashlib | import hashlib | ||||
import json | import json | ||||
import textwrap | import textwrap | ||||
from hypothesis import given | from hypothesis import given | ||||
from django.http.response import StreamingHttpResponse | from django.http.response import StreamingHttpResponse | ||||
from swh.model.identifiers import ORIGIN, SNAPSHOT, swhid | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.identifiers import ExtendedObjectType, ExtendedSWHID | |||||
from swh.web.api.views.graph import API_GRAPH_PERM | from swh.web.api.views.graph import API_GRAPH_PERM | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.config import SWH_WEB_INTERNAL_SERVER_NAME, get_config | from swh.web.config import SWH_WEB_INTERNAL_SERVER_NAME, get_config | ||||
from swh.web.tests.auth.keycloak_mock import mock_keycloak | from swh.web.tests.auth.keycloak_mock import mock_keycloak | ||||
from swh.web.tests.auth.sample_data import oidc_profile | from swh.web.tests.auth.sample_data import oidc_profile | ||||
from swh.web.tests.strategies import origin | from swh.web.tests.strategies import origin | ||||
from swh.web.tests.utils import check_http_get_response | from swh.web.tests.utils import check_http_get_response | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | |||||
@given(origin()) | @given(origin()) | ||||
def test_graph_response_resolve_origins( | def test_graph_response_resolve_origins( | ||||
archive_data, api_client, mocker, requests_mock, origin | archive_data, api_client, mocker, requests_mock, origin | ||||
): | ): | ||||
hasher = hashlib.sha1() | hasher = hashlib.sha1() | ||||
hasher.update(origin["url"].encode()) | hasher.update(origin["url"].encode()) | ||||
origin_sha1 = hasher.hexdigest() | origin_sha1 = hasher.digest() | ||||
origin_swhid = str(swhid(ORIGIN, origin_sha1)) | origin_swhid = str( | ||||
ExtendedSWHID(object_type=ExtendedObjectType.ORIGIN, object_id=origin_sha1) | |||||
) | |||||
snapshot = archive_data.snapshot_get_latest(origin["url"])["id"] | snapshot = archive_data.snapshot_get_latest(origin["url"])["id"] | ||||
snapshot_swhid = str(swhid(SNAPSHOT, snapshot)) | snapshot_swhid = str( | ||||
ardumont: why is it an extended swhid here? | |||||
Done Inline Actionsswh-graph uses swh:1:ori: to represent origins, and only ExtendedSWHID allows swh:1:ori: vlorentz: swh-graph uses `swh:1:ori:` to represent origins, and only ExtendedSWHID allows `swh:1:ori:` | |||||
ExtendedSWHID( | |||||
object_type=ExtendedObjectType.SNAPSHOT, object_id=hash_to_bytes(snapshot) | |||||
) | |||||
) | |||||
_authenticate_graph_user(api_client, mocker) | _authenticate_graph_user(api_client, mocker) | ||||
for graph_query, response_text, content_type in ( | for graph_query, response_text, content_type in ( | ||||
( | ( | ||||
f"visit/nodes/{snapshot_swhid}", | f"visit/nodes/{snapshot_swhid}", | ||||
f"{snapshot_swhid}\n{origin_swhid}\n", | f"{snapshot_swhid}\n{origin_swhid}\n", | ||||
"text/plain", | "text/plain", | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
why is it an extended swhid here?