Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
To cover cases in which the extracted metadata is not a dict
  • Loading branch information
candleindark committed Apr 29, 2024
1 parent 7d900cc commit 43013e7
Showing 1 changed file with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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

0 comments on commit 43013e7

Please sign in to comment.