def get_delivery_status_infos(self): """Get translated delivery status infos in a template friendly format. """ statuses = DeliveryScheduler(self.context).get_statuses() status_infos = [ {'name': n, 'status': translate(DELIVERY_STATUS_LABELS[s], context=self.request)} for n, s in statuses.items()] return status_infos
def setUp(self): super(TestDeliveryScheduler, self).setUp() with self.login(self.records_manager): self.register_transport(EnabledTransport, 't-enabled') self.register_transport(DisabledTransport, 't-disabled') scheduler = DeliveryScheduler(self.disposition_with_sip) scheduler.schedule_delivery() self.captured_log.clear()
def test_schedules_for_transports_with_no_delivery_attempt_yet(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) statuses = scheduler.get_statuses(create_if_missing=True) statuses.clear() scheduler.schedule_delivery() self.assertEqual({u't-enabled': STATUS_SCHEDULED}, statuses)
def test_does_not_automatically_reschedule_failed_delivery(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) statuses = scheduler.get_statuses(create_if_missing=True) statuses.clear() statuses[u't-enabled'] = STATUS_FAILED scheduler.schedule_delivery() self.assertEqual({u't-enabled': STATUS_FAILED}, statuses)
def test_nightly_sip_delivery(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) statuses = scheduler.get_statuses() self.assertEqual({u'filesystem': STATUS_SCHEDULED}, statuses) self.execute_nightly_jobs(expected=1) self.assertEqual({u'filesystem': STATUS_SUCCESS}, statuses) self.assertEqual([self.sip_filename], os.listdir(self.tempdir))
def test_all_transports_implement_interface(self): self.login(self.records_manager) # Also check our testing transports self.register_transport(DummyTransport, 't-dummy') self.register_transport(EnabledTransport, 't-enabled') self.register_transport(DisabledTransport, 't-disabled') self.register_transport(FailingTransport, 't-failing') scheduler = DeliveryScheduler(self.disposition_with_sip) transports = scheduler.get_transports() for name, transport in transports: verifyObject(ISIPTransport, transport)
def test_logs_when_overwriting_existing_sip(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) filename = '%s.zip' % self.disposition_with_sip.get_sip_name() dst_path = pjoin(self.tempdir, filename) scheduler.deliver() self.assertEqual([ u"Delivering using transport 'filesystem'", u"Transported %r to %r" % (self.sip_filename, self.dst_path), u"Successful delivery using transport 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs()) scheduler.schedule_delivery(force=True) self.assertEqual([ u"Scheduling delivery for transport: 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs()) scheduler.deliver() self.assertEqual([ u"Delivering using transport 'filesystem'", u'Overwriting existing file %s' % dst_path, u"Transported %r to %r" % (self.sip_filename, self.dst_path), u"Successful delivery using transport 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs())
def test_delivers_only_using_enabled_transports(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) scheduler.deliver() statuses = scheduler.get_statuses() statuses[u't-disabled'] = STATUS_SCHEDULED self.assertEqual([ u"Skip: Transport 'filesystem' is disabled", u"Skip: Transport 'ftps' is disabled", u"Skip: Transport 't-disabled' is disabled", u"Delivering using transport 't-enabled'", u"Successful delivery using transport 't-enabled'" ], self.captured_log.pop_msgs())
def test_catches_transport_exceptions_and_sets_failed_status(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) statuses = scheduler.get_statuses(create_if_missing=True) statuses.clear() self.register_transport(FailingTransport, 't-failing') statuses[u't-failing'] = STATUS_SCHEDULED scheduler.deliver() self.assertIn(u"Delivering using transport 't-failing'", self.captured_log.msgs) self.assertIn( u"Delivery with transport 't-failing' failed: Exception('Boom',)", self.captured_log.msgs) self.assertEqual(STATUS_FAILED, statuses[u't-failing'])
def test_sip_package_is_delivered_via_filesystem_transport(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) scheduler.deliver() self.assertEqual([ u"Delivering using transport 'filesystem'", u"Transported %r to %r" % (self.sip_filename, self.dst_path), u"Successful delivery using transport 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs()) self.assertEqual([self.sip_filename], os.listdir(self.tempdir)) with open(self.dst_path) as delivered_file: delivered_data = delivered_file.read() self.assertEqual(self.disposition_with_sip.get_sip_package().data, delivered_data)
def setUp(self): super(TestFilesystemTransportBase, self).setUp() # Keep track of temporary files we create self.tempdir = tempfile.mkdtemp() # Enable FilesystemTransport registry = getUtility(IRegistry) settings = registry.forInterface(IFilesystemTransportSettings) settings.enabled = True settings.destination_directory = self.tempdir.decode('utf-8') # Scheduling deliveries would normally happen automatically after the # 'disposition-transition-dispose' transition. # However, because the disposition was created as part of the fixture, # and the FilesystemTransport was disabled at that time, the SIP # won't be scheduled for delivery yet. with self.login(self.records_manager): scheduler = DeliveryScheduler(self.disposition_with_sip) scheduler.schedule_delivery() self.captured_log.clear()
def test_sip_package_is_scheduled_for_delivery_on_dispose(self, browser): self.login(self.records_manager, browser) self.set_workflow_state('disposition-state-appraised', self.disposition) self.enable_filesystem_transport() scheduler = DeliveryScheduler(self.disposition) self.assertFalse(scheduler.is_scheduled_for_delivery()) self.assertEqual({}, scheduler.get_statuses()) browser.open(self.disposition, view='overview') browser.click_on('disposition-transition-dispose') self.assertTrue(scheduler.is_scheduled_for_delivery()) self.assertEqual({u'filesystem': STATUS_SCHEDULED}, scheduler.get_statuses()) self.assertEquals(['Item state changed.'], info_messages()) self.assertTrue(self.disposition.has_sip_package())
def test_doesnt_deliver_twice_unless_rescheduled(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) scheduler.deliver() self.assertEqual([ u"Delivering using transport 'filesystem'", u"Transported %r to %r" % (self.sip_filename, self.dst_path), u"Successful delivery using transport 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs()) self.assertTrue(os.path.isfile(self.dst_path)) os.remove(self.dst_path) scheduler.deliver() self.assertEqual([ u"Skip: Not scheduled for delivery with transport 'filesystem'", u"Skip: Transport 'ftps' is disabled" ], self.captured_log.pop_msgs()) self.assertFalse(os.path.isfile(self.dst_path))
def test_force_schedule_reschedules_all_states(self): self.login(self.records_manager) scheduler = DeliveryScheduler(self.disposition_with_sip) statuses = scheduler.get_statuses(create_if_missing=True) statuses.clear() scheduler.schedule_delivery(force=True) self.assertEqual({u't-enabled': STATUS_SCHEDULED}, statuses) statuses[u't-enabled'] = STATUS_FAILED scheduler.schedule_delivery(force=True) self.assertEqual({u't-enabled': STATUS_SCHEDULED}, statuses) statuses[u't-enabled'] = STATUS_SUCCESS scheduler.schedule_delivery(force=True) self.assertEqual({u't-enabled': STATUS_SCHEDULED}, statuses) statuses[u't-enabled'] = STATUS_SCHEDULED scheduler.schedule_delivery(force=True) self.assertEqual({u't-enabled': STATUS_SCHEDULED}, statuses)
def is_scheduled_for_delivery(self): return DeliveryScheduler(self).is_scheduled_for_delivery()
def run_job(self, job, interrupt_if_necessary): disposition = job self.logger.info("Delivering SIP for %r" % disposition) DeliveryScheduler(disposition, parent_logger=self.logger).deliver()
def schedule_sip_for_delivery(self): DeliveryScheduler(self).schedule_delivery()