Browse Source

fix default error format

Bastien Sevajol 6 years ago
parent
commit
1a1bc47ec9
5 changed files with 16 additions and 16 deletions
  1. 2 2
      example.py
  2. 8 8
      hapic/processor.py
  3. 1 1
      setup.py
  4. 3 3
      tests/unit/test_decorator.py
  5. 2 2
      tests/unit/test_processor.py

+ 2 - 2
example.py View File

@@ -3,8 +3,8 @@ import marshmallow
3 3
 
4 4
 
5 5
 class ErrorResponseSchema(marshmallow.Schema):
6
-    error_message = marshmallow.fields.String(required=True)
7
-    error_details = marshmallow.fields.Dict(required=True)
6
+    message = marshmallow.fields.String(required=True)
7
+    details = marshmallow.fields.Dict(required=True)
8 8
 
9 9
 
10 10
 class HelloResponseSchema(marshmallow.Schema):

+ 8 - 8
hapic/processor.py View File

@@ -23,11 +23,11 @@ class RequestParameters(object):
23 23
 class ProcessValidationError(object):
24 24
     def __init__(
25 25
         self,
26
-        error_message: str,
27
-        error_details: dict,
26
+        message: str,
27
+        details: dict,
28 28
     ) -> None:
29
-        self.error_message = error_message
30
-        self.error_details = error_details
29
+        self.message = message
30
+        self.details = details
31 31
 
32 32
 
33 33
 class ProcessorInterface(object):
@@ -71,8 +71,8 @@ class MarshmallowOutputProcessor(OutputProcessor):
71 71
         data = self.schema.dump(data).data
72 72
         errors = self.schema.load(data).errors
73 73
         return ProcessValidationError(
74
-            error_message='Validation error of output data',
75
-            error_details=errors,
74
+            message='Validation error of output data',
75
+            details=errors,
76 76
         )
77 77
 
78 78
 
@@ -91,7 +91,7 @@ class MarshmallowInputProcessor(InputProcessor):
91 91
     def get_validation_error(self, data: dict) -> ProcessValidationError:
92 92
         marshmallow_errors = self.schema.load(data).errors
93 93
         return ProcessValidationError(
94
-            error_message='Validation error of input data',
95
-            error_details=marshmallow_errors,
94
+            message='Validation error of input data',
95
+            details=marshmallow_errors,
96 96
         )
97 97
 

+ 1 - 1
setup.py View File

@@ -23,7 +23,7 @@ setup(
23 23
     # Versions should comply with PEP440.  For a discussion on single-sourcing
24 24
     # the version across setup.py and the project code, see
25 25
     # https://packaging.python.org/en/latest/single_source_version.html
26
-    version='0.0.4',
26
+    version='0.0.4.1',
27 27
 
28 28
     description='HTTP api input/output manager',
29 29
     # long_description=long_description,

+ 3 - 3
tests/unit/test_decorator.py View File

@@ -58,10 +58,10 @@ class MyProcessor(ProcessorInterface):
58 58
         request_context: RequestParameters,
59 59
     ) -> ProcessValidationError:
60 60
         return ProcessValidationError(
61
-            error_details={
61
+            details={
62 62
                 'original_request_context': request_context,
63 63
             },
64
-            error_message='ERROR',
64
+            message='ERROR',
65 65
         )
66 66
 
67 67
 
@@ -197,7 +197,7 @@ class TestOutputControllerWrapper(Base):
197 197
         assert 'http_code' in result
198 198
         assert result['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
199 199
         assert 'original_error' in result
200
-        assert result['original_error'].error_details == {
200
+        assert result['original_error'].details == {
201 201
             'name': ['Missing data for required field.']
202 202
         }
203 203
 

+ 2 - 2
tests/unit/test_processor.py View File

@@ -61,8 +61,8 @@ class TestProcessor(Base):
61 61
             processor.process(tested_data)
62 62
 
63 63
         errors = processor.get_validation_error(tested_data)
64
-        assert errors.error_details
65
-        assert 'first_name' in errors.error_details
64
+        assert errors.details
65
+        assert 'first_name' in errors.details
66 66
 
67 67
     def test_unit__marshmallow_input_processor__ok__completed_data(self):
68 68
         processor = MarshmallowInputProcessor()