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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ bin
include
lib
.Python
tests/
.envrc
__pycache__
launch_flask.bat
Expand Down
6 changes: 4 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def index():

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


@app.route('/book/<competition>/<club>')
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit_test/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions tests/unit_test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from unittest.mock import patch


import server

def get_clubs():
return [
{
"name":"TEST_CLUB",
"email":"TEST_CLUB_EMAIL",
"points":"13"
}
]

def get_competitions():
return [
{
"name": "TEST_COMPETITION",
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
}
]

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

@pytest.fixture(scope="class")
def competitions(request):
request.cls.competitions = get_competitions()
yield

@pytest.fixture(scope="class")
def client(request):
with patch("server.clubs", get_clubs()):
with patch("server.competitions", get_competitions()):
with server.app.test_client() as client:
request.cls.client = client
yield
16 changes: 16 additions & 0 deletions tests/unit_test/mocks_files/fixture_load.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"clubs":[
{
"name":"TEST_CLUB",
"email":"TEST_CLUB_EMAIL",
"points":"13"
}
],
"competitions": [
{
"name": "TEST_COMPETITION",
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
}
]
}
28 changes: 28 additions & 0 deletions tests/unit_test/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest import TestCase

from pytest import mark

from server import loadClubs, loadCompetitions


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

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

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

def test_sould_login_in_out(self):
response = self.client.get("/logout")
self.assertEqual(response.status_code, 302)

def test_sould_connect_with_email_exists(self):
for cl in self.clubs:
response = self.client.post("/showSummary", data={'email': cl.get('email')})
self.assertEqual(response.status_code, 200)

def test_sould_no_connect_with_email_does_not_exists(self):
response = self.client.post("/showSummary", data={'email': "not_exists_email@test.com"})
assert response.status_code == 401