fix: linter errors over test_api.py

This commit is contained in:
Alec.Schmidt
2025-03-18 10:18:15 +01:00
parent 570a0d3cea
commit df1db2fd97

View File

@@ -17,7 +17,6 @@
from urllib.parse import urlencode from urllib.parse import urlencode
import json import json
import pytest
__author__ = 'Michael Mader' __author__ = 'Michael Mader'
__date__ = "2023-03-12" __date__ = "2023-03-12"
@@ -27,12 +26,12 @@ __email__ = "michael.maeder@hefr.ch"
def call(client, path, params): def call(client, path, params):
"""calling function that simulates an API webcall of a specific function/route """calling function that simulates an API webcall of a specific function/route
Args: Args:
client: this is the client object used by pytest to 'simulate' the API without running the webserver client: this is the client object used by pytest to 'simulate' the API without running the webserver
path: route of the API to use path: route of the API to use
params: GET parameter that are passed to the function params: GET parameter that are passed to the function
Returns: Returns:
json: the result of the client call json: the result of the client call
""" """
@@ -40,50 +39,59 @@ def call(client, path, params):
response = client.get(url) response = client.get(url)
return json.loads(response.data.decode('utf-8')) return json.loads(response.data.decode('utf-8'))
# increment test 1 # increment test 1
def test_plus_one1(client): def test_plus_one1(client):
result = call(client, '/inc', {'x': 2}) result = call(client, '/inc', {'x': 2})
assert result['x'] == 3 assert result['x'] == 3
# increment test 1 # increment test 1
def test_plus_one2(client): def test_plus_one2(client):
result = call(client, '/inc', {'x': -2}) result = call(client, '/inc', {'x': -2})
assert result['x'] == -1 assert result['x'] == -1
# adding test with negative value # adding test with negative value
def test_plus_y(client): def test_plus_y(client):
result = call(client, '/add', {'x': -2, 'y': 7}) result = call(client, '/add', {'x': -2, 'y': 7})
assert result['result'] == 5 assert result['result'] == 5
# multiplication test # multiplication test
def test_multiply(client): def test_multiply(client):
result = call(client, '/mul', {'x': -2, 'y': 7}) result = call(client, '/mul', {'x': -2, 'y': 7})
assert result['result'] == -14 assert result['result'] == -14
# division test # division test
def test_division(client): def test_division(client):
result = call(client, '/div', {'x': 35, 'y': 7}) result = call(client, '/div', {'x': 35, 'y': 7})
assert result['result'] == 5 assert result['result'] == 5
# type tests # type tests
def test_type_inc(client): def test_type_inc(client):
result = call(client, '/inc', {'x': 'a'}) result = call(client, '/inc', {'x': 'a'})
assert result["error"] == "Type error" assert result["error"] == "Type error"
def test_type_add(client): def test_type_add(client):
result = call(client, '/add', {'x': 'a', 'y': 1}) result = call(client, '/add', {'x': 'a', 'y': 1})
assert result["error"] == "Type error" assert result["error"] == "Type error"
result = call(client, '/add', {'x': 1, 'y': 'a'}) result = call(client, '/add', {'x': 1, 'y': 'a'})
assert result["error"] == "Type error" assert result["error"] == "Type error"
def test_type_mul(client): def test_type_mul(client):
result = call(client, '/mul', {'x': 'a', 'y': 1}) result = call(client, '/mul', {'x': 'a', 'y': 1})
assert result["error"] == "Type error" assert result["error"] == "Type error"
result = call(client, '/mul', {'x': 1, 'y': 'a'}) result = call(client, '/mul', {'x': 1, 'y': 'a'})
assert result["error"] == "Type error" assert result["error"] == "Type error"
def test_type_div(client): def test_type_div(client):
result = call(client, '/div', {'x': 'a', 'y': 1}) result = call(client, '/div', {'x': 'a', 'y': 1})
assert result["error"] == "Type error" assert result["error"] == "Type error"
result = call(client, '/div', {'x': 1, 'y': 'a'}) result = call(client, '/div', {'x': 1, 'y': 'a'})
assert result["error"] == "Type error" assert result["error"] == "Type error"