-
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.
Problem: Latest version of archivist now allows specifying whether the asset is stored on the DLT or not. Solution: An enumerated StorageIntegrity type added to the assets.create() method to allow specifying either LEDGER or TENANT_STORAGE. If unspecified TENANT_STORAGE is used. Signed-off-by: Paul Hewlett <phewlett76@gmail.com>
- Loading branch information
Showing
8 changed files
with
167 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Archivist Storage integrity | ||
Enumerated type that allows user to select the storage option when | ||
creating an asset. | ||
""" | ||
|
||
from enum import Enum | ||
|
||
|
||
class StorageIntegrity(Enum): | ||
"""Enumerate storage integrity options""" | ||
|
||
#: Assets are stored on the DLT | ||
LEDGER = 1 | ||
#: Assets are not stored on the DLT | ||
TENANT_STORAGE = 2 |
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,10 @@ | ||
|
||
.. _storage_integrity: | ||
|
||
Storage Integrity | ||
----------------- | ||
|
||
|
||
.. automodule:: archivist.storage_integrity | ||
:members: | ||
|
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,72 @@ | ||
""" | ||
Test assets creation | ||
""" | ||
|
||
from copy import deepcopy | ||
from os import environ | ||
from unittest import TestCase | ||
|
||
from archivist.archivist import Archivist | ||
from archivist.storage_integrity import StorageIntegrity | ||
|
||
# pylint: disable=fixme | ||
# pylint: disable=missing-docstring | ||
# pylint: disable=unused-variable | ||
|
||
BEHAVIOURS = [ | ||
"RecordEvidence", | ||
"Attachments", | ||
] | ||
ATTRS = { | ||
"arc_firmware_version": "1.0", | ||
"arc_serial_number": "vtl-x4-07", | ||
"arc_description": "Traffic flow control light at A603 North East", | ||
"arc_home_location_identity": "locations/115340cf-f39e-4d43-a2ee-8017d672c6c6", | ||
"arc_display_type": "Traffic light with violation camera", | ||
"some_custom_attribute": "value", | ||
} | ||
|
||
|
||
class TestAssetCreate(TestCase): | ||
""" | ||
Test Archivist Asset Create method | ||
""" | ||
|
||
maxDiff = None | ||
|
||
def setUp(cls): | ||
with open(environ["TEST_AUTHTOKEN"]) as fd: | ||
auth = fd.read().strip() | ||
cls.arch = Archivist(environ["TEST_ARCHIVIST"], auth=auth, verify=False) | ||
cls.attrs = deepcopy(ATTRS) | ||
|
||
def test_asset_create_tenant_storage(self): | ||
""" | ||
Test asset creation on tenant storage | ||
""" | ||
asset = self.arch.assets.create( | ||
BEHAVIOURS, | ||
self.attrs, | ||
confirm=True, | ||
) | ||
self.assertEqual( | ||
asset["storage_integrity"], | ||
StorageIntegrity.TENANT_STORAGE.name, | ||
msg="Incorrect asset storage integrity", | ||
) | ||
|
||
def test_asset_create_ledger(self): | ||
""" | ||
Test asset creation on ledger | ||
""" | ||
asset = self.arch.assets.create( | ||
BEHAVIOURS, | ||
self.attrs, | ||
storage_integrity=StorageIntegrity.LEDGER, | ||
confirm=True, | ||
) | ||
self.assertEqual( | ||
asset["storage_integrity"], | ||
StorageIntegrity.LEDGER.name, | ||
msg="Incorrect asset storage integrity", | ||
) |
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,32 @@ | ||
""" | ||
Test storage integrity | ||
""" | ||
|
||
# pylint: disable=attribute-defined-outside-init | ||
# pylint: disable=missing-docstring | ||
# pylint: disable=too-few-public-methods | ||
|
||
from unittest import TestCase | ||
|
||
from archivist.storage_integrity import StorageIntegrity | ||
|
||
|
||
class TestStorageIntegrity(TestCase): | ||
""" | ||
Test storage integrity for archivist | ||
""" | ||
|
||
def test_storage_integrity(self): | ||
""" | ||
Test storage_integrity | ||
""" | ||
self.assertEqual(StorageIntegrity.LEDGER.value, 1, msg="Incorrect value") | ||
self.assertEqual(StorageIntegrity.LEDGER.name, "LEDGER", msg="Incorrect value") | ||
self.assertEqual( | ||
StorageIntegrity.TENANT_STORAGE.value, 2, msg="Incorrect value" | ||
) | ||
self.assertEqual( | ||
StorageIntegrity.TENANT_STORAGE.name, | ||
"TENANT_STORAGE", | ||
msg="Incorrect value", | ||
) |