|
|
@@ -1,5 +1,6 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
|
|
import copy |
|
|
|
import datetime |
|
|
|
import hashlib |
|
|
|
import pasn1 |
|
|
@@ -22,13 +23,22 @@ class MDBase(object): |
|
|
|
'''This is a simple wrapper that turns a JSON object into a pythonesc |
|
|
|
object where attribute accesses work.''' |
|
|
|
|
|
|
|
_common_properties = [ 'uuid', 'type', 'modified', 'created_by_ref' ] |
|
|
|
_generated_properties = { |
|
|
|
'uuid': uuid.uuid4, |
|
|
|
'modified': datetime.datetime.utcnow |
|
|
|
} |
|
|
|
_common_properties = [ 'type', 'created_by_ref' ] |
|
|
|
|
|
|
|
def __init__(self, obj): |
|
|
|
obj = copy.deepcopy(obj) |
|
|
|
for x in self._common_properties: |
|
|
|
if x not in obj: |
|
|
|
raise ValueError('common property %s not present' % `x`) |
|
|
|
|
|
|
|
for x, fun in self._generated_properties.iteritems(): |
|
|
|
if x not in obj: |
|
|
|
obj[x] = fun() |
|
|
|
|
|
|
|
self._obj = obj |
|
|
|
|
|
|
|
@classmethod |
|
|
@@ -230,6 +240,15 @@ class _TestCases(unittest.TestCase): |
|
|
|
self.assertRaises(ValueError, MDBase.create_obj, { 'type': 'unknosldkfj' }) |
|
|
|
self.assertRaises(ValueError, MDBase.create_obj, { 'type': 'metadata' }) |
|
|
|
|
|
|
|
baseobj = { |
|
|
|
'type': 'metadata', |
|
|
|
'created_by_ref': '867c7563-79ae-435c-a265-9d8509cefac5', |
|
|
|
} |
|
|
|
origbase = copy.deepcopy(baseobj) |
|
|
|
md = MDBase.create_obj(baseobj) |
|
|
|
|
|
|
|
self.assertEqual(baseobj, origbase) |
|
|
|
|
|
|
|
def test_makehash(self): |
|
|
|
self.assertRaises(ValueError, ObjectStore.makehash, 'slkj') |
|
|
|
self.assertRaises(ValueError, ObjectStore.makehash, 'sha256:91751cee0a1ab8414400238a761411daa29643ab4b8243e9a91649e25be53ADA') |
|
|
|