Coverage for bundesliga_tippspiel/routes/api/betting.py: 74%

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 flask import Blueprint, request 

21from flask_login import login_required, current_user 

22from jerrycan.routes.decorators import api, api_login_required 

23from bundesliga_tippspiel.Config import Config 

24from bundesliga_tippspiel.utils.bets import place_bets 

25 

26 

27def define_blueprint(blueprint_name: str) -> Blueprint: 

28 """ 

29 Defines the blueprint for this route 

30 :param blueprint_name: The name of the blueprint 

31 :return: The blueprint 

32 """ 

33 blueprint = Blueprint(blueprint_name, __name__) 

34 api_base_path = f"/api/v{Config.API_VERSION}" 

35 

36 @blueprint.route(f"{api_base_path}/place_bets", methods=["PUT"]) 

37 @api_login_required 

38 @login_required 

39 @api 

40 def api_place_bets(): 

41 """ 

42 Places bets using the API 

43 Expects the following format: 

44 { 

45 "bets": [ 

46 {"league": str, "season": int, "matchday": int, 

47 "home_team": str, "away_team": str, 

48 "home_score": int, "away_score: int} 

49 ] 

50 } 

51 :return: The Response 

52 """ 

53 bets = [ 

54 (x["league"], x["season"], x["matchday"], 

55 x["home_team"], x["away_team"], 

56 x["home_score"], x["away_score"]) 

57 for x in request.get_json()["bets"] 

58 ] 

59 successful = place_bets(current_user, bets) 

60 return {"placed": successful} 

61 

62 return blueprint