def test_past_match_set_score_calls_calc_result_func_for_all_match_bets( self, mock_calc_bet_result): match = PastMatchFactory.create(home_score=None, away_score=None) user2 = UserFactory.create() BetFactory.create(home_score=4, away_score=3, match=match, user=self.user) BetFactory.create(home_score=2, away_score=1, match=match, user=user2) mock_calc_bet_result.return_value = 12 self.assertFalse(mock_calc_bet_result.called) match.set_score(home_score=2, away_score=1) self.assertEqual(mock_calc_bet_result.call_count, 2) mock_calc_bet_result.assert_has_calls([ call( home_bet=4, away_bet=3, home_score=2, away_score=1, shootout_winner=None, shootout_bet=None, ), call( home_bet=2, away_bet=1, home_score=2, away_score=1, shootout_winner=None, shootout_bet=None, ) ])
def test_matches_contain_bets(self): BetFactory.create(match=self.future_match1, user=self.user, home_score=2, away_score=1) response = self.client.get(self.url) self.assertEqual('2 - 1', str(response.context['matches'][1].bet))
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 test_match_update_bets_calls_set_result_for_every_bet( self, mock_set_result): user1 = UserFactory.create() user2 = UserFactory.create() match = PastMatchFactory(home_score=1, away_score=2) bet1 = BetFactory(match=match, user=user1) BetFactory(match=match, user=user2) match.update_bets() self.assertEqual(mock_set_result.call_count, 2)
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_past_match_set_score_set_all_match_bets_results(self): match = PastMatchFactory.create(home_score=None, away_score=None) user2 = UserFactory.create() BetFactory.create(home_score=4, away_score=3, match=match, user=self.user) BetFactory.create(home_score=2, away_score=1, match=match, user=user2) match.set_score(home_score=2, away_score=1) self.assertEqual(Bet.objects.all()[0].result, 6) self.assertEqual(Bet.objects.all()[1].result, 12)
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_result_field_can_be_black(self): bet = BetFactory.create(home_score=2, away_score=1, match=self.past_match, user=self.user) self.assertEqual(bet.result, None)
def test_has_string_representation(self): bet = BetFactory(home_score=0, away_score=1, match=self.past_match, user=self.user) self.assertEqual(str(bet), '0 - 1')
def test_invalid_for_past_matches(self): bet = BetFactory.create(match=self.past_match, user=self.user) with self.assertRaises(ValidationError): bet.full_clean()
def test_valid_for_future_matches(self): bet = BetFactory.create(match=self.future_match, user=self.user) bet.full_clean()
def test_should_contain_user(self): with self.assertRaises(IntegrityError): BetFactory(match=self.past_match)
def test_should_contain_match(self): with self.assertRaises(IntegrityError): BetFactory(user=self.user)