Coverage for bundesliga_tippspiel/utils/bets.py: 91%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

1"""LICENSE 

2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of bundesliga-tippspiel. 

5 

6bundesliga-tippspiel is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11bundesliga-tippspiel is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import List, Tuple 

21from jerrycan.base import db 

22from jerrycan.db.User import User 

23from bundesliga_tippspiel.db import Match, Bet 

24 

25 

26def place_bets( 

27 user: User, 

28 bets: List[Tuple[str, int, int, str, str, int, int]] 

29) -> List[Tuple[str, int, int, str, str, int, int]]: 

30 """ 

31 Places bets for a user 

32 :param user: The betting user 

33 :param bets: The bets to place in the form 

34 (league, season, matchday, home_abbrv, away_abbrv, 

35 home_score, away_score) 

36 :return: A list of successful bets 

37 """ 

38 successful = [] 

39 matches = { 

40 (x.home_team_abbreviation, x.away_team_abbreviation): x 

41 for x in Match.query.all() 

42 } 

43 for bet_tuple in bets: 

44 league, season, matchday, home, away, home_score, away_score = \ 

45 bet_tuple 

46 match = matches.get((home, away)) 

47 if match is None or match.has_started: 47 ↛ 48line 47 didn't jump to line 48, because the condition on line 47 was never true

48 continue # Can't bet on started matches 

49 bet = Bet( 

50 league=league, 

51 season=season, 

52 matchday=matchday, 

53 home_team_abbreviation=home, 

54 away_team_abbreviation=away, 

55 user_id=user.id, 

56 home_score=home_score, 

57 away_score=away_score 

58 ) 

59 db.session.merge(bet) 

60 successful.append(bet_tuple) 

61 db.session.commit() 

62 return successful