def test_path_unchanged(self): with utils.NamedTemporaryDirectory() as tmp_d: non_existing_path = tmp_d / 'does' / 'not' / 'exist' self.assertFalse(non_existing_path.exists()) utils.is_writeable(non_existing_path) self.assertFalse(non_existing_path.exists()) self.assertFalse((tmp_d / 'does').exists())
def test_disable_backoff(self): path = Path('swift://AUTH_stor_test/container/test/') swift_opts = {'num_retries': 0} utils.is_writeable(path, swift_opts) self.mock_copy.assert_called_with(self.filename, path, swift_retry_options=swift_opts)
def test_container_created_in_another_client(self): # Simulate that container doesn't exist at the beginning, but is created after the # is_writeable is called. self.mock_exists.side_effect = [False, True] self.mock_remove_container.side_effect = stor.swift.ConflictError( 'foo') self.assertTrue( utils.is_writeable('swift://AUTH_stor_test/container/'))
def test_path_no_perms(self): self.mock_copy.side_effect = stor.exceptions.FailedUploadError('foo') self.assertFalse(utils.is_writeable('s3://stor-test/foo/bar')) self.assertFalse(self.mock_remove.called)
def test_success(self): path = 's3://stor-test/foo/bar' self.assertTrue(utils.is_writeable(path)) self.mock_remove.assert_called_with( S3Path('{}/{}'.format(path, self.filename)))
def test_no_trailing_slash(self): path = SwiftPath('swift://AUTH_stor_test/container') utils.is_writeable(path) # no trailing slash self.mock_copy.assert_called_with(self.filename, utils.with_trailing_slash(path), swift_retry_options=None)
def test_path_no_perms(self): self.mock_copy.side_effect = stor.swift.UnauthorizedError('foo') self.assertFalse( utils.is_writeable('swift://AUTH_stor_test/container/test/'))
def test_existing_path_not_removed(self): self.mock_exists.return_value = True utils.is_writeable('swift://AUTH_stor_test/container/test/') self.assertFalse(self.mock_remove_container.called)
def test_path_unchanged(self): # Make the first call to exists() return False and the second return True. self.mock_exists.side_effect = [False, True] utils.is_writeable('swift://AUTH_stor_test/container/test/') self.mock_remove_container.assert_called_once_with( SwiftPath('swift://AUTH_stor_test/container/'))
def test_non_existing_path(self): self.mock_exists.return_value = False self.assertTrue( utils.is_writeable('swift://AUTH_stor_test/container/test/'))
def test_existing_path(self): self.mock_exists.return_value = True path = SwiftPath('swift://AUTH_stor_test/container/test/') self.assertTrue(utils.is_writeable(path)) self.mock_remove.assert_called_with(path / self.filename)
def test_path_no_perms(self): with utils.NamedTemporaryDirectory() as tmp_d: os.chmod(tmp_d, stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH) self.assertFalse(utils.is_writeable(tmp_d))
def test_existing_path_not_removed(self): with utils.NamedTemporaryDirectory() as tmp_d: self.assertTrue(tmp_d.exists()) utils.is_writeable(tmp_d) self.assertTrue(tmp_d.exists())
def test_non_existing_path(self): with utils.NamedTemporaryDirectory() as tmp_d: non_existing_path = tmp_d / 'does' / 'not' / 'exist' self.assertFalse(utils.is_writeable(non_existing_path))
def test_existing_path(self): with utils.NamedTemporaryDirectory() as tmp_d: self.assertTrue(utils.is_writeable(tmp_d))