Browse Source

fix tests and add coverall details

Bastien Sevajol 7 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

@@ -0,0 +1,2 @@
1
+service_name: travis-pro
2
+repo_token: FipUGbTT4XLGpZMktE2U0aa9CqX27vYMQ

+ 2 - 1
.gitignore View File

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

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

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

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

@@ -10,6 +10,7 @@ from hapic.decorator import InputOutputControllerWrapper
10 10
 from hapic.decorator import ExceptionHandlerControllerWrapper
11 11
 from hapic.decorator import InputControllerWrapper
12 12
 from hapic.decorator import OutputControllerWrapper
13
+from hapic.hapic import ErrorResponseSchema
13 14
 from hapic.processor import RequestParameters
14 15
 from hapic.processor import MarshmallowOutputProcessor
15 16
 from hapic.processor import ProcessValidationError
@@ -207,6 +208,7 @@ class TestExceptionHandlerControllerWrapper(Base):
207 208
         wrapper = ExceptionHandlerControllerWrapper(
208 209
             ZeroDivisionError,
209 210
             context,
211
+            schema=ErrorResponseSchema(),
210 212
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
211 213
         )
212 214
 
@@ -219,7 +221,9 @@ class TestExceptionHandlerControllerWrapper(Base):
219 221
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
220 222
         assert 'original_response' in response
221 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 229
     def test_unit__exception_handled__ok__exception_error_dict(self):
@@ -232,13 +236,14 @@ class TestExceptionHandlerControllerWrapper(Base):
232 236
         wrapper = ExceptionHandlerControllerWrapper(
233 237
             MyException,
234 238
             context,
239
+            schema=ErrorResponseSchema(),
235 240
             http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
236 241
         )
237 242
 
238 243
         @wrapper.get_wrapper
239 244
         def func(foo):
240 245
             exc = MyException('We are testing')
241
-            exc.error_dict = {'foo': 'bar'}
246
+            exc.error_detail = {'foo': 'bar'}
242 247
             raise exc
243 248
 
244 249
         response = func(42)
@@ -246,6 +251,7 @@ class TestExceptionHandlerControllerWrapper(Base):
246 251
         assert response['http_code'] == HTTPStatus.INTERNAL_SERVER_ERROR
247 252
         assert 'original_response' in response
248 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
         }