summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-27 11:05:23 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-27 11:05:23 +0800
commit2a5870f529b5defe9154834c252b0d30cccc9c8d (patch)
tree76e12bea1e4c4b103316a9f3298af7b726bc9b58
parenta8d260a0ef20e92f5ddf8bcb945cdbd0de6c501a (diff)
Database.update includes message in exceptions
-rw-r--r--jimbrella/database.py17
1 files changed, 10 insertions, 7 deletions
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 #<serial> 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