def test_needs_migration_not(self): document = {'_storage_path': 'path_1'} # test unit = Unit(Mock(), document) unit.new_path = 'path_1' needed = unit.needs_migration() # validation self.assertFalse(needed)
def test_needs_migration_not(self): document = { '_storage_path': 'path_1' } # test unit = Unit(Mock(), document) unit.new_path = 'path_1' needed = unit.needs_migration() # validation self.assertFalse(needed)
def test_migrate(self, path_exists, mkdir, shutil): unit_id = '123' plan = Mock() path = '/tmp/old/path_1' new_path = '/tmp/new/content/path_2' path_exists.return_value = True # test Unit.migrate(plan, unit_id, path, new_path) # validation path_exists.assert_called_once_with(path) mkdir.assert_called_once_with(os.path.dirname(new_path)) shutil.move.assert_called_once_with(path, new_path) plan.collection.update_one.assert_called_once_with( filter={'_id': unit_id}, update={'$set': {'_storage_path': new_path}})
def test_init(self): plan = Mock() document = Mock() # test unit = Unit(plan, document) # validation self.assertEqual(unit.plan, plan) self.assertEqual(unit.document, document)
def test_key_digest(self): unit_key = { 'name': 'Elmer Fudd', 'version': '2.0', 'age': 147, } document = { '_id': '12434', '_content_type_id': 'iso', '_storage_path': '/tmp/path_1' } document.update(unit_key) plan = Mock(key_fields=sorted(unit_key.keys(), reverse=True)) # test unit = Unit(plan, document) digest = unit.key_digest() # validation # the digest is the sha256.hexdigest() of the sorted unit.key.items() self.assertEqual( digest, 'c10d6ad917b10992b41df1b88acde7cd50903b62953e5084f601150a73d998d4')
def test_properties(self): unit_key = {'name': 'Elmer Fudd', 'version': '2.0'} plan = Mock(key_fields=unit_key.keys()) document = { '_id': '12434', '_content_type_id': 'iso', '_storage_path': '/tmp/path_1' } document.update(unit_key) # test unit = Unit(plan, document) # validation self.assertEqual(unit.id, document['_id']) self.assertEqual(unit.type_id, document['_content_type_id']) self.assertEqual(unit.storage_path, document['_storage_path']) self.assertEqual(unit.key, unit_key) self.assertEqual(unit.files, tuple())