Skip to content

Commit 71c39be

Browse files
committed
Changes to unit tests to reflect the stricter requirements on @id values needed to support openMINDS Collections
(which may have local ids starting with `_:`)
1 parent 6965c23 commit 71c39be

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

test/test_client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ def test_create_new_instance(kg_client, mocker):
211211
"create_new_with_id",
212212
lambda **kw: MockKGResponse({**kw["payload"], **{"@id": kw["instance_id"]}}),
213213
)
214-
response = kg_client.create_new_instance({"a": 1, "b": 2}, instance_id="some-id", space="not-a-real-space")
215-
assert response == {"@id": "some-id", "a": 1, "b": 2}
214+
fake_id = "00000000-0000-0000-0000-000000000000"
215+
response = kg_client.create_new_instance({"a": 1, "b": 2}, instance_id=fake_id, space="not-a-real-space")
216+
assert response == {"@id": fake_id, "a": 1, "b": 2}
216217

217218

218219
@skip_if_no_connection
@@ -222,12 +223,14 @@ def test_replace_instance(kg_client, mocker):
222223
"contribute_to_full_replacement",
223224
lambda **kw: MockKGResponse({**kw["payload"], **{"@id": kw["instance_id"]}}),
224225
)
225-
response = kg_client.replace_instance("some-id", {"a": 1, "b": 2})
226-
assert response == {"@id": "some-id", "a": 1, "b": 2}
226+
fake_id = "00000000-0000-0000-0000-000000000000"
227+
response = kg_client.replace_instance(fake_id, {"a": 1, "b": 2})
228+
assert response == {"@id": fake_id, "a": 1, "b": 2}
227229

228230

229231
@skip_if_no_connection
230232
def test_delete_instance(kg_client, mocker):
231233
mocker.patch.object(kg_client._kg_client.instances, "delete")
232-
response = kg_client.delete_instance("some-id")
233-
kg_client._kg_client.instances.delete.assert_called_once_with("some-id")
234+
fake_id = "00000000-0000-0000-0000-000000000000"
235+
response = kg_client.delete_instance(fake_id)
236+
kg_client._kg_client.instances.delete.assert_called_once_with(fake_id)

test/test_openminds_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def test_save_new_mock(mock_client):
596596
def test_save_existing_mock(mock_client):
597597
timestamp = datetime.now()
598598
new_model = omcore.Model(
599-
id="0000",
599+
id="http://example.org/00000000-0000-0000-0000-000000000000",
600600
name=f"Dummy new model created for testing at {timestamp}",
601601
alias=f"DummyModel-{timestamp.isoformat()}",
602602
abstraction_level=omterms.ModelAbstractionLevel.by_name("protein structure", mock_client),
@@ -627,7 +627,7 @@ def test_save_existing_mock(mock_client):
627627
def test_save_existing_mock_no_updates_allowed(mock_client):
628628
timestamp = datetime.now()
629629
new_model = omcore.Model(
630-
id="0000",
630+
id="http://example.org/00000000-0000-0000-0000-000000000000",
631631
name=f"Dummy new model created for testing at {timestamp}",
632632
alias=f"DummyModel-{timestamp.isoformat()}",
633633
abstraction_level=omterms.ModelAbstractionLevel.by_name("protein structure", mock_client),
@@ -659,7 +659,7 @@ def test_save_existing_mock_no_updates_allowed(mock_client):
659659
def test_save_replace_existing_mock(mock_client):
660660
timestamp = datetime.now()
661661
new_model = omcore.Model(
662-
id="0000",
662+
id="http://example.org/00000000-0000-0000-0000-000000000000",
663663
name=f"Dummy new model created for testing at {timestamp}",
664664
alias=f"DummyModel-{timestamp.isoformat()}",
665665
abstraction_level=omterms.ModelAbstractionLevel.by_name("protein structure", mock_client),

test/test_utility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_sha1sum():
7171

7272
def test_normalize_data():
7373
data = {
74-
"@id": "0000",
74+
"@id": "http://example.org/00000000-0000-0000-0000-000000000000",
7575
"@type": "https://openminds.ebrains.eu/core/Person",
7676
"affiliation": {
7777
"@type": "https://openminds.ebrains.eu/core/Affiliation",
@@ -85,7 +85,7 @@ def test_normalize_data():
8585
}
8686
context = {"@vocab": "https://openminds.ebrains.eu/vocab/"}
8787
expected = {
88-
"@id": "0000",
88+
"@id": "http://example.org/00000000-0000-0000-0000-000000000000",
8989
"@type": "https://openminds.ebrains.eu/core/Person",
9090
"https://openminds.ebrains.eu/vocab/affiliation": {
9191
"@type": "https://openminds.ebrains.eu/core/Affiliation",

test/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ def instance_from_full_uri(
7474
release_status: str = "released",
7575
require_full_data: bool = True,
7676
):
77-
if uri == "0000":
78-
return {"@id": "0000", "@type": ["https://openminds.om-i.org/types/Model"]}
77+
mock_id = "http://example.org/00000000-0000-0000-0000-000000000000"
78+
if uri == mock_id:
79+
return {"@id": mock_id, "@type": ["https://openminds.om-i.org/types/Model"]}
7980
else:
8081
raise NotImplementedError
8182

0 commit comments

Comments
 (0)