diff --git a/ui/cli.py b/ui/cli.py index 18c8dc0..e7aafb6 100644 --- a/ui/cli.py +++ b/ui/cli.py @@ -10,6 +10,7 @@ from cryptography.hazmat.primitives.serialization import Encoding, \ import base58 import copy import datetime +import functools import hashlib import mock import os.path @@ -142,7 +143,10 @@ class MDBase(object): return '%s(%s)' % (self.__class__.__name__, `self._obj`) def __getattr__(self, k): - return self._obj[k] + try: + return self._obj[k] + except KeyError: + raise AttributeError(k) def __setattr__(self, k, v): if k[0] == '_': # direct attribute @@ -227,6 +231,11 @@ class Persona(object): self._created_by_ref = self._identity.uuid + def MetaData(self, *args, **kwargs): + kwargs['created_by_ref'] = self.uuid + + return self.sign(MetaData(*args, **kwargs)) + @property def uuid(self): '''Return the UUID of the identity represented.''' @@ -676,6 +685,9 @@ class _TestCases(unittest.TestCase): # gets set directly, and is not a list self.assertEqual(md3.sig, fvalue) + # that invalid attribute access raises correct exception + self.assertRaises(AttributeError, getattr, md, 'somerandombogusattribute') + def test_mdbase_encode_decode(self): # that an object baseobj = { @@ -864,6 +876,24 @@ class _TestCases(unittest.TestCase): # and the old persona can verify it. self.assertTrue(vpersona.verify(nvtestobj)) + def test_persona_metadata(self): + # that a persona + persona = Persona() + persona.generate_key() + + # can create a metadata object + hashobj = ['asdlfkj'] + mdobj = persona.MetaData(hashes=hashobj) + + # that the object has the correct created_by_ref + self.assertEqual(mdobj.created_by_ref, persona.uuid) + + # and has the provided hashes + self.assertEqual(mdobj.hashes, hashobj) + + # and that it can be verified + persona.verify(mdobj) + def test_objectstore(self): objst = ObjectStore.load(os.path.join('fixtures', 'sample.data.pasn1'))