def setUp(self): super(TestDirectoryCreatorSubscriber, self).setUp() self.directory_to_create = os.path.join(self.file_creator.rootdir, 'new-directory') self.filename = os.path.join(self.directory_to_create, 'myfile') call_args = FakeTransferFutureCallArgs(fileobj=self.filename) meta = FakeTransferFutureMeta(call_args=call_args) self.future = FakeTransferFuture(meta=meta) self.subscriber = DirectoryCreatorSubscriber()
def _add_additional_subscribers(self, subscribers, fileinfo): subscribers.append(ProvideSizeSubscriber(fileinfo.size)) subscribers.append(DirectoryCreatorSubscriber()) subscribers.append(ProvideLastModifiedTimeSubscriber( fileinfo.last_update, self._result_queue)) if self._cli_params.get('is_move', False): subscribers.append(DeleteSourceObjectSubscriber( fileinfo.source_client))
def setUp(self): super(TestDirectoryCreatorSubscriber, self).setUp() self.directory_to_create = os.path.join(self.file_creator.rootdir, "new-directory") self.filename = os.path.join(self.directory_to_create, "myfile") call_args = FakeTransferFutureCallArgs(fileobj=self.filename) meta = FakeTransferFutureMeta(call_args=call_args) self.future = FakeTransferFuture(meta=meta) self.subscriber = DirectoryCreatorSubscriber()
class TestDirectoryCreatorSubscriber(BaseTestWithFileCreator): def setUp(self): super(TestDirectoryCreatorSubscriber, self).setUp() self.directory_to_create = os.path.join(self.file_creator.rootdir, "new-directory") self.filename = os.path.join(self.directory_to_create, "myfile") call_args = FakeTransferFutureCallArgs(fileobj=self.filename) meta = FakeTransferFutureMeta(call_args=call_args) self.future = FakeTransferFuture(meta=meta) self.subscriber = DirectoryCreatorSubscriber() def test_on_queued_creates_directories_if_do_not_exist(self): self.subscriber.on_queued(self.future) self.assertTrue(os.path.exists(self.directory_to_create)) def test_on_queued_does_not_create_directories_if_exist(self): os.makedirs(self.directory_to_create) # This should not cause any issues if the directory already exists self.subscriber.on_queued(self.future) # The directory should still exist self.assertTrue(os.path.exists(self.directory_to_create)) def test_on_queued_failure_propogates_create_directory_error(self): # If makedirs() raises an OSError of exception, we should # propogate the exception with a better worded CreateDirectoryError. with mock.patch("os.makedirs") as makedirs_patch: makedirs_patch.side_effect = OSError() with self.assertRaises(CreateDirectoryError): self.subscriber.on_queued(self.future) self.assertFalse(os.path.exists(self.directory_to_create)) def test_on_queued_failure_propogates_clear_error_message(self): # If makedirs() raises an OSError of exception, we should # propogate the exception. with mock.patch("os.makedirs") as makedirs_patch: os_error = OSError() os_error.errno = errno.EEXIST makedirs_patch.side_effect = os_error # The on_queued should not raise an error if the directory # already exists try: self.subscriber.on_queued(self.future) except Exception as e: self.fail( "on_queued should not have raised an exception related " "to directory creation especially if one already existed " "but got %s" % e )
class TestDirectoryCreatorSubscriber(BaseTestWithFileCreator): def setUp(self): super(TestDirectoryCreatorSubscriber, self).setUp() self.directory_to_create = os.path.join(self.file_creator.rootdir, 'new-directory') self.filename = os.path.join(self.directory_to_create, 'myfile') call_args = FakeTransferFutureCallArgs(fileobj=self.filename) meta = FakeTransferFutureMeta(call_args=call_args) self.future = FakeTransferFuture(meta=meta) self.subscriber = DirectoryCreatorSubscriber() def test_on_queued_creates_directories_if_do_not_exist(self): self.subscriber.on_queued(self.future) self.assertTrue(os.path.exists(self.directory_to_create)) def test_on_queued_does_not_create_directories_if_exist(self): os.makedirs(self.directory_to_create) # This should not cause any issues if the directory already exists self.subscriber.on_queued(self.future) # The directory should still exist self.assertTrue(os.path.exists(self.directory_to_create)) def test_on_queued_failure_propogates_create_directory_error(self): # If makedirs() raises an OSError of exception, we should # propogate the exception with a better worded CreateDirectoryError. with mock.patch('os.makedirs') as makedirs_patch: makedirs_patch.side_effect = OSError() with self.assertRaises(CreateDirectoryError): self.subscriber.on_queued(self.future) self.assertFalse(os.path.exists(self.directory_to_create)) def test_on_queued_failure_propogates_clear_error_message(self): # If makedirs() raises an OSError of exception, we should # propogate the exception. with mock.patch('os.makedirs') as makedirs_patch: os_error = OSError() os_error.errno = errno.EEXIST makedirs_patch.side_effect = os_error # The on_queued should not raise an error if the directory # already exists try: self.subscriber.on_queued(self.future) except Exception as e: self.fail( 'on_queued should not have raised an exception related ' 'to directory creation especially if one already existed ' 'but got %s' % e)
def _add_additional_subscribers(self, subscribers, fileinfo): subscribers.append(ProvideSizeSubscriber(fileinfo.size)) subscribers.append(DirectoryCreatorSubscriber()) subscribers.append( ProvideLastModifiedTimeSubscriber(fileinfo.last_update, self._result_queue))