Browse Source

add test to ensure enum working

Bastien Sevajol 6 years ago
parent
commit
5ed744b7d1
1 changed files with 26 additions and 0 deletions
  1. 26 0
      tests/func/test_doc.py

+ 26 - 0
tests/func/test_doc.py View File

@@ -1,6 +1,7 @@
1 1
 # coding: utf-8
2 2
 import marshmallow
3 3
 import bottle
4
+from marshmallow.validate import OneOf
4 5
 
5 6
 from hapic import Hapic
6 7
 from tests.base import Base
@@ -195,3 +196,28 @@ class TestDocGeneration(Base):
195 196
                 '$ref': '#/definitions/DefaultErrorBuilder'
196 197
             }
197 198
         } == doc['paths']['/upload']['post']['responses'][500]
199
+
200
+    def test_func__enum__nominal_case(self):
201
+        hapic = Hapic()
202
+        # TODO BS 20171113: Make this test non-bottle
203
+        app = bottle.Bottle()
204
+        hapic.set_context(MyContext(app=app))
205
+
206
+        class MySchema(marshmallow.Schema):
207
+            category = marshmallow.fields.String(
208
+                validate=OneOf(['foo', 'bar'])
209
+            )
210
+
211
+        @hapic.with_api_doc()
212
+        @hapic.input_body(MySchema())
213
+        def my_controller():
214
+            return
215
+
216
+        app.route('/paper', method='POST', callback=my_controller)
217
+        doc = hapic.generate_doc()
218
+
219
+        assert ['foo', 'bar'] == doc.get('definitions', {})\
220
+            .get('MySchema', {})\
221
+            .get('properties', {})\
222
+            .get('category', {})\
223
+            .get('enum')