Commit 767e7dcc authored by Hermann Krumrey's avatar Hermann Krumrey

Merge branch 'develop' into 'master'

Develop

See merge request namibsun/python/bundesliga-tippspiel!12
parents 228137f2 98add40a
V 0.17.0:
- Introduced custom HTTP error pages
- Fixed issues with updating match data
V 0.16.5:
- Fixed issues with updating match data
V 0.16.4:
......
......@@ -36,6 +36,9 @@ login_manager = LoginManager(app)
"""
The Flask-Login Login Manager
"""
# Config
app.config["TRAP_HTTP_EXCEPTIONS"] = True
login_manager.session_protection = "strong"
......
......@@ -36,6 +36,6 @@ def load_routes():
# noinspection PyUnresolvedReferences
import bundesliga_tippspiel.routes.information
# noinspection PyUnresolvedReferences
# import bundesliga_tippspiel.routes.errors
import bundesliga_tippspiel.routes.errors
load_api_routes()
......@@ -17,19 +17,24 @@ You should have received a copy of the GNU General Public License
along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
# from flask import redirect, url_for, flash
# from bundesliga_tippspiel import app
# from bundesliga_tippspiel.types.enums import AlertSeverity
from flask import redirect, url_for, flash, render_template
from werkzeug.exceptions import HTTPException
from bundesliga_tippspiel import app
from bundesliga_tippspiel.types.enums import AlertSeverity
# @app.errorhandler(401)
# def unauthorized(_):
# """
# Custom redirect for 401 errors
# :return: A redirect to the login page
# """
# flash(
# "Du bist nicht angemeldet. Bitte melde dich an.",
# AlertSeverity.DANGER.value
# )
# return redirect(url_for("login"))
@app.errorhandler(HTTPException)
def error_handling(error: HTTPException):
"""
Custom redirect for 401 errors
:param error: The error that caused the error handler to be called
:return: A redirect to the login page
"""
if error.code == 401:
flash(
"Du bist nicht angemeldet. Bitte melde dich an.",
AlertSeverity.DANGER.value
)
return redirect(url_for("login"))
else:
return render_template("static/error_page.html", error=error)
{#
Copyright 2017 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bundesliga-tippspiel.
bundesliga-tippspiel is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bundesliga-tippspiel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "components/base_layout.html" %}
{% block body %}
<h1>Error {{ error.code }}</h1>
<h3>{{ error.description }}</h3>
{% endblock %}
......@@ -108,7 +108,11 @@ class _RouteTestFramework(_TestFramework):
unauthorized = self.client.get(
self.route_path, follow_redirects=True
)
self.assertEqual(unauthorized.status_code, 401)
self.assertEqual(unauthorized.status_code, 200)
self.assertTrue(
b"Du bist nicht angemeldet. Bitte melde dich an."
in unauthorized.data
)
self.login()
static = self.client.get(self.route_path, follow_redirects=True)
......@@ -152,4 +156,4 @@ class _RouteTestFramework(_TestFramework):
else:
continue
self.assertEqual(malformed.status_code, 400)
self.assertTrue(b"Error 400" in malformed.data)
......@@ -54,8 +54,11 @@ class TestDeleteUserRoute(_RouteTestFramework):
self.assertTrue(b"Dein Account wurde erfolgreich gel" in resp.data)
self.assertFalse(User.query.get(self.user.id))
unauthorized = self.client.post(self.route_path)
self.assertEqual(unauthorized.status_code, 401)
unauthorized = self.client.post(self.route_path, follow_redirects=True)
self.assertTrue(
b"Du bist nicht angemeldet. Bitte melde dich an."
in unauthorized.data
)
def test_unsuccessful_requests(self):
"""
......
......@@ -67,9 +67,12 @@ class TestMatchRoute(_RouteTestFramework):
Tests (an) unsuccessful request(s)
:return: None
"""
resp = self.client.get(self.route_path)
self.assertEqual(resp.status_code, 401)
resp = self.client.get(self.route_path, follow_redirects=True)
self.assertTrue(
b"Du bist nicht angemeldet. Bitte melde dich an."
in resp.data
)
self.login()
resp = self.client.get("/match/1000")
self.assertEqual(resp.status_code, 404)
self.assertTrue(b"Error 404"in resp.data)
......@@ -96,4 +96,4 @@ class TestTeamRoute(_RouteTestFramework):
"""
self.login()
resp = self.client.get("/team/1000000000")
self.assertEqual(resp.status_code, 404)
self.assertTrue(b"Error 404" in resp.data)
......@@ -81,4 +81,4 @@ class TestUserRoute(_RouteTestFramework):
"""
self.login()
resp = self.client.get("/user/1000000000")
self.assertEqual(resp.status_code, 404)
self.assertTrue(b"Error 404" in resp.data)
......@@ -157,7 +157,7 @@ def parse_goal(goal_data: Dict[str, Any], match_id: int) -> Optional[Goal]:
minute_et = minute - 90
minute = 90
return Goal(
goal = Goal(
id=goal_data["GoalID"],
match_id=match_id,
player_id=goal_data["GoalGetterID"],
......@@ -169,6 +169,11 @@ def parse_goal(goal_data: Dict[str, Any], match_id: int) -> Optional[Goal]:
penalty=goal_data["IsPenalty"]
)
if goal.home_score == 0 and goal.away_score == 0:
return None
else:
return goal
def parse_player(goal_data: Dict[str, Any], team_id: int) -> Player:
"""
......
0.16.5
\ No newline at end of file
0.17.0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment