Skip to content

Commit 5dfecbe

Browse files
committed
metadata api integration test
1 parent 4fb8605 commit 5dfecbe

3 files changed

Lines changed: 164 additions & 0 deletions

File tree

requirements.testing.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
celery~=5.4.0
2+
minio~=7.2.10
3+
requests~=2.32.3
4+
Flask~=3.0.3
5+
Werkzeug~=3.0.4
6+
redis~=5.2.0
7+
python-dotenv~=1.0.1
8+
apiflask~=2.4.0
9+
roc-validator~=0.6.5
10+
pytest~=8.4.1

tests/data/ro-crate-metadata.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"@context": "https://w3id.org/ro/crate/1.1/context",
3+
"@graph": [
4+
{
5+
"@id": "./",
6+
"@type": "Dataset",
7+
"name": "example dataset",
8+
"description": "crate that should conform with validator requirements",
9+
"datePublished": "2024-03-17T15:55:54+00:00",
10+
"license": {
11+
"@id": "http://spdx.org/licenses/MIT"
12+
},
13+
"hasPart": [
14+
{
15+
"@id": "paper.pdf"
16+
},
17+
{
18+
"@id": "results.csv"
19+
},
20+
{
21+
"@id": "images/figure.svg"
22+
},
23+
{
24+
"@id": "logs/"
25+
}
26+
]
27+
},
28+
{
29+
"@id": "ro-crate-metadata.json",
30+
"@type": "CreativeWork",
31+
"about": {
32+
"@id": "./"
33+
},
34+
"conformsTo": {
35+
"@id": "https://w3id.org/ro/crate/1.1"
36+
}
37+
},
38+
{
39+
"@id": "paper.pdf",
40+
"@type": "File",
41+
"author": [
42+
{
43+
"@id": "https://orcid.org/0000-0000-0000-0000"
44+
},
45+
{
46+
"@id": "https://orcid.org/0000-0000-0000-0001"
47+
}
48+
],
49+
"encodingFormat": "application/pdf",
50+
"name": "manuscript"
51+
},
52+
{
53+
"@id": "results.csv",
54+
"@type": "File",
55+
"author": {
56+
"@id": "https://orcid.org/0000-0000-0000-0000"
57+
},
58+
"encodingFormat": "text/csv",
59+
"name": "experimental data"
60+
},
61+
{
62+
"@id": "images/figure.svg",
63+
"@type": "File",
64+
"author": {
65+
"@id": "https://orcid.org/0000-0000-0000-0001"
66+
},
67+
"encodingFormat": "image/svg+xml",
68+
"name": "bar chart"
69+
},
70+
{
71+
"@id": "logs/",
72+
"@type": "Dataset"
73+
},
74+
{
75+
"@id": "https://orcid.org/0000-0000-0000-0000",
76+
"@type": "Person",
77+
"affiliation": "University of Flatland",
78+
"name": "Alice Doe"
79+
},
80+
{
81+
"@id": "https://orcid.org/0000-0000-0000-0001",
82+
"@type": "Person",
83+
"affiliation": "University of Flatland",
84+
"name": "Bob Doe"
85+
},
86+
{
87+
"@id": "#hdr2024",
88+
"@type": "Project Meeting",
89+
"endDate": "2024-04-16",
90+
"location": "Swansea, UK",
91+
"name": "HDR-UK 2024",
92+
"startDate": "2024-04-15"
93+
},
94+
{
95+
"@id": "https://spdx.org/licenses/MIT",
96+
"@type": "CreativeWork",
97+
"name": "MIT Licence",
98+
"identifier": "MIT"
99+
}
100+
]
101+
}

tests/metadata_integration.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pytest
2+
import subprocess
3+
import time
4+
import requests
5+
import json
6+
import os
7+
8+
9+
@pytest.fixture(scope="session", autouse=True)
10+
def docker_compose():
11+
"""Start Docker Compose before tests, shut down after."""
12+
print("Starting Docker Compose...")
13+
subprocess.run(
14+
["docker", "compose", "-f", "docker-compose-develop.yml", "up", "-d"],
15+
check=True
16+
)
17+
time.sleep(10) # Wait for services to start — adjust as needed
18+
19+
yield # Run the tests
20+
21+
print("Stopping Docker Compose...")
22+
subprocess.run(["docker", "compose", "down"], check=True)
23+
24+
25+
26+
def test_validate_metadata():
27+
url = "http://localhost:5001/ro_crates/validate_metadata"
28+
headers = {
29+
"accept": "application/json",
30+
"Content-Type": "application/json"
31+
}
32+
33+
# Load the JSON from file
34+
filepath = os.path.join("tests/data", "ro-crate-metadata.json")
35+
with open(filepath, "r", encoding="utf-8") as f:
36+
crate_json_data = json.load(f)
37+
38+
# The API expects the JSON to be passed as a string
39+
payload = {
40+
"crate_json": json.dumps(crate_json_data)
41+
}
42+
43+
response = requests.post(url, json=payload, headers=headers)
44+
45+
response_result = json.loads(response.json()['result'])
46+
47+
# Print response for debugging
48+
print("Status Code:", response.status_code)
49+
print("Response JSON:", response_result)
50+
51+
# Assertions — update based on expected API behavior
52+
assert response.status_code == 200
53+
assert response_result['passed'] == True

0 commit comments

Comments
 (0)