Created database class.
Tidied app.py so that it only contains controller logic. Added error handling for if number of entrants exceeds number of possible identifiers Updated test coverage to test for all identifiers, as well as error case
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import pytest
|
||||
import sys, os
|
||||
myPath = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.append(myPath + '/../web/')
|
||||
try:
|
||||
os.remove('./tests/hbc.db')
|
||||
except:
|
||||
pass
|
||||
|
||||
from web import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
app.app.config['TESTING'] = True
|
||||
@@ -8,18 +17,24 @@ def client():
|
||||
|
||||
yield client
|
||||
|
||||
def test_root_page(client):
|
||||
|
||||
def test_root_page(client):
|
||||
rv = client.get('/')
|
||||
assert rv.status_code == 200
|
||||
assert b'Please enter your first name and initial' in rv.data
|
||||
|
||||
def test_generate_first(client):
|
||||
rv2 = client.post('/generate', data=dict(name='tester'), follow_redirects=True)
|
||||
assert rv2.status_code == 200
|
||||
assert b'Please mark all of your bottlecaps with the following identifier: <strong>A' in rv2.data
|
||||
|
||||
def test_generate_second(client):
|
||||
def test_generate(client):
|
||||
for identifier in app.my_db.get_identifiers_list():
|
||||
rv = client.post('/generate', data=dict(name='tester'), follow_redirects=True)
|
||||
assert rv.status_code == 200
|
||||
assert b'Please mark all of your bottlecaps with the following identifier: <strong>' \
|
||||
+ str(identifier).encode('UTF-8') in rv.data
|
||||
|
||||
|
||||
def test_generate_over_limit(client):
|
||||
rv = client.post('/generate', data=dict(name='tester'), follow_redirects=True)
|
||||
assert rv.status_code == 200
|
||||
assert b'Please mark all of your bottlecaps with the following identifier: <strong>B' in rv.data
|
||||
assert b'Maximum entry limit reached - please contact Sean or Joe' in rv.data
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user