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

MAINT: renaming and first int test

parent 8a3a73c4
No related branches found
No related tags found
1 merge request!1Restructure and add integration tests
Showing
with 98 additions and 0 deletions
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Henrik tom Wörden (h.tomwoerden@indiscale.com)
# Copyright (C) 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/>.
"""
basic integration test of the loan workflow
"""
from pytest import fixture
import json
import linkahead as db
import re
from tempfile import NamedTemporaryFile
from linkahead.utils.server_side_scripting import run_server_side_script
from box_loan import (BORROWER, BOX, COMMENT, DESTINATION, EXHAUST_CONTENTS,
EXPECTED_RETURN, F_BOX, F_COMMENT, F_DESTINATION,PERSON,
F_EMAIL, F_EXHAUST_CONTENTS, F_EXPECTED_RETURN_DATE, EMAIL,
F_FIRST_NAME, F_LAST_NAME, FIRST_NAME, LAST_NAME, LOAN, LOCATION,
LOAN_REQUESTED, assert_date_in_future,
assert_key_in_data, get_box, insert_or_update_person, main,
send_loan_request_mail)
TESTLOANCOMMENT = 'This is a test'
TESTBOXNUMBER = '0123 TEST'
TESTDESTINATION = 'TEST DEST'
TESTBORROWEREMAIL = 'test@example.com'
TESTFN = "Alice"
TESTLN = "Wunderland"
def delete_stuff():
to_be_deleted = db.Container()
to_be_deleted.extend(db.execute_query(f"FIND loan with {COMMENT.name}='{TESTLOANCOMMENT}'"))
to_be_deleted.extend(db.execute_query(f"FIND '{TESTDESTINATION}'"))
to_be_deleted.extend(db.execute_query(f"FIND '{TESTBOXNUMBER}'"))
to_be_deleted.extend(db.execute_query(f"FIND person with {EMAIL.name}='{TESTBORROWEREMAIL}'"))
if len(to_be_deleted)>0:
to_be_deleted.delete()
@fixture(autouse=True)
def prepare():
delete_stuff()
db.Record(name=TESTBOXNUMBER).add_parent(BOX.name).insert()
db.Record(name=TESTDESTINATION).add_parent(LOCATION.name).insert()
(db.Record().add_parent(PERSON.name).add_property(EMAIL.name, TESTBORROWEREMAIL)
.add_property(FIRST_NAME.name, TESTFN)
.add_property(LAST_NAME.name, TESTLN).insert())
yield
delete_stuff()
def test_request_loan():
data = {}
data[F_EXHAUST_CONTENTS] = False
data[F_EXPECTED_RETURN_DATE]= "2042-02-02"
data[F_BOX]=db.utils.get_entity.get_entity_by_name(TESTBOXNUMBER).id
data[F_COMMENT]=TESTLOANCOMMENT
data[F_DESTINATION]=db.utils.get_entity.get_entity_by_name(TESTDESTINATION).id
data[F_EMAIL]=TESTBORROWEREMAIL
data[F_LAST_NAME]=TESTLN
data[F_FIRST_NAME]=TESTFN
fi = NamedTemporaryFile(delete=False, suffix=".json")
fi.close()
with open(fi.name, "w") as f:
json.dump(data, f)
response = run_server_side_script("loan_management/request_loan.py",
#"pos0",
#option1="val1",
files={"-p0": fi.name},
**{"auth-token":db.get_connection()._authenticator.auth_token})
assert response.stderr is None
assert response.code == 0
loan = db.execute_query(f"FIND loan with {COMMENT.name}='{TESTLOANCOMMENT}'", unique=True)
assert loan.get_property(f"{BOX.name}").value == data[F_BOX]
assert loan.get_property(f"{LOAN_REQUESTED.name}").value.startswith("20")
assert loan.get_property(f"{BORROWER.name}").value == db.execute_query(
f"FIND {PERSON.name} with {EMAIL.name}='{TESTBORROWEREMAIL}'", unique=True).id
assert loan.get_property(f"{EXPECTED_RETURN.name}").value == data[F_EXPECTED_RETURN_DATE]
assert loan.get_property(f"{EXHAUST_CONTENTS.name}").value == data[F_EXHAUST_CONTENTS]
assert loan.get_property(f"{DESTINATION.name}").value == data[F_DESTINATION]
../loan-custom/caosdb-server/scripting/bin/loan_management/box_loan.py
\ No newline at end of file
../loan-custom/caosdb-server/scripting/bin/loan_management/conf.py
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment