1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ __pycache__/
|
||||
.devcontainer/
|
||||
|
||||
src/.pdm-python
|
||||
src/htmlcov
|
13
src/app.py
13
src/app.py
@@ -45,30 +45,43 @@ global_data = {'username': 'no_user'}
|
||||
# incrementation route
|
||||
@app.route('/inc')
|
||||
def plus_one():
|
||||
try:
|
||||
x = int(request.args.get('x', 1))
|
||||
except:
|
||||
return json.dumps({"error": "Type error"})
|
||||
|
||||
return json.dumps({'x': operators.addition(x, 1)})
|
||||
|
||||
# addition route, the parameters will be passed with 'x' and 'y'
|
||||
@app.route('/add')
|
||||
def plus_y():
|
||||
try:
|
||||
x = int(request.args.get('x', 1))
|
||||
y = int(request.args.get('y', 1))
|
||||
except:
|
||||
return json.dumps({"error": "Type error"})
|
||||
return json.dumps({'result': operators.addition(x, y)})
|
||||
|
||||
|
||||
# multiplication route, the parameters will be passed with 'x' and 'y'
|
||||
@app.route('/mul')
|
||||
def multiply_y():
|
||||
try:
|
||||
x = int(request.args.get('x', 1))
|
||||
y = int(request.args.get('y', 1))
|
||||
except:
|
||||
return json.dumps({"error": "Type error"})
|
||||
return json.dumps({'result': operators.multiplication(x, y)})
|
||||
|
||||
|
||||
# division route, the parameters will be passed with 'x' and 'y'
|
||||
@app.route('/div')
|
||||
def division_y():
|
||||
try:
|
||||
x = int(request.args.get('x', 1))
|
||||
y = int(request.args.get('y', 1))
|
||||
except:
|
||||
return json.dumps({"error": "Type error"})
|
||||
return json.dumps({'result': operators.division(x, y)})
|
||||
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
from urllib.parse import urlencode
|
||||
import json
|
||||
import pytest
|
||||
|
||||
__author__ = 'Michael Mader'
|
||||
__date__ = "2023-03-12"
|
||||
@@ -63,3 +64,26 @@ def test_multiply(client):
|
||||
def test_division(client):
|
||||
result = call(client, '/div', {'x': 35, 'y': 7})
|
||||
assert result['result'] == 5
|
||||
|
||||
# type tests
|
||||
def test_type_inc(client):
|
||||
result = call(client, '/inc', {'x': 'a'})
|
||||
assert result["error"] == "Type error"
|
||||
|
||||
def test_type_add(client):
|
||||
result = call(client, '/add', {'x': 'a', 'y': 1})
|
||||
assert result["error"] == "Type error"
|
||||
result = call(client, '/add', {'x': 1, 'y': 'a'})
|
||||
assert result["error"] == "Type error"
|
||||
|
||||
def test_type_mul(client):
|
||||
result = call(client, '/mul', {'x': 'a', 'y': 1})
|
||||
assert result["error"] == "Type error"
|
||||
result = call(client, '/mul', {'x': 1, 'y': 'a'})
|
||||
assert result["error"] == "Type error"
|
||||
|
||||
def test_type_div(client):
|
||||
result = call(client, '/div', {'x': 'a', 'y': 1})
|
||||
assert result["error"] == "Type error"
|
||||
result = call(client, '/div', {'x': 1, 'y': 'a'})
|
||||
assert result["error"] == "Type error"
|
Reference in New Issue
Block a user