Browse Source

add test for doc generation when input_files + input_body both used on same controller

Bastien Sevajol 6 years ago
parent
commit
303a59a84b
1 changed files with 33 additions and 0 deletions
  1. 33 0
      tests/func/test_doc.py

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

@@ -91,3 +91,36 @@ class TestDocGeneration(Base):
91 91
         assert 'produce' in doc['paths']['/avatar']['get']
92 92
         assert 'image/jpeg' in doc['paths']['/avatar']['get']['produce']
93 93
         assert 200 in doc['paths']['/avatar']['get']['responses']
94
+
95
+    def test_func__input_files_doc__ok__one_file_and_text(self):
96
+        hapic = Hapic()
97
+        hapic.set_context(MyContext())
98
+        app = bottle.Bottle()
99
+
100
+        class MySchema(marshmallow.Schema):
101
+            name = marshmallow.fields.String(required=True)
102
+
103
+        class MyFilesSchema(marshmallow.Schema):
104
+            file_abc = marshmallow.fields.Raw(required=True)
105
+
106
+        @hapic.with_api_doc()
107
+        @hapic.input_files(MyFilesSchema())
108
+        @hapic.input_body(MySchema())
109
+        def my_controller(hapic_data=None):
110
+            assert hapic_data
111
+            assert hapic_data.files
112
+
113
+        app.route('/upload', method='POST', callback=my_controller)
114
+        doc = hapic.generate_doc(app)
115
+
116
+        assert doc
117
+        assert '/upload' in doc['paths']
118
+        assert 'consume' in doc['paths']['/upload']['post']
119
+        assert 'multipart/form-data' in doc['paths']['/upload']['post']['consume']
120
+        assert 'parameters' in doc['paths']['/upload']['post']
121
+        assert {
122
+                   'name': 'file_abc',
123
+                   'required': True,
124
+                   'in': 'formData',
125
+                   'type': 'file',
126
+               } in doc['paths']['/upload']['post']['parameters']