def handle(self, *args, **options): if options['date']: receipt_date = parse_date(options['date']) if not receipt_date: raise CommandError( 'Date %s cannot be parsed, use YYYY-MM-DD format' % date) else: workdays = WorkdayChecker() if not workdays.is_workday(date.today()): return receipt_date = workdays.get_previous_workday(date.today()) api_session = api_client.get_authenticated_api_session( settings.BANK_ADMIN_USERNAME, settings.BANK_ADMIN_PASSWORD) self.__class__.function(api_session, receipt_date)
class WorkdayCheckerTestCase(BankAdminTestCase): def setUp(self): mock_bank_holidays() self.checker = WorkdayChecker() @responses.activate def test_christmas_is_not_workday(self): self.assertFalse(self.checker.is_workday(date(2016, 12, 27))) @responses.activate def test_weekend_is_not_workday(self): self.assertFalse(self.checker.is_workday(date(2016, 12, 17))) @responses.activate def test_weekday_is_workday(self): self.assertTrue(self.checker.is_workday(date(2016, 12, 21))) @responses.activate def test_next_workday_middle_of_week(self): next_day = self.checker.get_next_workday(date(2016, 12, 21)) self.assertEqual(next_day, date(2016, 12, 22)) @responses.activate def test_next_workday_weekend(self): next_day = self.checker.get_next_workday(date(2016, 12, 16)) self.assertEqual(next_day, date(2016, 12, 19)) @responses.activate def test_next_workday_bank_holidays(self): next_day = self.checker.get_next_workday(date(2016, 12, 23)) self.assertEqual(next_day, date(2016, 12, 28)) @responses.activate def test_previous_workday_middle_of_week(self): previous_day = self.checker.get_previous_workday(date(2016, 12, 22)) self.assertEqual(previous_day, date(2016, 12, 21)) @responses.activate def test_previous_workday_weekend(self): previous_day = self.checker.get_previous_workday(date(2016, 12, 19)) self.assertEqual(previous_day, date(2016, 12, 16)) @responses.activate def test_previous_workday_bank_holidays(self): previous_day = self.checker.get_previous_workday(date(2016, 12, 28)) self.assertEqual(previous_day, date(2016, 12, 23))
def handle(self, *args, **options): if settings.CLOUD_PLATFORM_MIGRATION_MODE: logger.warning( f'{self.__class__.__module__} management command will not run in migration mode' ) return if options['date']: receipt_date = parse_date(options['date']) if not receipt_date: raise CommandError( 'Date %s cannot be parsed, use YYYY-MM-DD format' % date) else: workdays = WorkdayChecker() if not workdays.is_workday(date.today()): return receipt_date = workdays.get_previous_workday(date.today()) api_session = api_client.get_authenticated_api_session( settings.BANK_ADMIN_USERNAME, settings.BANK_ADMIN_PASSWORD) self.__class__.function(api_session, receipt_date)
def handle(self, **options): if settings.CLOUD_PLATFORM_MIGRATION_MODE: logger.warning( f'{self.__class__.__module__} management command will not run in migration mode' ) return date = options['date'] scheduled = options['scheduled'] if date and scheduled: raise CommandError( 'Date cannot be provided if running as a scheduled command') elif scheduled: try: should_continue = is_first_instance() except StackException: should_continue = True if not should_continue: logger.warning( 'Not processing private estate emails as running on non-key instance ' '(command is not idempotent)') return today = timezone.now().date() workdays = WorkdayChecker() if not workdays.is_workday(today): logger.info( 'Non-workday: no private estate batches to process') return date = workdays.get_previous_workday(today) else: date = parse_date(date) if date is None: raise CommandError( 'Date cannot be parsed, use YYYY-MM-DD format') self.process_batches(date)
def setUp(self): mock_bank_holidays() self.checker = WorkdayChecker()