def setUp(self): super().setUp() self.future_match = FutureMatchFactory.create(home_team='Ajax', away_team='Barcelona') self.future_match2 = FutureMatchFactory.create(home_team='Barcelona', away_team='Ajax') self.past_match = PastMatchFactory.create() self.past_match2 = PastMatchFactory.create() # Ugo is a logged-in user user = self.create_pre_authenticated_session('ugo') self.bets = [ BetFactory.create(match=self.future_match, user=user, home_score=5, away_score=1), BetFactory.create(match=self.past_match, user=user, home_score=1, away_score=1), BetFactory.create(match=self.past_match2, user=user, home_score=2, away_score=1), ]
def setUpTestData(cls): cls.future_match1 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=2)) cls.future_match2 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=1)) cls.future_match3 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=3)) cls.user = UserFactory.create()
def setUpData(self): self.past_match = PastMatchFactory.create(home_team='Bordo', away_team='Chelsea') self.past_match2 = PastMatchFactory.create(home_team='Bordo', away_team='Ajax') self.past_match3 = PastMatchFactory.create(home_team='Chelsea', away_team='Ajax', home_score=None, away_score=None) self.future_match = FutureMatchFactory.create(home_team='Ajax', away_team='Barcelona', datetime="2047-01-09 05:04+00:00") self.user1 = UserFactory.create(username='******') self.user2 = UserFactory.create(username='******') self.bets = [ [ BetFactory.create(match=self.future_match, user=self.user1, home_score=2, away_score=1), BetFactory.create(match=self.future_match, user=self.user2, home_score=4, away_score=0), ], # future match [ None, BetFactory.create(match=self.past_match, user=self.user2, home_score=2, away_score=0), ], # past match [ BetFactory.create(match=self.past_match2, user=self.user1, home_score=1, away_score=3), BetFactory.create(match=self.past_match2, user=self.user2, home_score=0, away_score=0), ], [ None, BetFactory.create(match=self.past_match3, user=self.user2, home_score=0, away_score=0), ] ] self.past_match.set_score(home_score=2, away_score=0) self.past_match2.set_score(home_score=0, away_score=0)
def test_set_score_doesnt_call_save_model_for_future_match( self, mock_save): match = FutureMatchFactory.create() mock_save.reset_mock() match.set_score(home_score=1, away_score=2) self.assertFalse(mock_save.called)
def test_bet_save_doesnt_calls_calc_result_func(self, mock_calc_bet_result): match = FutureMatchFactory.create() BetFactory.build(home_score=2, away_score=1, match=match, user=self.user) self.assertFalse(mock_calc_bet_result.called, False)
def test_has_result_false_for_future_match(self): match = FutureMatchFactory.create() self.assertFalse(match.has_result)
def test_can_be_without_scores(self): match = FutureMatchFactory.create() match.full_clean() # should not raise
def test_has_is_in_future_attr(self): past_match = PastMatchFactory.create() future_match = FutureMatchFactory.create() self.assertTrue(future_match.in_future) self.assertFalse(past_match.in_future)
def setUpTestData(cls): cls.past_match = PastMatchFactory.create() cls.future_match = FutureMatchFactory.create() cls.user = UserFactory.create()