Skip to content
Snippets Groups Projects
Commit 64427660 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

TST: clean up unittests

parent a952a3a0
Branches
Tags
1 merge request!1Restructure and add integration tests
Pipeline #54739 failed
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Henrik tom Wörden (h.tomwoerden@indiscale.com)
# Copyright (C) 2020-2024 IndiScale GmbH (info@indiscale.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from os.path import abspath, dirname, join from os.path import abspath, dirname, join
from pytest import raises from pytest import raises
from linkahead import get_connection, configure_connection from linkahead import get_connection, configure_connection
...@@ -7,20 +25,14 @@ from loan.box_loan import (_caller, create_person, ...@@ -7,20 +25,14 @@ from loan.box_loan import (_caller, create_person,
assert_date_in_future, DataError, EmailPatternError, assert_date_in_future, DataError, EmailPatternError,
assert_email_pattern) assert_email_pattern)
from utils import get_form_data_example
def get_data_example():
return abspath(join(dirname(__file__), "request_loan_form.json"))
def test_caller():
args = [get_data_example()]
def test_func(data):
assert data["box"] == 2345, "should contain the data from json"
return 1337
assert _caller(test_func, args) == 1337 def test_return_value_of_caller():
tval = 1337
assert _caller(lambda d: tval, [get_form_data_example()]
) == tval
def test_create_person(): def test_create_person():
p = create_person("anna", "lytik", "a@b.com") p = create_person("anna", "lytik", "a@b.com")
...@@ -29,7 +41,7 @@ def test_create_person(): ...@@ -29,7 +41,7 @@ def test_create_person():
assert p.get_property(LAST_NAME.name).value == "lytik" assert p.get_property(LAST_NAME.name).value == "lytik"
assert p.get_property(EMAIL.name).value == "a@b.com" assert p.get_property(EMAIL.name).value == "a@b.com"
def test_create_person_with_wrong_email_pattern(): def test_email_validation():
with raises(EmailPatternError): with raises(EmailPatternError):
assert_email_pattern("@asdf") assert_email_pattern("@asdf")
with raises(EmailPatternError): with raises(EmailPatternError):
...@@ -44,6 +56,7 @@ def test_create_person_with_wrong_email_pattern(): ...@@ -44,6 +56,7 @@ def test_create_person_with_wrong_email_pattern():
assert_email_pattern("\"#\"@ö.de") assert_email_pattern("\"#\"@ö.de")
def test_assert_date_in_future(): def test_assert_date_in_future():
# I can't wait for 2050 :-)
assert assert_date_in_future("2050-01-01") is None assert assert_date_in_future("2050-01-01") is None
with raises(DataError): with raises(DataError):
assert_date_in_future("1971-01-01") assert_date_in_future("1971-01-01")
...@@ -8,16 +8,11 @@ from loan.box_loan import (PERSON, FIRST_NAME, EMAIL, BOX, BORROWER, ...@@ -8,16 +8,11 @@ from loan.box_loan import (PERSON, FIRST_NAME, EMAIL, BOX, BORROWER,
DESTINATION, F_FIRST_NAME, F_EMAIL, DESTINATION, F_FIRST_NAME, F_EMAIL,
F_EXPECTED_RETURN_DATE, DataError, BOX_NUMBER) F_EXPECTED_RETURN_DATE, DataError, BOX_NUMBER)
from loan.request_loan import (create_loan, _issue_loan_request) from loan.request_loan import (create_loan, _issue_loan_request)
from utils import get_form_data_example
def get_data_example():
return abspath(join(dirname(__file__), "request_loan_form.json"))
def test_issue_loan_request_with_wrong_return_date(): def test_issue_loan_request_with_wrong_return_date():
data = get_data(get_data_example()) data = get_data(get_form_data_example())
data[F_EXPECTED_RETURN_DATE] = "1983-02-03" data[F_EXPECTED_RETURN_DATE] = "1983-02-03"
with raises(DataError): with raises(DataError):
_issue_loan_request(data) _issue_loan_request(data)
......
...@@ -9,19 +9,11 @@ from loan.box_loan import (FIRST_NAME, EMAIL, LAST_NAME, F_FIRST_NAME, ...@@ -9,19 +9,11 @@ from loan.box_loan import (FIRST_NAME, EMAIL, LAST_NAME, F_FIRST_NAME,
LOAN_REQUESTED, StateError, F_EXPECTED_RETURN_DATE, LOAN_REQUESTED, StateError, F_EXPECTED_RETURN_DATE,
DataError, LOAN) DataError, LOAN)
from loan.request_return import get_loan, _issue_return_request from loan.request_return import get_loan, _issue_return_request
from utils import get_form_data_example
def get_data_example():
return abspath(join(dirname(__file__), "request_loan_form.json"))
def test_return_request_with_wrong_return_date(): def test_return_request_with_wrong_return_date():
data = get_data(get_data_example()) data = get_data(get_form_data_example())
data[F_EXPECTED_RETURN_DATE] = "1983-02-03" data[F_EXPECTED_RETURN_DATE] = "1983-02-03"
with raises(DataError): with raises(DataError):
_issue_return_request(data) _issue_return_request(data)
......
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Henrik tom Wörden (h.tomwoerden@indiscale.com)
# Copyright (C) 2020-2024 IndiScale GmbH (info@indiscale.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
some utility functions
"""
from os.path import abspath, dirname, join
def get_form_data_example():
return abspath(join(dirname(__file__), "request_loan_form.json"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment