async def test_happy_path(self, mock_datetime, mock_session_factory): reminder_mock = _mock_reminder(mock_session_factory, DEFAULT_PHONE_NUMBER) mock_datetime.utcnow.return_value = DEFAULT_NOW tracker = _create_tracker() dispatcher = CollectingDispatcher() with patch.dict("os.environ", ENV): await ActionSendDailyCheckInReminder().run(dispatcher, tracker, {}) self.assertEqual(len(dispatcher.messages), 1) message = dispatcher.messages[0] self.assertEqual(message["template"], "utter_checkin_reminder") self.assertEqual(message["first_name"], DEFAULT_FIRST_NAME) self.assertEqual( message["check_in_url"], CHECKIN_URL_PATTERN.format( language=DEFAULT_LANGUAGE, reminder_id=DEFAULT_REMINDER_ID_HASH ), ) self.assertEqual(reminder_mock.last_reminded_at, DEFAULT_NOW) mock_session_factory.return_value.commit.assert_called() mock_session_factory.return_value.close.assert_called()
def setUp(self): super().setUp() self.maxDiff = None self.patcher = patch.dict("os.environ", ENV) self.patcher.start() self.action = ActionInitializeDailyCheckin()
async def test_phone_not_match(self, mock_session_factory): _mock_reminder(mock_session_factory, "99999999999") tracker = _create_tracker() dispatcher = CollectingDispatcher() with patch.dict("os.environ", ENV): with self.assertRaises(expected_exception=InvalidExternalEventException): await ActionSendDailyCheckInReminder().run(dispatcher, tracker, {}) mock_session_factory.return_value.rollback.assert_called() mock_session_factory.return_value.close.assert_called()
async def test_reminder_not_found(self, mock_session_factory): mock_session_factory.return_value.query.return_value.get.return_value = None tracker = _create_tracker() dispatcher = CollectingDispatcher() with patch.dict("os.environ", ENV): with self.assertRaises(expected_exception=ReminderNotFoundException): await ActionSendDailyCheckInReminder().run(dispatcher, tracker, {}) mock_session_factory.return_value.rollback.assert_called() mock_session_factory.return_value.close.assert_called()
async def test_555_phone_number_no_reminder( self, mock_datetime, mock_session_factory ): _mock_reminder(mock_session_factory, "12345556789") mock_datetime.utcnow.return_value = DEFAULT_NOW tracker = _create_tracker() dispatcher = CollectingDispatcher() with patch.dict("os.environ", ENV): await ActionSendDailyCheckInReminder().run(dispatcher, tracker, {}) self.assertListEqual(dispatcher.messages, []) mock_session_factory.return_value.commit.assert_called() mock_session_factory.return_value.close.assert_called()