diff --git a/loanpy/unittests/test_box_loan.py b/loanpy/unittests/test_box_loan.py index 9e7631d1c172511c040b676df48269e996570131..77906a04891c4c7da901d8863f9d9f814c7ac829 100644 --- a/loanpy/unittests/test_box_loan.py +++ b/loanpy/unittests/test_box_loan.py @@ -1,3 +1,21 @@ +# 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 pytest import raises from linkahead import get_connection, configure_connection @@ -7,20 +25,14 @@ from loan.box_loan import (_caller, create_person, assert_date_in_future, DataError, EmailPatternError, 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(): p = create_person("anna", "lytik", "a@b.com") @@ -29,7 +41,7 @@ def test_create_person(): assert p.get_property(LAST_NAME.name).value == "lytik" 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): assert_email_pattern("@asdf") with raises(EmailPatternError): @@ -44,6 +56,7 @@ def test_create_person_with_wrong_email_pattern(): assert_email_pattern("\"#\"@ö.de") def test_assert_date_in_future(): + # I can't wait for 2050 :-) assert assert_date_in_future("2050-01-01") is None with raises(DataError): assert_date_in_future("1971-01-01") diff --git a/loanpy/unittests/test_request_loan.py b/loanpy/unittests/test_request_loan.py index 2379f7be473864a56e52bb617e0e8333199dcda5..63c937579048001ac944988be11058659f08baef 100644 --- a/loanpy/unittests/test_request_loan.py +++ b/loanpy/unittests/test_request_loan.py @@ -8,16 +8,11 @@ from loan.box_loan import (PERSON, FIRST_NAME, EMAIL, BOX, BORROWER, DESTINATION, F_FIRST_NAME, F_EMAIL, F_EXPECTED_RETURN_DATE, DataError, BOX_NUMBER) from loan.request_loan import (create_loan, _issue_loan_request) - - - - -def get_data_example(): - return abspath(join(dirname(__file__), "request_loan_form.json")) +from utils import get_form_data_example 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" with raises(DataError): _issue_loan_request(data) diff --git a/loanpy/unittests/test_request_return.py b/loanpy/unittests/test_request_return.py index 7dd55be61a75769cef479e60401209b9267347a4..8f6bd3b00d8cf02707eb0e688ff92e871f7f42f6 100644 --- a/loanpy/unittests/test_request_return.py +++ b/loanpy/unittests/test_request_return.py @@ -9,19 +9,11 @@ from loan.box_loan import (FIRST_NAME, EMAIL, LAST_NAME, F_FIRST_NAME, LOAN_REQUESTED, StateError, F_EXPECTED_RETURN_DATE, DataError, LOAN) from loan.request_return import get_loan, _issue_return_request - - - -def get_data_example(): - return abspath(join(dirname(__file__), "request_loan_form.json")) - - - - +from utils import get_form_data_example 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" with raises(DataError): _issue_return_request(data) diff --git a/loanpy/unittests/utils.py b/loanpy/unittests/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..c56975795276d029c644b06b1d0a2bc3aba7add8 --- /dev/null +++ b/loanpy/unittests/utils.py @@ -0,0 +1,26 @@ +# 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"))