@@ -108,6 +108,9 @@ _asn1coder = pasn1.ASN1DictCoder(coerce=_trytodict)
class ObjectStore(object):
class ObjectStore(object):
'''A container to store for the various Metadata objects.'''
'''A container to store for the various Metadata objects.'''
# The _uuids property contains both the UUIDv4 for objects, and
# looking up the UUIDv5 for FileObjects.
def __init__(self, created_by_ref):
def __init__(self, created_by_ref):
self._created_by_ref = created_by_ref
self._created_by_ref = created_by_ref
self._uuids = {}
self._uuids = {}
@@ -373,7 +376,7 @@ class _TestCases(unittest.TestCase):
r = byid
r = byid
self.assertEqual(r.uuid, '3e466e06-45de-4ecc-84ba-2d2a3d970e96')
self.assertEqual(r.uuid, '3e466e06-45de-4ecc-84ba-2d2a3d970e96')
self.assertEqual(r['dc:au th or'], 'John-Mark Gurney')
self.assertEqual(r['dc:cre ator'], 'John-Mark Gurney')
fname = 'testfile.pasn1'
fname = 'testfile.pasn1'
objst.store(fname)
objst.store(fname)
@@ -392,9 +395,15 @@ class _TestCases(unittest.TestCase):
testfname = os.path.join(self.tempdir, 'test.txt')
testfname = os.path.join(self.tempdir, 'test.txt')
self.assertEqual(objst.by_file(testfname), [ byid ])
self.assertEqual(objst.by_file(testfname), [ byid ])
self.assertEqual(objst.by_file(testfname), [ byid ])
self.assertRaises(KeyError, objst.by_file, '/dev/null')
# XXX make sure that object store contains fileobject
# XXX make sure that object store contains fileobject
# Tests to add:
# Non-duplicates when same metadata is located by multiple hashes.
def test_main(self):
def test_main(self):
# Test the main runner, this is only testing things that are
# Test the main runner, this is only testing things that are
# specific to running the program, like where the store is
# specific to running the program, like where the store is
@@ -417,7 +426,7 @@ class _TestCases(unittest.TestCase):
[ 'progname', '-l', testfname ])) as (stdout, argv):
[ 'progname', '-l', testfname ])) as (stdout, argv):
main()
main()
self.assertEqual(stdout.getvalue(),
self.assertEqual(stdout.getvalue(),
'dc:au th or:\tJohn-Mark Gurney\nhashes:\tsha256:91751cee0a1ab8414400238a761411daa29643ab4b8243e9a91649e25be53ada\nhashes:\tsha512:7d5768d47b6bc27dc4fa7e9732cfa2de506ca262a2749cb108923e5dddffde842bbfee6cb8d692fb43aca0f12946c521cce2633887914ca1f96898478d10ad3f\nlang:\ten\n')
'dc:cre ator:\tJohn-Mark Gurney\nhashes:\tsha256:91751cee0a1ab8414400238a761411daa29643ab4b8243e9a91649e25be53ada\nhashes:\tsha512:7d5768d47b6bc27dc4fa7e9732cfa2de506ca262a2749cb108923e5dddffde842bbfee6cb8d692fb43aca0f12946c521cce2633887914ca1f96898478d10ad3f\nlang:\ten\n')
eu.assert_called_with('~/.medashare_store.pasn1')
eu.assert_called_with('~/.medashare_store.pasn1')
if False: # pragma: no cover
if False: # pragma: no cover
@@ -425,8 +434,3 @@ class _TestCases(unittest.TestCase):
with mock.patch('sys.stdout', StringIO.StringIO()) as ssw:
with mock.patch('sys.stdout', StringIO.StringIO()) as ssw:
print 'foobar'
print 'foobar'
self.assertEqual(ssw.getvalue(), 'foobar\n')
self.assertEqual(ssw.getvalue(), 'foobar\n')
# XXX - how to do created_by for object store?
# store it in the loaded object?
# if so, have to restructure how we handle loading