def test_preseason_reminder(self): """ Tests sending the preseason reminder if it's due :return: None """ base = "bundesliga_tippspiel.background.season_events." email = base + "send_email" load_season_events() now = datetime.utcnow() self.match.matchday = 1 db.session.commit() with patch(email) as email_mock: self.assertEqual(email_mock.call_count, 0) self.match.kickoff_datetime = now + timedelta(weeks=2) db.session.commit() self.assertFalse(handle_preseason_reminder()) self.assertEqual(email_mock.call_count, 0) self.match.kickoff_datetime = now + timedelta(days=5) db.session.commit() self.assertTrue(handle_preseason_reminder()) self.assertEqual(email_mock.call_count, 1)
def test_executing(self): """ Tests if the events are executed correctly, and only once. :return: None """ base = "bundesliga_tippspiel.background.season_events." mocked = [ base + "handle_preseason_reminder", base + "handle_midseason_reminder", base + "handle_postseason_wrapup" ] before = load_season_events() for event in before: self.assertFalse(event.executed) with patch(mocked[0], lambda: True): with patch(mocked[1], lambda: True): with patch(mocked[2], lambda: True): handle_season_events() after = load_season_events() for event in after: self.assertTrue(event.executed) with patch(mocked[0], lambda: self.fail()): with patch(mocked[1], lambda: self.fail()): with patch(mocked[2], lambda: self.fail()): handle_season_events()
def test_postseason_wrapup(self): """ Tests doing the postseason wrapup :return: None """ base = "bundesliga_tippspiel.background.season_events." email = base + "send_email" load_season_events() now = datetime.utcnow() self.match.matchday = 34 db.session.commit() with patch(email) as email_mock: self.assertEqual(email_mock.call_count, 0) self.match.kickoff_datetime = now db.session.commit() self.assertFalse(handle_postseason_wrapup()) self.assertEqual(email_mock.call_count, 0) self.match.kickoff_datetime = now - timedelta(days=1, seconds=1) db.session.commit() self.assertTrue(handle_postseason_wrapup()) self.assertEqual(email_mock.call_count, 1)
def test_initializing(self): """ Tests initializing the season-wide database entries :return: None """ total = len([x for x in SeasonEventType]) self.assertEqual(len(SeasonEvent.query.all()), 0) load_season_events() self.assertEqual(len(SeasonEvent.query.all()), total) load_season_events() self.assertEqual(len(SeasonEvent.query.all()), total)