Skip to content
Snippets Groups Projects
Commit 47a17f3b authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

TST: Mock get_entity_by_name in unit test

parent 7f0fec7c
No related branches found
No related tags found
No related merge requests found
from linkahead import Record
from linkahead import Record, Property
from unittest.mock import Mock, patch
from loan.box_loan import BOX, BOX_RETURNED, BOX_BORROWED
from loan.manual_return import _set_returned_box
from loan.manual_return import _set_returned_box, db
def mock_get_entity_by_name(name, role):
if name == BOX_RETURNED.name and role == "PROPERTY":
return Property(name=BOX_RETURNED.name, id=12345)
raise ValueError(f"Mock not defined for {name} with role {role}.")
@patch("loan.manual_return.db.get_entity_by_name", new=Mock(side_effect=mock_get_entity_by_name))
def test_set_returned_box():
loan = Record()
loan.add_property(BOX, name=BOX_BORROWED.name, value="1234@abcd")
......@@ -15,4 +24,5 @@ def test_set_returned_box():
assert len(loan.get_properties()) == 2
assert loan.get_property(BOX_BORROWED.name).value == "1234@abcd"
assert loan.get_property(BOX_RETURNED.name).value == "1234@HEAD"
print(loan)
assert loan.get_property(12345).value == "1234@HEAD"
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