def test_register_reminder_error_01(self) -> None: """ Test the function that register a reminder, with an invalid session id. """ # The expected result expected_result = None # Prepare the mocks db_calls_mock.get_show_session.return_value = None # Call the function actual_result = reminders.register_reminder(self.session, 1, 60, 1) # Verify the result self.assertEqual(expected_result, actual_result) # Verify the calls to the mocks db_calls_mock.get_show_session.assert_called_with(self.session, 1)
def test_register_reminder_error_02(self) -> None: """ Test the function that register a reminder, with a session that is airing in less than two hours. """ # The expected result expected_result = None # Prepare the mocks show_session = models.ShowSession(None, None, datetime.datetime.utcnow() + datetime.timedelta(hours=1), 1, 1) db_calls_mock.get_show_session.return_value = show_session # Call the function actual_result = reminders.register_reminder(self.session, 1, 60, 1) # Verify the result self.assertEqual(expected_result, actual_result) # Verify the calls to the mocks db_calls_mock.get_show_session.assert_called_with(self.session, 1)
def post(self, args): """Register a reminder.""" show_session_id = args['show_session_id'] anticipation_minutes = args['anticipation_minutes'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') if reminders.register_reminder(session, show_session_id, anticipation_minutes, user_id) is not None: return flask.make_response( flask.jsonify({ 'reminder_list': auxiliary.list_to_json( reminders.get_reminders(session, user_id)) }), 201) else: return flask.make_response('Invalid reminder', 400)
def test_register_reminder_ok(self) -> None: """ Test the function that register a reminder, with success. """ # Prepare the mocks show_session = models.ShowSession(None, None, datetime.datetime.utcnow() + datetime.timedelta(hours=4), 1, 1) db_calls_mock.get_show_session.return_value = show_session reminder = models.Reminder(60, 1, 1) reminder.id = 123 db_calls_mock.register_reminder.return_value = reminder # Call the function actual_result = reminders.register_reminder(self.session, 1, 60, 1) # Verify the result self.assertEqual(123, actual_result.id) self.assertEqual(60, actual_result.anticipation_minutes) self.assertEqual(1, actual_result.session_id) self.assertEqual(1, actual_result.user_id) # Verify the calls to the mocks db_calls_mock.get_show_session.assert_called_with(self.session, 1) db_calls_mock.register_reminder.assert_called_with(self.session, 1, 60, 1)