Skip to content

Commit 670d6cb

Browse files
committed
test: add test for metaclass based class creation
1 parent 72c1ef7 commit 670d6cb

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/integration/store_and_load_test.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import sys
23
from pathlib import Path
34

@@ -263,3 +264,63 @@ def test_characteristic_creation(wiki_domain, wiki_username, wiki_password):
263264
# ) # namespace detection fails otherwise
264265
# osw.delete_entity(my_characteristic)
265266
# pp.delete()
267+
268+
269+
def test_metaclass(wiki_domain, wiki_username, wiki_password):
270+
cm = CredentialManager()
271+
cm.add_credential(
272+
CredentialManager.UserPwdCredential(
273+
iri=wiki_domain, username=wiki_username, password=wiki_password
274+
)
275+
)
276+
wtsite = WtSite(WtSite.WtSiteConfig(iri=wiki_domain, cred_mngr=cm))
277+
osw = OSW(site=wtsite)
278+
279+
osw.fetch_schema(
280+
OSW.FetchSchemaParam(
281+
schema_title=[
282+
"Category:OSWc11438cd6c814ed1a5a253555ee351b4", # ProcessType
283+
],
284+
mode="replace",
285+
)
286+
)
287+
288+
# Create a characteristic as instance of ProcessType
289+
my_process = model.ProcessType(
290+
uuid="1a78f9b2-ae5f-4769-85ab-78070795939b",
291+
name="TestProcess",
292+
subclass_of=["Category:OSWe5aa96bffb1c4d95be7fbd46142ad203"], # Process
293+
label=[model.Label(text="Test Process")],
294+
description=[
295+
model.Description(text="A test process for the osw python package")
296+
],
297+
status_default="Item:OSWa2b4567ad4874ea1b9adfed19a3d06d1", # InWork
298+
start_date_time_default=datetime.datetime.fromisoformat("2024-01-01T00:00:00"),
299+
)
300+
301+
# store it as instance, which generates the schema
302+
# note: namespace and meta_category should be detected automatically in the future
303+
osw.store_entity(
304+
OSW.StoreEntityParam(
305+
entities=[my_process],
306+
namespace="Category",
307+
# meta_category_title=model.ProcessType.get_iri(),
308+
meta_category_title="Category:OSWc11438cd6c814ed1a5a253555ee351b4",
309+
overwrite=OverwriteOptions.true,
310+
)
311+
)
312+
313+
# load the characteristic as category
314+
osw.fetch_schema(
315+
OSW.FetchSchemaParam(
316+
schema_title=["Category:" + my_process.get_osw_id()],
317+
mode="append",
318+
)
319+
)
320+
321+
# create an instance of the characteristic
322+
t = model.TestProcess(label=[model.Label(text="Test Instance")])
323+
assert t.status == "Item:OSWa2b4567ad4874ea1b9adfed19a3d06d1"
324+
# not working yet - would require
325+
# start_date_time: Optional[datetime] = datetime.fromisoformat("2024-01-01T00:00:00")
326+
# assert t.start_date_time == datetime.datetime.fromisoformat("2024-01-01T00:00:00")

0 commit comments

Comments
 (0)