-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Predefined settings for any endpoint
Problem: Creating assets usually requires some common settings and it is tedious to repeatedly specify them when manipulating entities. Solution: Add a fixtures property that allows the user to 'accumulate' predefined fixed settings. Signed-off-by: Paul Hewlett <[email protected]>
- Loading branch information
Showing
16 changed files
with
305 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Archivist dict deep merge | ||
""" | ||
|
||
from copy import deepcopy | ||
|
||
from flatten_dict import flatten, unflatten | ||
|
||
|
||
def _deepmerge(dct1: dict, dct2: dict) -> dict: | ||
"""Deep merge 2 dictionaries | ||
The settings from dct2 overwrite or add to dct1 | ||
""" | ||
if dct1 is None: | ||
return deepcopy(dct2) | ||
|
||
return unflatten({**flatten(dct1), **flatten(dct2)}) | ||
|
||
|
||
def _dotstring(dct: dict) -> str: | ||
"""Emit nested dictionary as dot delimited string""" | ||
return flatten(dct, reducer="dot").items() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.. _fixtures: | ||
|
||
Fixtures | ||
============================================= | ||
|
||
One can specify common attributes when creating/counting/querying assets, events | ||
and locations. | ||
|
||
.. code-block:: python | ||
from copy import deepcopy | ||
from archivist.archivist import Archivist | ||
from archivist.errors import ArchivistError | ||
from archivist.storage_integrity import StorageIntegrity | ||
# Oauth2 token that grants access | ||
with open(".auth_token", mode='r') as tokenfile: | ||
authtoken = tokenfile.read().strip() | ||
# Initialize connection to Archivist - for assets on DLT. | ||
ledger = Archivist( | ||
"https://app.rkvst.io", | ||
auth=authtoken, | ||
fixtures = { | ||
"assets": { | ||
"storage_integrity": StorageIntegrity.LEDGER.name, | ||
} | ||
}, | ||
) | ||
# lets define doors in our namespace that reside on the ledger... | ||
doors = deepcopy(ledger) | ||
doors.fixtures = { | ||
"assets": { | ||
"attributes": { | ||
"arc_display_type": "door", | ||
"arc_namespace": "project xyz", | ||
}, | ||
}, | ||
} | ||
# a red front door | ||
door = doors.assets.create( | ||
attrs={ | ||
"arc_display_name": "front door", | ||
"colour": "red", | ||
}, | ||
confirm=True, | ||
) | ||
# a green back door | ||
door = doors.assets.create( | ||
attrs={ | ||
"arc_display_name": "back door", | ||
"colour": "green", | ||
}, | ||
confirm=True, | ||
) | ||
# no need to specify arc_display_type... | ||
no_of_doors = doors.assets.count() | ||
for d in doors.assets.list(): | ||
print(d) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Jitsuin Archivist | |
|
||
features | ||
getting_started | ||
fixtures | ||
archivist | ||
assets | ||
events | ||
|
Oops, something went wrong.