Exemplo n.º 1
0
 def test08_write_inventory_and_sidecar(self):
     """Test write_object_and_sidecar."""
     tmpfs = fs.tempfs.TempFS(identifier='test_write_inventory_and_sidecar')
     oo = Object(obj_fs=tmpfs)
     oo.write_inventory_and_sidecar({'abc': 'def'})
     self.assertEqual(set(tmpfs.listdir('')),
                      set(['inventory.json', 'inventory.json.sha512']))
     with tmpfs.open('inventory.json') as fh:
         j = json.load(fh)
     self.assertEqual(j, {'abc': 'def'})
     digest = tmpfs.readtext('inventory.json.sha512')
     self.assertRegex(digest, r'''[0-9a-f]{128} inventory.json\n''')
     # and now making directory
     oo = Object(obj_fs=tmpfs)
     invdir = 'xxx'
     oo.write_inventory_and_sidecar({'gh': 'ik'}, invdir)
     self.assertEqual(set(tmpfs.listdir(invdir)),
                      set(['inventory.json', 'inventory.json.sha512']))
     with tmpfs.open(fs.path.join(invdir, 'inventory.json')) as fh:
         j = json.load(fh)
     self.assertEqual(j, {'gh': 'ik'})
Exemplo n.º 2
0
 def test08_write_inventory_and_sidecar(self):
     """Test write_object_and_sidecar."""
     tempdir = tempfile.mkdtemp(prefix='test_write_inventory_and_sidecar')
     oo = Object()
     oo.write_inventory_and_sidecar(tempdir, {'abc': 'def'})
     self.assertEqual(set(os.listdir(tempdir)),
                      set(['inventory.json', 'inventory.json.sha512']))
     with open(os.path.join(tempdir, 'inventory.json')) as fh:
         j = json.load(fh)
     self.assertEqual(j, {'abc': 'def'})
     with open(os.path.join(tempdir, 'inventory.json.sha512')) as fh:
         digest = fh.read()
     self.assertRegex(digest, r'''[0-9a-f]{128} inventory.json\n''')
     # and now makind directory
     oo = Object()
     invdir = os.path.join(tempdir, 'xxx')
     oo.write_inventory_and_sidecar(invdir, {'gh': 'ik'})
     self.assertEqual(set(os.listdir(invdir)),
                      set(['inventory.json', 'inventory.json.sha512']))
     with open(os.path.join(invdir, 'inventory.json')) as fh:
         j = json.load(fh)
     self.assertEqual(j, {'gh': 'ik'})