59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
import pytest
|
|
from app import app
|
|
|
|
ROUTE = '/dice'
|
|
|
|
|
|
@pytest.fixture
|
|
def app_instance():
|
|
"""Create and configure a new test client instance."""
|
|
app_instance = app
|
|
app.config['TESTING'] = True
|
|
return app_instance
|
|
|
|
|
|
def test_roll_dice_success(app_instance):
|
|
with app.test_client() as client:
|
|
# successful request
|
|
response = client.get(ROUTE,
|
|
query_string={'quantity': '3', 'geometry': '6',
|
|
'discard_lowest': 'false'})
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_quantity_out_of_range_low(app_instance):
|
|
with app.test_client() as client:
|
|
response = client.get(ROUTE, query_string={'quantity': '0',
|
|
'geometry': '6', 'discard_lowest': 'false'})
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_quantity_out_of_range_high(app_instance):
|
|
with app.test_client() as client:
|
|
response = client.get(ROUTE, query_string={'quantity': '101',
|
|
'geometry': '6', 'discard_lowest': 'false'})
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_geometry_out_of_range_low(app_instance):
|
|
with app.test_client() as client:
|
|
# geometry out of range
|
|
response = client.get(ROUTE, query_string={'quantity': '3',
|
|
'geometry': '2', 'discard_lowest': 'false'})
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_geometry_out_of_range_high(app_instance):
|
|
with app.test_client() as client:
|
|
response = client.get(ROUTE, query_string={'quantity': '3',
|
|
'geometry': '101', 'discard_lowest': 'false'})
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_discard_lowest_success(app_instance):
|
|
with app.test_client() as client:
|
|
# test discard_lowest
|
|
response = client.get(ROUTE, query_string={'quantity': '3',
|
|
'geometry': '6', 'discard_lowest': 'true'})
|
|
assert response.status_code == 200
|