|
| 1 | +import datetime |
1 | 2 | import sys |
2 | 3 | from pathlib import Path |
3 | 4 |
|
@@ -263,3 +264,63 @@ def test_characteristic_creation(wiki_domain, wiki_username, wiki_password): |
263 | 264 | # ) # namespace detection fails otherwise |
264 | 265 | # osw.delete_entity(my_characteristic) |
265 | 266 | # 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