Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for
from flask import Flask, render_template, request, redirect, flash, url_for
from datetime import datetime


Expand All @@ -8,13 +8,11 @@ def loadClubs(path='clubs.json'):
listOfClubs = json.load(c)['clubs']
return listOfClubs


def loadCompetitions(path='competitions.json'):
with open(path) as comps:
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions


app = Flask(__name__)
app.secret_key = 'something_special'

Expand All @@ -26,26 +24,24 @@ def loadCompetitions(path='competitions.json'):
def index():
return render_template('index.html')

@app.route('/showSummary',methods=['POST'])
@app.route('/showSummary', methods=['POST'])
def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']]
other_clubs = [club for club in clubs if club['email'] != request.form['email']]
if len(club):
return render_template('welcome.html',club=club[0],competitions=competitions, clubs=other_clubs), 200
return render_template('welcome.html', club=club[0], competitions=competitions, clubs=other_clubs), 200
return render_template('index.html'), 401


@app.route('/book/<competition>/<club>')
def book(competition,club):
def book(competition, club):
foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0]
if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
return render_template('booking.html', club=foundClub, competition=foundCompetition)
else:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions)


@app.route('/purchasePlaces',methods=['POST'])
def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
Expand All @@ -70,10 +66,8 @@ def purchasePlaces():
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions), 200


# TODO: Add route for points display


@app.route('/logout')
def logout():
return redirect(url_for('index'))
12 changes: 4 additions & 8 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GUDLFT Registration</title>
<title>Document</title>
</head>
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Please enter your secretary email to continue:
<form action="showSummary" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
ul>l*5
</body>
</html>
65 changes: 30 additions & 35 deletions tests/unit_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,43 @@

import server

clubs_obj = [
{
"name":"TEST_CLUB_1",
"email":"TEST_CLUB_EMAIL_1",
"points":"10"
},
{
"name":"TEST_CLUB_2",
"email":"TEST_CLUB_EMAIL_2",
"points":"10"
}
]
def mocks():
clubs_obj = [
{
"name":"TEST_CLUB_1",
"email":"TEST_CLUB_EMAIL_1",
"points":"10"
},
{
"name":"TEST_CLUB_2",
"email":"TEST_CLUB_EMAIL_2",
"points":"10"
}
]

competitions_obj = [
{
"name": "TEST_COMPETITION_1",
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
},
{
"name": "TEST_COMPETITION_2",
"date": "2025-03-27 10:00:00",
"numberOfPlaces": "25"
}
]


@pytest.fixture(scope="class")
def clubs(request):
request.cls.clubs = clubs_obj
yield

@pytest.fixture(scope="class")
def competitions(request):
request.cls.competitions = competitions_obj
yield
competitions_obj = [
{
"name": "TEST_COMPETITION_1",
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
},
{
"name": "TEST_COMPETITION_2",
"date": "2025-03-27 10:00:00",
"numberOfPlaces": "25"
}
]
return clubs_obj, competitions_obj

@pytest.fixture(scope="class")
def client(request):
clubs_obj, competitions_obj = mocks()
print(mocks())
with patch("server.clubs", clubs_obj):
with patch("server.competitions", competitions_obj):
with server.app.test_client() as client:
request.cls.clubs = clubs_obj
request.cls.competitions = competitions_obj
request.cls.client = client
request.cls.cost = server.cost
yield
4 changes: 2 additions & 2 deletions tests/unit_test/mocks_files/fixture_load.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name":"TEST_CLUB_1",
"email":"TEST_CLUB_EMAIL_1",
"points":"7"
"points":"10"
},
{
"name":"TEST_CLUB_2",
Expand All @@ -20,7 +20,7 @@
{
"name": "TEST_COMPETITION_2",
"date": "2025-03-27 10:00:00",
"numberOfPlaces": "24"
"numberOfPlaces": "25"
}
]
}
16 changes: 11 additions & 5 deletions tests/unit_test/test_server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from unittest import TestCase

from pytest import mark
from pytest import mark, fixture

from server import loadClubs, loadCompetitions
import json

with open("./tests/unit_test/mocks_files/fixture_load.json", 'r') as FILE_CURSOR:
FILE = json.load(FILE_CURSOR)

@mark.usefixtures('client', 'clubs', 'competitions')
@mark.usefixtures('client')
class TestServer(TestCase):

def test_loadClubs(self):
self.assertListEqual(loadClubs("./tests/unit_test/mocks_files/fixture_load.json"), self.clubs)
clubs = FILE.get("clubs")
self.assertListEqual(loadClubs("./tests/unit_test/mocks_files/fixture_load.json"), clubs)

def test_loadCompetitions(self):
self.assertListEqual(loadCompetitions("./tests/unit_test/mocks_files/fixture_load.json"), self.competitions)
competitions = FILE.get("competitions")
self.assertListEqual(loadCompetitions("./tests/unit_test/mocks_files/fixture_load.json"), competitions)

def test_sould_login_in_out(self):
response = self.client.get("/logout")
Expand Down Expand Up @@ -46,7 +52,7 @@ def test_sould_not_purshase_more_than_12_places(self):
})
self.assertIn("You cannot required more than 12 places!", response.data.decode())
self.assertEqual(response.status_code, 403)

def test_sould_not_purshase_booking_if_date_passed(self):
response = self.client.post('/purchasePlaces', data={
"club": "TEST_CLUB_1",
Expand Down