|
| 1 | +import json |
| 2 | +import os |
| 3 | +from uuid import UUID |
| 4 | + |
| 5 | +import osw.model.entity as model |
| 6 | +from osw.express import OswExpress |
| 7 | + |
| 8 | +# Create/update the password file under examples/accounts.pwd.yaml |
| 9 | +pwd_file_path = os.path.join( |
| 10 | + os.path.dirname(os.path.abspath(__file__)), "accounts.pwd.yaml" |
| 11 | +) |
| 12 | +# pwd_file_path = "./accounts.pwd.yaml" |
| 13 | +# create OSW instance which auto-registers as a oold backend |
| 14 | +osw_obj = OswExpress( |
| 15 | + domain="wiki-dev.open-semantic-lab.org", cred_filepath=pwd_file_path |
| 16 | +) |
| 17 | + |
| 18 | +# create an instance of a keyword and store it |
| 19 | +k = model.Keyword( |
| 20 | + uuid=UUID("dcb75346-cf24-4793-bdb8-0c6fd68ebc2c"), |
| 21 | + label=[model.Label(text="Test Keyword", lang="en")], |
| 22 | + description=[model.Description(text="Test Description", lang="en")], |
| 23 | +) |
| 24 | +k.store_jsonld() |
| 25 | + |
| 26 | +# create an instance of an item linked to the keyword and store it |
| 27 | +# the keyword will be stored by its IRI ("Item:OSWdcb75346cf244793bdb80c6fd68ebc2c") |
| 28 | +i = model.Item( |
| 29 | + uuid=UUID("c65b130f-8aca-4d29-b1fd-6aef488759a6"), |
| 30 | + label=[model.Label(text="Test Item for OOLD Integration", lang="en")], |
| 31 | + keywords=[k], |
| 32 | +) |
| 33 | +assert i.label[0].text == "Test Item for OOLD Integration" |
| 34 | +jsonld_export = json.loads(i.json()) |
| 35 | +assert jsonld_export["keywords"][0] == "Item:OSWdcb75346cf244793bdb80c6fd68ebc2c" |
| 36 | +i.store_jsonld() |
| 37 | + |
| 38 | +# load the item again by its IRI |
| 39 | +i_ = model.Item[i.get_iri()] |
| 40 | +assert i_.uuid == i.uuid |
| 41 | + |
| 42 | +# accessing the keyword property auto-resolves the keyword iri via the oold backend |
| 43 | +assert i_.keywords[0].label[0].text == "Test Keyword" |
0 commit comments