def test_open(self, _mkdir): storage = SharedStorage('git', '1234') storage.open() self.assertEqual(_mkdir.call_args_list, [ ((storage.content_dir, ), {}), ((storage.links_dir, ), {}), ])
def test_open(self, _mkdir): storage = SharedStorage('git', '1234') storage.open() self.assertEqual( _mkdir.call_args_list, [ ((storage.content_dir,), {}), ((storage.links_dir,), {}), ])
def test_link(self, symlink): unit = Mock(id='0123456789') storage = SharedStorage('git', '1234') # test storage.link(unit) # validation expected_path = os.path.join(storage.links_dir, unit.id) symlink.assert_called_once_with(storage.content_dir, expected_path) self.assertEqual(unit.storage_path, expected_path)
def test_shared_dir(self, config): storage_dir = '/tmp/storage' config.get = lambda s, p: {'server': {'storage_dir': storage_dir}}[s][p] storage = SharedStorage('git', '1234') self.assertEqual( storage.shared_dir, os.path.join(storage_dir, 'content', 'shared', storage.provider, storage.storage_id))
def test_init(self, sha256): provider = 'git' storage_id = '1234' storage = SharedStorage(provider, storage_id) sha256.assert_called_once_with(storage_id) self.assertEqual(storage.storage_id, sha256.return_value.hexdigest.return_value) self.assertEqual(storage.provider, provider)
def test_duplicate_link(self, islink, readlink, symlink): unit = Mock(id='0123456789') storage = SharedStorage('git', '1234') islink.return_value = True symlink.side_effect = OSError() symlink.side_effect.errno = EEXIST readlink.return_value = storage.content_dir # test storage.link(unit) # note: not exception raised # validation expected_path = os.path.join(storage.links_dir, unit.id) symlink.assert_called_once_with(storage.content_dir, expected_path) self.assertEqual(unit.storage_path, expected_path)
def pre_save_signal(cls, sender, document, **kwargs): """ The signal that is triggered before a unit is saved. Set the _storage_path on the document and add the symbolic link. :param sender: sender class :type sender: object :param document: Document that sent the signal :type document: SharedContentUnit """ super(SharedContentUnit, cls).pre_save_signal(sender, document, **kwargs) with SharedStorage(document.storage_provider, document.storage_id) as storage: document._storage_path = storage.link(document)
def test_different_link_target(self, islink, readlink, symlink): unit = Mock(id='0123456789') storage = SharedStorage('git', '1234') islink.return_value = True symlink.side_effect = OSError() symlink.side_effect.errno = EEXIST readlink.return_value = 'different link target' # test self.assertRaises(OSError, storage.link, unit) # validation expected_path = os.path.join(storage.links_dir, unit.id) symlink.assert_called_once_with(storage.content_dir, expected_path)
def test_duplicate_nonlink(self, islink, readlink, symlink): unit = Mock(id='0123456789') storage = SharedStorage('git', '1234') islink.return_value = False # not a link symlink.side_effect = OSError() symlink.side_effect.errno = EEXIST readlink.return_value = storage.content_dir # test self.assertRaises(OSError, storage.link, unit) # validation expected_path = os.path.join(storage.links_dir, unit.id) symlink.assert_called_once_with(storage.content_dir, expected_path)
def test_link_failed(self, symlink): unit = Mock(id='0123456789') storage = SharedStorage('git', '1234') symlink.side_effect = OSError() symlink.side_effect.errno = EPERM self.assertRaises(OSError, storage.link, unit)
def test_get(self): storage = SharedStorage('git', '1234') storage.get(None) # just for coverage
def test_put(self): unit = Mock() storage = SharedStorage('git', '1234') storage.link = Mock() storage.put(unit) storage.link.assert_called_once_with(unit)
def test_links_dir(self): storage = SharedStorage('git', '1234') self.assertEqual( storage.links_dir, os.path.join(storage.shared_dir, 'links'))
def test_content_dir(self): storage = SharedStorage('git', '1234') self.assertEqual( storage.content_dir, os.path.join(storage.shared_dir, 'content'))
def storage_dir(self): storage_id = self.remote_id with SharedStorage(constants.STORAGE_PROVIDER, storage_id) as storage: return storage.content_dir