From a892b7273a10aab33bb3853c10c79a298f06a029 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 2 Sep 2019 10:54:13 -0700 Subject: [PATCH] add overlay support --- ui/cli.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/ui/cli.py b/ui/cli.py index 5d44608..b2479af 100644 --- a/ui/cli.py +++ b/ui/cli.py @@ -45,6 +45,7 @@ class MDBase(object): 'modified': datetime.datetime.utcnow } _common_properties = [ 'type', 'created_by_ref' ] # XXX - add lang? + _common_optional = [ 'overlay_refs' ] _common_names = set(_common_properties + _generated_properties.keys()) def __init__(self, obj): @@ -64,7 +65,7 @@ class MDBase(object): @classmethod def create_obj(cls, obj): - '''Using obj as a base, create an instead of MDBase of the + '''Using obj as a base, create an instance of MDBase of the correct type. If the correct type is not found, a ValueError is raised.''' @@ -422,6 +423,41 @@ class _TestCases(unittest.TestCase): self.created_by_ref) self.assertEqual(oldid, files[0].id) + def test_mdbaseoverlay(self): + objst = ObjectStore(self.created_by_ref) + + # that a base object + bid = uuid.uuid4() + objst.loadobj({ + 'type': 'metadata', + 'uuid': bid, + 'modified': datetime.datetime(2019, 6, 10, 14, 3, 10), + 'created_by_ref': self.created_by_ref, + 'hashes': [ 'sha256:91751cee0a1ab8414400238a761411daa29643ab4b8243e9a91649e25be53ada' ], + 'someprop': [ 'somevalue' ], + 'lang': 'en', + }) + + # can have an overlay object + oid = uuid.uuid4() + dhash = 'sha256:a7c96262c21db9a06fd49e307d694fd95f624569f9b35bb3ffacd880440f9787' + objst.loadobj({ + 'type': 'metadata', + 'uuid': oid, + 'modified': datetime.datetime(2019, 6, 10, 18, 3, 10), + 'created_by_ref': self.created_by_ref, + 'hashes': [ dhash ], + 'overlay_refs': [ bid ], + 'lang': 'en', + }) + + # and that when you get it's properties + oobj = objst.by_id(oid) + oitems = oobj.items() + + # that is has the overlays property + print `oitems` + def test_objectstore(self): objst = ObjectStore.load(os.path.join('fixtures', 'sample.data.pasn1'))