Browse Source

fix tests and add coverall details

Bastien Sevajol 6 years ago
parent
commit
cd0fc20389
4 changed files with 17 additions and 8 deletions
  1. 2 0
      .coveralls.yml
  2. 2 1
      .gitignore
  3. 3 3
      tests/ext/unit/test_bottle.py
  4. 10 4
      tests/unit/test_decorator.py

+ 2 - 0
.coveralls.yml View File

1
+service_name: travis-pro
2
+repo_token: FipUGbTT4XLGpZMktE2U0aa9CqX27vYMQ

+ 2 - 1
.gitignore View File

4
 *~
4
 *~
5
 /venv
5
 /venv
6
 .cache
6
 .cache
7
-*.egg-info
7
+*.egg-info
8
+.coverage

+ 3 - 3
tests/ext/unit/test_bottle.py View File

9
 class TestBottleExt(Base):
9
 class TestBottleExt(Base):
10
     def test_unit__map_binding__ok__decorated_function(self):
10
     def test_unit__map_binding__ok__decorated_function(self):
11
         hapic_ = hapic.Hapic()
11
         hapic_ = hapic.Hapic()
12
-        hapic_.set_context(hapic.ext.bottle.bottle_context)
12
+        hapic_.set_context(hapic.ext.bottle.BottleContext())
13
 
13
 
14
         app = bottle.Bottle()
14
         app = bottle.Bottle()
15
 
15
 
29
 
29
 
30
     def test_unit__map_binding__ok__mapped_function(self):
30
     def test_unit__map_binding__ok__mapped_function(self):
31
         hapic_ = hapic.Hapic()
31
         hapic_ = hapic.Hapic()
32
-        hapic_.set_context(hapic.ext.bottle.bottle_context)
32
+        hapic_.set_context(hapic.ext.bottle.BottleContext())
33
 
33
 
34
         app = bottle.Bottle()
34
         app = bottle.Bottle()
35
 
35
 
50
 
50
 
51
     def test_unit__map_binding__ok__mapped_method(self):
51
     def test_unit__map_binding__ok__mapped_method(self):
52
         hapic_ = hapic.Hapic()
52
         hapic_ = hapic.Hapic()
53
-        hapic_.set_context(hapic.ext.bottle.bottle_context)
53
+        hapic_.set_context(hapic.ext.bottle.BottleContext())
54
 
54
 
55
         app = bottle.Bottle()
55
         app = bottle.Bottle()
56
 
56
 

+ 10 - 4
tests/unit/test_decorator.py View File

10
 from hapic.decorator import ExceptionHandlerControllerWrapper
10
 from hapic.decorator import ExceptionHandlerControllerWrapper
11
 from hapic.decorator import InputControllerWrapper
11
 from hapic.decorator import InputControllerWrapper
12
 from hapic.decorator import OutputControllerWrapper
12
 from hapic.decorator import OutputControllerWrapper
13
+from hapic.hapic import ErrorResponseSchema
13
 from hapic.processor import RequestParameters
14
 from hapic.processor import RequestParameters
14
 from hapic.processor import MarshmallowOutputProcessor
15
 from hapic.processor import MarshmallowOutputProcessor
15
 from hapic.processor import ProcessValidationError
16
 from hapic.processor import ProcessValidationError
207
         wrapper = ExceptionHandlerControllerWrapper(
208
         wrapper = ExceptionHandlerControllerWrapper(
208
             ZeroDivisionError,
209
             ZeroDivisionError,
209
             context,
210
             context,
211
+            schema=ErrorResponseSchema(),
210
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
212
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
211
         )
213
         )
212
 
214
 
219
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
221
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
220
         assert 'original_response' in response
222
         assert 'original_response' in response
221
         assert response['original_response'] == {
223
         assert response['original_response'] == {
222
-            'error_message': 'We are testing',
224
+            'message': 'We are testing',
225
+            'code': None,
226
+            'detail': {},
223
         }
227
         }
224
 
228
 
225
     def test_unit__exception_handled__ok__exception_error_dict(self):
229
     def test_unit__exception_handled__ok__exception_error_dict(self):
232
         wrapper = ExceptionHandlerControllerWrapper(
236
         wrapper = ExceptionHandlerControllerWrapper(
233
             MyException,
237
             MyException,
234
             context,
238
             context,
239
+            schema=ErrorResponseSchema(),
235
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
240
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
236
         )
241
         )
237
 
242
 
238
         @wrapper.get_wrapper
243
         @wrapper.get_wrapper
239
         def func(foo):
244
         def func(foo):
240
             exc = MyException('We are testing')
245
             exc = MyException('We are testing')
241
-            exc.error_dict = {'foo': 'bar'}
246
+            exc.error_detail = {'foo': 'bar'}
242
             raise exc
247
             raise exc
243
 
248
 
244
         response = func(42)
249
         response = func(42)
246
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
251
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
247
         assert 'original_response' in response
252
         assert 'original_response' in response
248
         assert response['original_response'] == {
253
         assert response['original_response'] == {
249
-            'error_message': 'We are testing',
250
-            'foo': 'bar',
254
+            'message': 'We are testing',
255
+            'code': None,
256
+            'detail': {'foo': 'bar'},
251
         }
257
         }