Beispiel #1
0
 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))
Beispiel #2
0
    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,
            )
        ])
Beispiel #3
0
    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),
        ]
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
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)
Beispiel #7
0
 def test_invalid_for_past_matches(self):
     bet = BetFactory.create(match=self.past_match, user=self.user)
     with self.assertRaises(ValidationError):
         bet.full_clean()
Beispiel #8
0
 def test_valid_for_future_matches(self):
     bet = BetFactory.create(match=self.future_match, user=self.user)
     bet.full_clean()