def test_due_when_bets_placed(self):
        """
        Tests if the is_due method works correctly when bets are placed
        :return: None
        """
        now = datetime.utcnow()
        reminder = ReminderSettings(user=self.user_two,
                                    reminder_time=600,
                                    reminder_type=ReminderType.EMAIL)

        self.db.session.delete(self.match)
        self.db.session.commit()

        match_one = Match(
            home_team=self.team_one,
            away_team=self.team_two,
            matchday=1,
            kickoff=(now + timedelta(minutes=5)).strftime("%Y-%m-%d:%H-%M-%S"),
            started=False,
            finished=False,
            home_current_score=0,
            away_current_score=0,
            season=self.config.season(),
            league=self.config.OPENLIGADB_LEAGUE)
        match_two = Match(
            home_team=self.team_two,
            away_team=self.team_one,
            matchday=1,
            kickoff=(now + timedelta(minutes=7)).strftime("%Y-%m-%d:%H-%M-%S"),
            started=False,
            finished=False,
            home_current_score=0,
            away_current_score=0,
            season=self.config.season(),
            league=self.config.OPENLIGADB_LEAGUE)

        self.db.session.add(match_one)
        self.db.session.add(match_two)
        self.db.session.commit()

        self.assertEqual(len(reminder.get_due_matches()), 2)

        self.generate_sample_bet(self.user_two, match_one)
        self.assertEqual(len(reminder.get_due_matches()), 1)

        self.generate_sample_bet(self.user_two, match_two)
        self.assertEqual(len(reminder.get_due_matches()), 0)
    def test_due(self):
        """
        Tests if due matches can be found correctly

        Dates:
        Now ----- Reminder 1 ----- Match 1 ----- Reminder 2 ----- Match 2
        -0----------10min-----------30min-----------60min---------120min-
        :return: None
        """
        now = datetime.utcnow()
        new_user = User(username="******",
                        email="Z",
                        confirmed=True,
                        password_hash="Z",
                        confirmation_hash="Z")
        reminder_one = ReminderSettings(user=self.user_two,
                                        reminder_time=600,
                                        reminder_type=ReminderType.EMAIL)
        reminder_two = ReminderSettings(user=new_user,
                                        reminder_time=3600,
                                        reminder_type=ReminderType.EMAIL)

        self.db.session.delete(self.match)
        self.db.session.commit()

        match_one = Match(
            home_team=self.team_one,
            away_team=self.team_two,
            matchday=1,
            kickoff=(now +
                     timedelta(minutes=30)).strftime("%Y-%m-%d:%H-%M-%S"),
            started=False,
            finished=False,
            home_current_score=0,
            away_current_score=0,
            season=self.config.season(),
            league=self.config.OPENLIGADB_LEAGUE)
        match_two = Match(
            home_team=self.team_two,
            away_team=self.team_one,
            matchday=1,
            kickoff=(now +
                     timedelta(minutes=120)).strftime("%Y-%m-%d:%H-%M-%S"),
            started=False,
            finished=False,
            home_current_score=0,
            away_current_score=0,
            season=self.config.season(),
            league=self.config.OPENLIGADB_LEAGUE)

        self.db.session.add(match_one)
        self.db.session.add(match_two)
        self.db.session.add(new_user)
        self.db.session.commit()

        self.assertEqual(reminder_one.get_due_matches(), [])
        self.assertEqual(reminder_two.get_due_matches(), [match_one])

        with self.context:
            with mock.patch("bundesliga_tippspiel.db.settings."
                            "ReminderSettings.send_email") as mocked:
                reminder_one.send_reminder()
                self.assertEqual(0, mocked.call_count)
                reminder_two.send_reminder()
                self.assertEqual(1, mocked.call_count)
                reminder_one.send_reminder()
                reminder_two.send_reminder()
                self.assertEqual(1, mocked.call_count)

        self.assertEqual(reminder_one.get_due_matches(), [])
        self.assertEqual(reminder_two.get_due_matches(), [])

        reminder_one.set_reminder_time(10000)
        reminder_two.set_reminder_time(10000)

        self.assertEqual(reminder_two.get_due_matches(),
                         [match_one, match_two])
        self.assertEqual(reminder_two.get_due_matches(),
                         [match_one, match_two])

        with self.context:
            with mock.patch("bundesliga_tippspiel.db.settings."
                            "ReminderSettings.send_email") as mocked:
                reminder_one.send_reminder()
                self.assertEqual(1, mocked.call_count)
                reminder_two.send_reminder()
                self.assertEqual(2, mocked.call_count)
                reminder_one.send_reminder()
                reminder_two.send_reminder()
                self.assertEqual(2, mocked.call_count)