فهرست منبع

Add tests for protocol errors

Signed-off-by: Stan Janssen <stan.janssen@elaad.nl>
Stan Janssen 4 سال پیش
والد
کامیت
0f8c363be6
3فایلهای تغییر یافته به همراه24 افزوده شده و 13 حذف شده
  1. 1 1
      openleadr/enums.py
  2. 12 12
      openleadr/errors.py
  3. 11 0
      test/test_errors.py

+ 1 - 1
openleadr/enums.py

@@ -167,7 +167,7 @@ class STATUS_CODES(metaclass=Enum):
     REPORT_NOT_SUPPORTED = 461
     TARGET_MISMATCH = 462
     NOT_REGISTERED_OR_AUTHORIZED = 463
-    DEPLOYMENT_ERROR_OTHER = 469
+    DEPLOYMENT_ERROR_OR_OTHER_ERROR = 469
 
 
 class SECURITY_LEVEL:

+ 12 - 12
openleadr/errors.py

@@ -17,77 +17,77 @@ class HTTPError(Exception):
 
 
 class OutOfSequenceError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='OUT OF SEQUENCE'):
         super().__init__()
         self.response_code = STATUS_CODES.OUT_OF_SEQUENCE
         self.response_description = description
 
 
 class NotAllowedError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='NOT ALLOWED'):
         super().__init__()
         self.response_code = STATUS_CODES.NOT_ALLOWED
         self.response_description = description
 
 
 class InvalidIdError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='INVALID ID'):
         super().__init__()
         self.response_code = STATUS_CODES.INVALID_ID
         self.response_description = description
 
 
 class NotRecognizedError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='NOT RECOGNIZED'):
         super().__init__()
         self.response_code = STATUS_CODES.NOT_RECOGNIZED
         self.response_description = description
 
 
 class InvalidDataError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='INVALID DATA'):
         super().__init__()
         self.response_code = STATUS_CODES.INVALID_DATA
         self.response_description = description
 
 
 class ComplianceError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='COMPLIANCE ERROR'):
         super().__init__()
         self.response_code = STATUS_CODES.COMPLIANCE_ERROR
         self.response_description = description
 
 
 class SignalNotSupportedError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='SIGNAL NOT SUPPORTED'):
         super().__init__()
         self.response_code = STATUS_CODES.SIGNAL_NOT_SUPPORTED
         self.response_description = description
 
 
 class ReportNotSupportedError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='REPORT NOT SUPPORTED'):
         super().__init__()
         self.response_code = STATUS_CODES.REPORT_NOT_SUPPORTED
         self.response_description = description
 
 
 class TargetMismatchError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='TARGET MISMATCH'):
         super().__init__()
         self.response_code = STATUS_CODES.TARGET_MISMATCH
         self.response_description = description
 
 
 class NotRegisteredOrAuthorizedError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='NOT REGISTERED OR AUTHORIZED'):
         super().__init__()
         self.response_code = STATUS_CODES.NOT_REGISTERED_OR_AUTHORIZED
         self.response_description = description
 
 
 class DeploymentError(ProtocolError):
-    def __init__(self, description=None):
+    def __init__(self, description='DEPLOYMENT ERROR OR OTHER ERROR'):
         super().__init__()
-        self.response_code = STATUS_CODES.DEPLOYMENT_ERROR_OTHER
+        self.response_code = STATUS_CODES.DEPLOYMENT_ERROR_OR_OTHER_ERROR
         self.response_description = description

+ 11 - 0
test/test_errors.py

@@ -0,0 +1,11 @@
+from openleadr import errors, enums
+
+def test_protocol_errors():
+    for error in dir(errors):
+        if isinstance(getattr(errors, error), type):
+            err = getattr(errors, error)()
+            if isinstance(err, errors.ProtocolError) and not type(err) == errors.ProtocolError:
+                err_description = err.response_description
+                err_code = err.response_code
+                err_enum = err_description.replace(" ", "_")
+                assert enums.STATUS_CODES[err_enum] == err_code