Changeset View
Standalone View
swh/deposit/tests/api/test_deposit_metadata.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from django.urls import reverse | |||||
from rest_framework import status | |||||
from swh.deposit.config import COL_IRI | |||||
def test_deposit_metadata_invalid( | |||||
authenticated_client, deposit_collection, atom_dataset | |||||
): | |||||
"""Posting an invalid swhid reference is propagated to clients | |||||
""" | |||||
invalid_swhid = "swh:1:dir :31b5c8cc985d190b5a7ef4878128ebfdc2358f49" | |||||
xml_data = atom_dataset["entry-data-with-swhid"].format(swhid=invalid_swhid) | |||||
response = authenticated_client.post( | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | |||||
content_type="application/atom+xml;type=entry", | |||||
data=xml_data, | |||||
HTTP_SLUG="external-id", | |||||
) | |||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | |||||
assert b"Invalid SWHID reference" in response.content | |||||
vlorentz: that's exactly the same code as what is being tested | |||||
Done Inline Actionsyes, I know. If I inline the calls, the tests will get even longer that it is currently, not helping I could also use directly the helper function you proposed i extract above and ardumont: yes, I know.
But how to do better than that though?
If I inline the calls, the tests will get… | |||||
Done Inline ActionsWrite the expected data in pytest.mark.parametrize. vlorentz: Write the expected data in `pytest.mark.parametrize`. | |||||
Done Inline ActionsI understand your suggestion as write the expected RawExtrinsicMetadata for each input... so "Ouch", that will be quite difficult to read. I settled on updating the diff to reuse the utils function compute_metadata_context (which now has dedicated tests, so we can trust it more somehow). ardumont: I understand your suggestion as `write the expected RawExtrinsicMetadata for each input...`
so… | |||||
Done Inline Actions
Good! vlorentz: > I settled on updating the diff to reuse the utils function compute_metadata_context (which… | |||||
Not Done Inline Actionsis swhid_context a full SWHID or just the context? moranegg: is `swhid_context` a full SWHID or just the context? | |||||
Done Inline Actionsa full swhid with context here, well in all the diff, a:
ardumont: a full swhid with context
here, well in all the diff, a:
- swhid core is really just a core… |
that's exactly the same code as what is being tested