From a382b77eaa81998d5a413a019701137117b45eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijn=20De=C3=A9?= Date: Mon, 26 Nov 2018 14:30:17 +0100 Subject: [PATCH] Added validation to the models --- plugins/UM3NetworkPrinting/src/Models.py | 14 ++++++++++++++ plugins/UM3NetworkPrinting/src/SendMaterialJob.py | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Models.py b/plugins/UM3NetworkPrinting/src/Models.py index e2ad411e90..d0708c8127 100644 --- a/plugins/UM3NetworkPrinting/src/Models.py +++ b/plugins/UM3NetworkPrinting/src/Models.py @@ -6,6 +6,10 @@ class BaseModel: def __init__(self, **kwargs): self.__dict__.update(kwargs) + self.validate() + + def validate(self): + pass ## Class representing a material that was fetched from the cluster API. @@ -19,6 +23,10 @@ class ClusterMaterial(BaseModel): self.density = None # type: str super().__init__(**kwargs) + def validate(self): + if not self.guid: + raise ValueError("guid is required on ClusterMaterial") + ## Class representing a local material that was fetched from the container registry. class LocalMaterial(BaseModel): @@ -40,3 +48,9 @@ class LocalMaterial(BaseModel): self.definition = None # type: str self.compatible = None # type: bool super().__init__(**kwargs) + + def validate(self): + if not self.GUID: + raise ValueError("guid is required on LocalMaterial") + if not self.id: + raise ValueError("id is required on LocalMaterial") diff --git a/plugins/UM3NetworkPrinting/src/SendMaterialJob.py b/plugins/UM3NetworkPrinting/src/SendMaterialJob.py index 48760af28e..6f33e75ee1 100644 --- a/plugins/UM3NetworkPrinting/src/SendMaterialJob.py +++ b/plugins/UM3NetworkPrinting/src/SendMaterialJob.py @@ -159,8 +159,8 @@ class SendMaterialJob(Job): Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.") except json.JSONDecodeError: Logger.log("e", "Request material storage on printer: I didn't understand the printer's answer.") - except TypeError: - Logger.log("e", "Request material storage on printer: Printer's answer was missing GUIDs.") + except ValueError: + Logger.log("e", "Request material storage on printer: Printer's answer was missing a value.") ## Retrieves a list of local materials #