diff --git a/datalad_registry/tests/test_blueprints/test_api/test_url_metadata.py b/datalad_registry/tests/test_blueprints/test_api/test_url_metadata.py index be9d9be2..f23c39e2 100644 --- a/datalad_registry/tests/test_blueprints/test_api/test_url_metadata.py +++ b/datalad_registry/tests/test_blueprints/test_api/test_url_metadata.py @@ -8,19 +8,31 @@ def populate_with_metadata(flask_app): from datalad_registry.models import RepoUrl, URLMetadata, db url = RepoUrl(url="https://example.com") - url_metadata = URLMetadata( - dataset_describe="abc", - dataset_version="cde", - extractor_name="complete-imagination", - extractor_version="0.1.0", - extraction_parameter={"a": 1, "b": 2}, - extracted_metadata={"brave": "new world", "apple": "1984"}, - url=url, - ) + + url_metadata_lst = [ + URLMetadata( + dataset_describe="abc", + dataset_version="cde", + extractor_name="complete-imagination", + extractor_version="0.1.0", + extraction_parameter={"a": 1, "b": 2}, + extracted_metadata={"brave": "new world", "apple": "1984"}, + url=url, + ), + URLMetadata( + dataset_describe="foo", + dataset_version="bar", + extractor_name="baz", + extractor_version="1.0.0", + extraction_parameter={"x": 10, "y": 20}, + extracted_metadata=["a", 1, {"year": 1984}], + url=url, + ), + ] with flask_app.app_context(): db.session.add(url) - db.session.add(url_metadata) + db.session.add_all(url_metadata_lst) db.session.commit() @@ -32,19 +44,38 @@ def test_not_found(self, flask_client, url_metadata_id): assert resp.status_code == 404 @pytest.mark.usefixtures("populate_with_metadata") - def test_found(self, flask_client): - resp = flask_client.get("/api/v2/url-metadata/1") + @pytest.mark.parametrize( + "url_metadata_id, expected_metadata", + [ + ( + 1, + URLMetadataModel( + dataset_describe="abc", + dataset_version="cde", + extractor_name="complete-imagination", + extractor_version="0.1.0", + extraction_parameter={"a": 1, "b": 2}, + extracted_metadata={"brave": "new world", "apple": "1984"}, + ), + ), + ( + 2, + URLMetadataModel( + dataset_describe="foo", + dataset_version="bar", + extractor_name="baz", + extractor_version="1.0.0", + extraction_parameter={"x": 10, "y": 20}, + extracted_metadata=["a", 1, {"year": 1984}], + ), + ), + ], + ) + def test_found(self, url_metadata_id, expected_metadata, flask_client): + resp = flask_client.get(f"/api/v2/url-metadata/{url_metadata_id}") assert resp.status_code == 200 returned_metadata = URLMetadataModel.parse_obj(resp.json) - expected_metadata = URLMetadataModel( - dataset_describe="abc", - dataset_version="cde", - extractor_name="complete-imagination", - extractor_version="0.1.0", - extraction_parameter={"a": 1, "b": 2}, - extracted_metadata={"brave": "new world", "apple": "1984"}, - ) assert returned_metadata == expected_metadata