Skip to content

Commit

Permalink
issue OpenClassrooms-Student-Center#2 user number of places input is …
Browse files Browse the repository at this point in the history
…at most the number of points available
  • Loading branch information
kivtorsm committed Jun 22, 2023
1 parent 5b341c9 commit 6b676db
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion templates/booking.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ <h2>{{competition['name']}}</h2>
<form action="/purchasePlaces" method="post">
<input type="hidden" name="club" value="{{club['name']}}">
<input type="hidden" name="competition" value="{{competition['name']}}">
<label for="places">How many places?</label><input type="number" name="places" id=""/>
<label for="places">How many places?</label>
<input type="number" name="places" id="" min="0" max="{{ club['points'] }}"/>
<button type="submit">Book</button>
</form>
</body>
Expand Down
42 changes: 34 additions & 8 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import sys
import os
import pytest

import server
from bs4 import BeautifulSoup

current = os.path.dirname(os.path.realpath(__file__))
parent = os.path.dirname(current)
sys.path.append(parent)
import server


@pytest.mark.parametrize("email", ['admin@irontemple.com', 'false@adress.com'])
Expand All @@ -19,9 +15,9 @@ def test_should_status_code_200(client, email):


def test_should_show_error(client):
'''
"""
Tests an error is shown if email provided is unknown.
'''
"""
email = 'false@adress.com'
response = client.post('/showSummary', data={
'email': email
Expand All @@ -37,3 +33,33 @@ def test_should_raise_index_error():
club = server.get_club_by_email(email)


class MockCompetition:
@staticmethod
def get_info():
return


def test_should_check_max_input(mocker, client):
club = {
"name": "Club Mock",
"email": "Email Mock",
"points": "5"
}
competition = {
"name": "Competition Mock",
"date": "2020-10-22 13:30:00",
"numberOfPlaces": "25"
}
mock_clubs = [club]
mock_competitions = [competition]
mocker.patch.object(server, 'clubs', mock_clubs)
mocker.patch.object(server, 'competitions', mock_competitions)

response = client.get(f'/book/{competition["name"]}/{club["name"]}')
response_soup = BeautifulSoup(response.data.decode(), 'html.parser')
input_field = response_soup.find("input", {"name": "places"})
input_max_places = input_field.attrs["max"]

expected_result = 5

assert int(input_max_places) == expected_result

0 comments on commit 6b676db

Please sign in to comment.