|
|
@@ -17,6 +17,7 @@ import datetime |
|
|
|
import functools |
|
|
|
import hashlib |
|
|
|
import io |
|
|
|
import itertools |
|
|
|
import json |
|
|
|
import os.path |
|
|
|
import pathlib |
|
|
@@ -87,6 +88,10 @@ class MDBase(object): |
|
|
|
#'parent_refs': lambda x: [ _makeuuid(y) for y in x ], |
|
|
|
} |
|
|
|
|
|
|
|
# Override on a per subclass basis |
|
|
|
_class_instance_properties = { |
|
|
|
} |
|
|
|
|
|
|
|
_common_properties = [ 'type', 'created_by_ref' ] # XXX - add lang? |
|
|
|
_common_optional = set(('parent_refs', 'sig')) |
|
|
|
_common_names = set(_common_properties + list( |
|
|
@@ -113,7 +118,9 @@ class MDBase(object): |
|
|
|
if x not in obj: |
|
|
|
raise ValueError('common property %s not present' % repr(x)) |
|
|
|
|
|
|
|
for x, fun in self._instance_properties.items(): |
|
|
|
for x, fun in itertools.chain( |
|
|
|
self._instance_properties.items(), |
|
|
|
self._class_instance_properties.items()): |
|
|
|
if x in obj: |
|
|
|
obj[x] = fun(obj[x]) |
|
|
|
|
|
|
@@ -536,6 +543,10 @@ def _hashfile(fname): |
|
|
|
class FileObject(MDBase): |
|
|
|
_type = 'file' |
|
|
|
|
|
|
|
_class_instance_properties = { |
|
|
|
'hostid': _makeuuid, |
|
|
|
} |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def make_id(fname): |
|
|
|
'''Take a local file name, and make the id for it. Note that |
|
|
@@ -835,25 +846,44 @@ class _TestCases(unittest.TestCase): |
|
|
|
self.basetempdir = d |
|
|
|
self.tempdir = d / 'subdir' |
|
|
|
|
|
|
|
persona = Persona.load(os.path.join('fixtures', 'sample.persona.pasn1')) |
|
|
|
self.created_by_ref = persona.get_identity().uuid |
|
|
|
self.persona = Persona.load(os.path.join('fixtures', 'sample.persona.pasn1')) |
|
|
|
self.created_by_ref = self.persona.get_identity().uuid |
|
|
|
|
|
|
|
shutil.copytree(self.fixtures / 'testfiles', self.tempdir) |
|
|
|
|
|
|
|
self.oldcwd = os.getcwd() |
|
|
|
|
|
|
|
def test_fileobject_abs(self): |
|
|
|
def tearDown(self): |
|
|
|
shutil.rmtree(self.basetempdir) |
|
|
|
self.tempdir = None |
|
|
|
|
|
|
|
os.chdir(self.oldcwd) |
|
|
|
|
|
|
|
def test_fileobject(self): |
|
|
|
os.chdir(self.tempdir) |
|
|
|
|
|
|
|
a = FileObject.from_file('test.txt', self.created_by_ref) |
|
|
|
objst = ObjectStore(self.created_by_ref) |
|
|
|
|
|
|
|
a = self.persona.by_file('test.txt') |
|
|
|
|
|
|
|
# that the dir is absolute |
|
|
|
self.assertEqual(a.dir[0], '/') |
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
shutil.rmtree(self.basetempdir) |
|
|
|
self.tempdir = None |
|
|
|
# make sure the file's hostid is a UUID |
|
|
|
self.assertIsInstance(a.hostid, uuid.UUID) |
|
|
|
|
|
|
|
os.chdir(self.oldcwd) |
|
|
|
objst.loadobj(a) |
|
|
|
|
|
|
|
# write out the store |
|
|
|
objst.store('teststore.pasn1') |
|
|
|
|
|
|
|
# load it back in |
|
|
|
objstr = ObjectStore.load('teststore.pasn1') |
|
|
|
|
|
|
|
a = objstr.by_id(a['uuid']) |
|
|
|
|
|
|
|
# make sure the hostid is still a UUID |
|
|
|
self.assertIsInstance(a.hostid, uuid.UUID) |
|
|
|
|
|
|
|
def test_mdbase(self): |
|
|
|
self.assertRaises(ValueError, MDBase, created_by_ref='') |
|
|
@@ -1195,6 +1225,12 @@ class _TestCases(unittest.TestCase): |
|
|
|
patches = [] |
|
|
|
|
|
|
|
for cmd in cmds: |
|
|
|
try: |
|
|
|
if cmd['skip']: |
|
|
|
continue |
|
|
|
except KeyError: |
|
|
|
pass |
|
|
|
|
|
|
|
try: |
|
|
|
special = cmd['special'] |
|
|
|
except KeyError: |
|
|
|