コード例 #1
0
    def test_next_alert_this_weekday(self, mock_utc_now):
        cert_date = CollectNextAlert('monday',
                                     timezone='America/Chicago',
                                     alert_time='10:30:00')

        # monday, June 1
        mock_utc_now.return_value = datetime.fromisoformat(
            '2020-06-01T10:00:00-05:00')
        actual = cert_date.next_alert_at()
        # monday, June 8
        expected = datetime.fromisoformat('2020-06-08T15:30:00+00:00')
        self.assertEqual(actual, expected)

        # tuesday, June 2
        mock_utc_now.return_value = datetime.fromisoformat(
            '2020-06-02T10:00:00-05:00')
        actual = cert_date.next_alert_at()
        # monday, June 8
        expected = datetime.fromisoformat('2020-06-08T15:30:00+00:00')
        self.assertEqual(actual, expected)

        # monday, June 8
        mock_utc_now.return_value = datetime.fromisoformat(
            '2020-06-08T10:00:00-05:00')
        actual = cert_date.next_alert_at()
        # monday, June 15
        expected = datetime.fromisoformat('2020-06-15T15:30:00+00:00')
        self.assertEqual(actual, expected)
コード例 #2
0
def apply_next_alert(alert):
    # pin "now" to the previous "next_alert_at" so we don't introduce drift from the original alert
    now = datetime.fromisoformat(alert['next_alert_at'])
    next_alert = CollectNextAlert(f"next {alert['alert_day']}",
                                  timezone=alert['timezone'],
                                  alert_time=alert['alert_time'])

    alerts_repo.set_next_alert(alert['phone_number'],
                               next_alert.next_alert_at(now).isoformat())
コード例 #3
0
    def test_parse_input(self):
        # valid
        for response in ('monday', 'MonDaY', 'next monday', 'Next MonDay'):
            self.assertTrue(CollectNextAlert(response).is_valid)

        # invalid
        for response in ('moday', 'this is wrong'):
            cert_date = CollectNextAlert(response)
            self.assertFalse(cert_date.is_valid)

            # throw exception when accessing properties on invalid collector
            with self.assertRaises(CollectException):
                sequence = cert_date.sequence

            with self.assertRaises(CollectException):
                dow = cert_date.day_of_week
コード例 #4
0
 def test_get_formatted_date(self, mock_utc_now):
     mock_utc_now.return_value = datetime.fromisoformat(
         '2020-06-01T10:00:00-05:00')
     self.assertEqual(
         CollectNextAlert('monday').formatted_date,
         'Monday, June 08 at 09:30 AM')
コード例 #5
0
 def test_day_of_week(self):
     for day in ('monday', 'tuesday', 'wednesday', 'thursday', 'friday',
                 'MoNdaY', 'TueSdaY', 'WednEsdaY', 'ThurSdaY', 'FriDaY'):
         self.assertEqual(CollectNextAlert(day).day_of_week, day.lower())
コード例 #6
0
 def test_get_sequence(self):
     self.assertEqual(CollectNextAlert('monday').sequence, 0)
     self.assertEqual(CollectNextAlert('next monday').sequence, 1)