Skip to content

Commit 0c28b67

Browse files
committed
tests: refactor helper method
1 parent 04c98bc commit 0c28b67

2 files changed

Lines changed: 60 additions & 56 deletions

File tree

tests/common.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import functools
23
import json
34
import os
@@ -66,6 +67,60 @@ def make_dataset_dict(hint=""):
6667
return dataset_dict
6768

6869

70+
def make_dataset_dict_full_fake():
71+
org_id = f"{uuid.uuid4()}"
72+
ds_id = f"{uuid.uuid4()}"
73+
user_id = f"{uuid.uuid4()}"
74+
created = datetime.date.fromtimestamp(time.time() - 50).isoformat()
75+
modified = datetime.date.fromtimestamp(time.time()).isoformat()
76+
77+
return {"authors": "John Doe",
78+
"creator_user_id": f"{user_id}",
79+
"doi": "",
80+
"id": f"{ds_id}",
81+
"isopen": True,
82+
"license_id": "CC-BY-SA-4.0",
83+
"license_title": "Creative Commons Attribution Share-Alike 4.0",
84+
"license_url": "https://creativecommons.org/licenses/by-sa/4.0/",
85+
"metadata_created": created,
86+
"metadata_modified": modified,
87+
"name": "an-example-dataset",
88+
"notes": "A description",
89+
"num_resources": 1, "num_tags": 2,
90+
"organization": {
91+
"id": f"{org_id}",
92+
"name": "dcoraid-circle", "title": "",
93+
"type": "organization",
94+
"description": "", "image_url": "",
95+
"created": "2020-09-23T09:50:44.826360",
96+
"is_organization": True,
97+
"approval_status": "approved",
98+
"state": "active"},
99+
"owner_org": f"{org_id}",
100+
"private": True, "references": "",
101+
"state": "active", "title": "Dataset Title",
102+
"type": "dataset", "resources": [
103+
{"cache_last_updated": None, "cache_url": None,
104+
"created": created,
105+
"modified": modified,
106+
"dc:experiment:date": "2018-12-11",
107+
"dc:experiment:event count": 47, "dc:experiment:run index": 1,
108+
"url_type": "s3_upload"}],
109+
"tags": [{"display_name": "GFP",
110+
"id": "5b5e7553-49a0-49b4-b342-28b8384800c0",
111+
"name": "GFP",
112+
"state": "active",
113+
"vocabulary_id": None},
114+
{"display_name": "HL60",
115+
"id": "f4e18050-d2dc-4fd2-93d4-015666f0e066",
116+
"name": "HL60",
117+
"state": "active",
118+
"vocabulary_id": None}],
119+
"groups": [],
120+
"relationships_as_subject": [],
121+
"relationships_as_object": []}
122+
123+
69124
@functools.lru_cache()
70125
def make_dataset_for_download(seed=0, wait_for_resource_metadata=False):
71126
"""Set `seed` to get a new dataset (in case you need fresh resource ids)"""

tests/test_dbmodel_meta_cache_sqlite.py

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,14 @@
1-
import uuid
2-
31
import pytest
42
from dcoraid.dbmodel import meta_cache_sqlite
53

6-
7-
def make_example_ds_dict():
8-
org_id = f"{uuid.uuid4()}"
9-
ds_id = f"{uuid.uuid4()}"
10-
user_id = f"{uuid.uuid4()}"
11-
return {"authors": "John Doe",
12-
"creator_user_id": f"{user_id}",
13-
"doi": "",
14-
"id": f"{ds_id}",
15-
"isopen": True,
16-
"license_id": "CC-BY-SA-4.0",
17-
"license_title": "Creative Commons Attribution Share-Alike 4.0",
18-
"license_url": "https://creativecommons.org/licenses/by-sa/4.0/",
19-
"metadata_created": "2025-09-11T08:09:52.947634",
20-
"metadata_modified": "2025-09-11T08:10:13.882541",
21-
"name": "an-example-dataset",
22-
"notes": "A description",
23-
"num_resources": 1, "num_tags": 2,
24-
"organization": {
25-
"id": f"{org_id}",
26-
"name": "dcoraid-circle", "title": "",
27-
"type": "organization",
28-
"description": "", "image_url": "",
29-
"created": "2020-09-23T09:50:44.826360",
30-
"is_organization": True,
31-
"approval_status": "approved",
32-
"state": "active"},
33-
"owner_org": f"{org_id}",
34-
"private": True, "references": "",
35-
"state": "active", "title": "Dataset Title",
36-
"type": "dataset", "resources": [
37-
{"cache_last_updated": None, "cache_url": None,
38-
"created": "2025-09-18T08:10:06.286171",
39-
"dc:experiment:date": "2018-12-11",
40-
"dc:experiment:event count": 47, "dc:experiment:run index": 1,
41-
"url_type": "s3_upload"}],
42-
"tags": [{"display_name": "GFP",
43-
"id": "5b5e7553-49a0-49b4-b342-28b8384800c0",
44-
"name": "GFP",
45-
"state": "active",
46-
"vocabulary_id": None},
47-
{"display_name": "HL60",
48-
"id": "f4e18050-d2dc-4fd2-93d4-015666f0e066",
49-
"name": "HL60",
50-
"state": "active",
51-
"vocabulary_id": None}],
52-
"groups": [],
53-
"relationships_as_subject": [],
54-
"relationships_as_object": []}
4+
from .common import make_dataset_dict_full_fake
555

566

577
def test_create_write_read(tmp_path):
588
db_path = tmp_path / "database.db"
599

6010
with meta_cache_sqlite.SQLiteKeyJSONDatabase(db_path) as db:
61-
ds_dict = make_example_ds_dict()
11+
ds_dict = make_dataset_dict_full_fake()
6212
db[ds_dict["id"]] = ds_dict
6313
ds_dict2 = db[ds_dict["id"]]
6414
assert ds_dict == ds_dict2
@@ -69,16 +19,15 @@ def test_create_write_read(tmp_path):
6919
assert ds_dict == ds_dict3
7020

7121

72-
7322
def test_create_multiple_and_iter(tmp_path):
7423
db_path = tmp_path / "database.db"
7524

7625
with meta_cache_sqlite.SQLiteKeyJSONDatabase(db_path) as db:
77-
ds_dict = make_example_ds_dict()
26+
ds_dict = make_dataset_dict_full_fake()
7827
db[ds_dict["id"]] = ds_dict
7928

8029
for ii in range(10):
81-
dsi = make_example_ds_dict()
30+
dsi = make_dataset_dict_full_fake()
8231
db[dsi["id"]] = dsi
8332

8433
assert db[ds_dict["id"]] == ds_dict
@@ -94,7 +43,7 @@ def test_pop(tmp_path):
9443
db_path = tmp_path / "database.db"
9544

9645
with meta_cache_sqlite.SQLiteKeyJSONDatabase(db_path) as db:
97-
ds_dict = make_example_ds_dict()
46+
ds_dict = make_dataset_dict_full_fake()
9847
db[ds_dict["id"]] = ds_dict
9948
ds_dict2 = db[ds_dict["id"]]
10049
assert ds_dict == ds_dict2

0 commit comments

Comments
 (0)