Пример #1
0
 def test_open(self, _mkdir):
     storage = SharedStorage('git', '1234')
     storage.open()
     self.assertEqual(_mkdir.call_args_list, [
         ((storage.content_dir, ), {}),
         ((storage.links_dir, ), {}),
     ])
Пример #2
0
 def test_open(self, _mkdir):
     storage = SharedStorage('git', '1234')
     storage.open()
     self.assertEqual(
         _mkdir.call_args_list,
         [
             ((storage.content_dir,), {}),
             ((storage.links_dir,), {}),
         ])
Пример #3
0
    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)
Пример #4
0
 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))
Пример #5
0
 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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
 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)
Пример #11
0
 def test_get(self):
     storage = SharedStorage('git', '1234')
     storage.get(None)  # just for coverage
Пример #12
0
 def test_put(self):
     unit = Mock()
     storage = SharedStorage('git', '1234')
     storage.link = Mock()
     storage.put(unit)
     storage.link.assert_called_once_with(unit)
Пример #13
0
 def test_links_dir(self):
     storage = SharedStorage('git', '1234')
     self.assertEqual(
         storage.links_dir,
         os.path.join(storage.shared_dir, 'links'))
Пример #14
0
 def test_content_dir(self):
     storage = SharedStorage('git', '1234')
     self.assertEqual(
         storage.content_dir,
         os.path.join(storage.shared_dir, 'content'))
Пример #15
0
 def storage_dir(self):
     storage_id = self.remote_id
     with SharedStorage(constants.STORAGE_PROVIDER, storage_id) as storage:
         return storage.content_dir