Exemplo n.º 1
0
 def test_can_load_object(self):
     content = b'spam'
     sha256sum = hashlib.sha256(content).hexdigest()
     md5 = hashlib.md5(content).hexdigest()
     self.options['filename'] = self.create_file(content)
     obj = Object(self.options)
     self.assertIsNone(obj.md5)
     self.assertIsNone(obj['sha256sum'])
     obj.load()
     self.assertEqual(obj.md5, md5)
     self.assertEqual(obj['sha256sum'], sha256sum)
Exemplo n.º 2
0
 def test_can_generate_upload_body(self):
     obj = Object({
         'filename': __file__,
         'mode': 'raw',
         'target-type': 'device',
         'target': '/dev/sda',
     })
     obj.load()
     with open(__file__) as fp:
         data = fp.read().encode()
     sha = hashlib.sha256(data).hexdigest()
     md5 = hashlib.md5(data).hexdigest()
     expected = {
         'filename': __file__,
         'size': os.path.getsize(__file__),
         'sha256sum': sha,
         'md5': md5,
         'chunks': 1,
     }
     self.assertEqual(obj.to_upload(), expected)
Exemplo n.º 3
0
 def test_template_keeps_equal_after_object_load(self):
     obj = Object(self.default_options)
     expected = obj.to_template()
     obj.load()
     observed = obj.to_template()
     self.assertEqual(expected, observed)