Browse Source

add skip, make sure hostid is a uuid when reloaded..

main
John-Mark Gurney 2 years ago
parent
commit
bf0677d6a3
2 changed files with 52 additions and 9 deletions
  1. +7
    -0
      ui/fixtures/cmd.basic.json
  2. +45
    -9
      ui/medashare/cli.py

+ 7
- 0
ui/fixtures/cmd.basic.json View File

@@ -177,5 +177,12 @@
"cmd": [ "modify", "modified=foo", "test.txt" ], "cmd": [ "modify", "modified=foo", "test.txt" ],
"exit": 1, "exit": 1,
"stderr": "ERROR: tag needs to start with a \"+\" (add) or a \"-\" (remove).\n" "stderr": "ERROR: tag needs to start with a \"+\" (add) or a \"-\" (remove).\n"
},
{
"skip": 1,
"title": "dump is correct",
"cmd": [ "dump" ],
"exit": 0,
"stdout": "ERROR: tag needs to start with a \"+\" (add) or a \"-\" (remove).\n"
} }
] ]

+ 45
- 9
ui/medashare/cli.py View File

@@ -17,6 +17,7 @@ import datetime
import functools import functools
import hashlib import hashlib
import io import io
import itertools
import json import json
import os.path import os.path
import pathlib import pathlib
@@ -87,6 +88,10 @@ class MDBase(object):
#'parent_refs': lambda x: [ _makeuuid(y) for y in x ], #'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_properties = [ 'type', 'created_by_ref' ] # XXX - add lang?
_common_optional = set(('parent_refs', 'sig')) _common_optional = set(('parent_refs', 'sig'))
_common_names = set(_common_properties + list( _common_names = set(_common_properties + list(
@@ -113,7 +118,9 @@ class MDBase(object):
if x not in obj: if x not in obj:
raise ValueError('common property %s not present' % repr(x)) 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: if x in obj:
obj[x] = fun(obj[x]) obj[x] = fun(obj[x])


@@ -536,6 +543,10 @@ def _hashfile(fname):
class FileObject(MDBase): class FileObject(MDBase):
_type = 'file' _type = 'file'


_class_instance_properties = {
'hostid': _makeuuid,
}

@staticmethod @staticmethod
def make_id(fname): def make_id(fname):
'''Take a local file name, and make the id for it. Note that '''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.basetempdir = d
self.tempdir = d / 'subdir' 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) shutil.copytree(self.fixtures / 'testfiles', self.tempdir)


self.oldcwd = os.getcwd() 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) 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], '/') 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): def test_mdbase(self):
self.assertRaises(ValueError, MDBase, created_by_ref='') self.assertRaises(ValueError, MDBase, created_by_ref='')
@@ -1195,6 +1225,12 @@ class _TestCases(unittest.TestCase):
patches = [] patches = []


for cmd in cmds: for cmd in cmds:
try:
if cmd['skip']:
continue
except KeyError:
pass

try: try:
special = cmd['special'] special = cmd['special']
except KeyError: except KeyError:


Loading…
Cancel
Save