コード例 #1
0
ファイル: test_storage.py プロジェクト: maxamillion/pulp
    def test_put_file(self, _mkdir, shutil):
        path_in = '/tmp/test'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        shutil.copy.assert_called_once_with(path_in, unit.storage_path)
コード例 #2
0
    def test_put_file(self, _mkdir, shutil):
        path_in = '/tmp/test'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        shutil.copy.assert_called_once_with(path_in, unit.storage_path)
コード例 #3
0
ファイル: test_storage.py プロジェクト: maxamillion/pulp
    def test_put_file_with_location(self, _mkdir, shutil):
        path_in = '/tmp/test'
        location = '/a/b/'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()

        # test
        storage.put(unit, path_in, location)

        # validation
        destination = os.path.join(unit.storage_path, location.lstrip('/'))
        _mkdir.assert_called_once_with(os.path.dirname(destination))
        shutil.copy.assert_called_once_with(path_in, destination)
コード例 #4
0
    def test_put_file_with_location(self, _mkdir, shutil):
        path_in = '/tmp/test'
        location = '/a/b/'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()

        # test
        storage.put(unit, path_in, location)

        # validation
        destination = os.path.join(unit.storage_path, location.lstrip('/'))
        _mkdir.assert_called_once_with(os.path.dirname(destination))
        shutil.copy.assert_called_once_with(path_in, destination)
コード例 #5
0
ファイル: test_storage.py プロジェクト: ktdreyer/pulp
    def test_put_file(self, config, shutil):
        path_in = '/tmp/test'
        storage_dir = '/tmp/storage'
        unit = Mock(id='0123456789', unit_type_id='ABC')
        config.get = lambda s, p: {'server': {'storage_dir': storage_dir}}[s][p]
        storage = FileStorage()

        # test
        storage.put(unit, path_in)

        # validation
        destination = os.path.join(
            os.path.join(storage_dir, 'content', 'units', unit.unit_type_id),
            unit.id[0:4], unit.id)
        shutil.copy.assert_called_once_with(path_in, destination)
        self.assertEqual(unit.storage_path, destination)
コード例 #6
0
ファイル: test_storage.py プロジェクト: alexxa/pulp
    def test_put_file_with_location(self, _mkdir, shutil, tempfile, close, rename):
        path_in = '/tmp/test'
        location = '/a/b/'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)

        # test
        storage.put(unit, path_in, location)

        # validation
        destination = os.path.join(unit.storage_path, location.lstrip('/'))
        _mkdir.assert_called_once_with(os.path.dirname(destination))
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        rename.assert_called_once_with(temp_destination, destination)
コード例 #7
0
ファイル: test_storage.py プロジェクト: ggainey/pulp
    def test_put_file_with_location(self, _mkdir, shutil, tempfile, close,
                                    rename):
        path_in = '/tmp/test'
        location = '/a/b/'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)

        # test
        storage.put(unit, path_in, location)

        # validation
        destination = os.path.join(unit.storage_path, location.lstrip('/'))
        _mkdir.assert_called_once_with(os.path.dirname(destination))
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        rename.assert_called_once_with(temp_destination, destination)
コード例 #8
0
ファイル: test_storage.py プロジェクト: alexxa/pulp
    def test_put_file_correct_size(self, _mkdir, shutil, tempfile, close, rename):
        path_in = '/tmp/test'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        tempfile.mkstemp.assert_called_once_with(dir=os.path.dirname(unit.storage_path))
        close.assert_called_once_with('fd')
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        unit.verify_size.assert_called_once_with(temp_destination)
        rename.assert_called_once_with(temp_destination, unit.storage_path)
コード例 #9
0
ファイル: test_storage.py プロジェクト: ggainey/pulp
    def test_put_file_correct_size(self, _mkdir, shutil, tempfile, close,
                                   rename):
        path_in = '/tmp/test'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        tempfile.mkstemp.assert_called_once_with(
            dir=os.path.dirname(unit.storage_path))
        close.assert_called_once_with('fd')
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        unit.verify_size.assert_called_once_with(temp_destination)
        rename.assert_called_once_with(temp_destination, unit.storage_path)
コード例 #10
0
ファイル: test_storage.py プロジェクト: alexxa/pulp
    def test_put_file_no_verify_size(self, _mkdir, shutil, tempfile, close, remove, rename):
        path_in = '/tmp/test'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)
        unit.verify_size.side_effect = AttributeError("object has no attribute 'verify_size'")

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        tempfile.mkstemp.assert_called_once_with(dir=os.path.dirname(unit.storage_path))
        close.assert_called_once_with('fd')
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        unit.verify_size.assert_called_once_with(temp_destination)
        self.assertFalse(remove.called)
        rename.assert_called_once_with(temp_destination, unit.storage_path)
コード例 #11
0
ファイル: test_storage.py プロジェクト: ggainey/pulp
    def test_put_file_no_verify_size(self, _mkdir, shutil, tempfile, close,
                                     remove, rename):
        path_in = '/tmp/test'
        temp_destination = '/some/file/path'
        unit = Mock(id='123', storage_path='/tmp/storage')
        storage = FileStorage()
        tempfile.mkstemp.return_value = ('fd', temp_destination)
        unit.verify_size.side_effect = AttributeError(
            "object has no attribute 'verify_size'")

        # test
        storage.put(unit, path_in)

        # validation
        _mkdir.assert_called_once_with(os.path.dirname(unit.storage_path))
        tempfile.mkstemp.assert_called_once_with(
            dir=os.path.dirname(unit.storage_path))
        close.assert_called_once_with('fd')
        shutil.copy.assert_called_once_with(path_in, temp_destination)
        unit.verify_size.assert_called_once_with(temp_destination)
        self.assertFalse(remove.called)
        rename.assert_called_once_with(temp_destination, unit.storage_path)