Skip to content
Snippets Groups Projects
Commit c7548f93 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

api/metadata: Fix issues detected with hypothesis

Running metadata tests with multiple hyothesis examples uncovered those
issues in api-1-raw-extrinsic-metadata-swhid Web API view:

  - RawExtrinsincMetaData only targetting core SWHIds must be provided as test inputs.

  - link-next URL for pagination was invalid.

  - next_page_token must be encoded before providing it to urlsafe_b64encode.
parent e18d30e5
No related branches found
Tags v0.0.395
No related merge requests found
......@@ -145,14 +145,18 @@ def api_raw_extrinsic_metadata_swhid(request, target):
"results": results,
"headers": {},
}
if result_page.next_page_token is not None:
response["headers"]["link-next"] = reverse(
"api-1-raw-extrinsic-metadata",
"api-1-raw-extrinsic-metadata-swhid",
url_args={"target": target},
query_params=dict(
authority=authority_str,
after=after_str,
limit=limit_str,
page_token=base64.urlsafe_b64encode(result_page.next_page_token),
page_token=base64.urlsafe_b64encode(
result_page.next_page_token.encode()
),
),
request=request,
)
......
......@@ -5,14 +5,34 @@
import attr
from hypothesis import given, strategies
from hypothesis.strategies._internal.core import sampled_from
import pytest
from swh.model.hypothesis_strategies import raw_extrinsic_metadata
from swh.model.hypothesis_strategies import (
raw_extrinsic_metadata as raw_extrinsic_metadata_orig,
)
from swh.model.hypothesis_strategies import sha1_git
from swh.model.identifiers import ExtendedObjectType, ExtendedSWHID, ObjectType
from swh.web.common.utils import reverse
from swh.web.tests.api.views.utils import scroll_results
from swh.web.tests.utils import check_api_get_responses, check_http_get_response
# public Web API endpoint for raw extrinsic metadata does not support
# extended SWHIDs so we ensure only core ones will be used in test inputs.
@strategies.composite
def raw_extrinsic_metadata(draw):
remd = draw(raw_extrinsic_metadata_orig())
remd = attr.evolve(
remd,
target=ExtendedSWHID(
object_type=ExtendedObjectType(draw(sampled_from(ObjectType)).value),
object_id=draw(sha1_git()),
),
)
return attr.evolve(remd, id=remd.compute_hash())
@given(raw_extrinsic_metadata())
def test_api_raw_extrinsic_metadata(api_client, subtest, metadata):
# ensure archive_data fixture will be reset between each hypothesis
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment