From 2a5870f529b5defe9154834c252b0d30cccc9c8d Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 27 Oct 2021 11:05:23 +0800 Subject: Database.update includes message in exceptions --- jimbrella/database.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'jimbrella/database.py') diff --git a/jimbrella/database.py b/jimbrella/database.py index fd8f35c..ab945da 100644 --- a/jimbrella/database.py +++ b/jimbrella/database.py @@ -184,7 +184,7 @@ class Database: """ # `serial` must be specified. if "serial" not in umb: - raise UmbrellaValueError + raise UmbrellaValueError("serial") # check if umbrella # exists in database umb["serial"] = int(umb["serial"]) @@ -193,24 +193,24 @@ class Database: raise UmbrellaNotFoundError status = umb_in_db["status"] - if "status" in umb: + if "status" in umb and umb["status"]: if status not in STATUSES: - raise UmbrellaValueError # invalid + raise UmbrellaValueError("status") # invalid # admin specifies a (perhaps different) status status = umb["status"] - if "lent_at" in umb: - # check if `umb` has valid date (`lent_at`) + if "lent_at" in umb and umb["lent_at"]: + # check if `umb` has valid date (`lent_at`) if any if isinstance(umb["lent_at"], datetime): lent_at = umb["lent_at"] elif isinstance(umb["lent_at"], str): try: umb["lent_at"] = datetime.fromisoformat(umb["lent_at"]) except ValueError: - raise UmbrellaValueError + raise UmbrellaValueError("lent_at") else: - raise UmbrellaValueError + raise UmbrellaValueError("lent_at") # we will now check the validity of `umb` based on `status` if status == "available": @@ -229,6 +229,9 @@ class Database: ]: umb[key] = umb[key] if (key in umb and umb[key]) else umb_in_db[key] + if not umb["lent_at"]: + raise UmbrellaValueError("lent_at") + return self._update(umb) @staticmethod -- cgit v1.2.3