Browse Source

fix fake_api functional test with title and description

Guénaël Muller 6 years ago
parent
commit
cd515e4b93

+ 6 - 1
example/fake_api/bottle_api.py View File

@@ -107,7 +107,12 @@ if __name__ == "__main__":
107 107
     controllers.bind(app)
108 108
     hapic.set_context(BottleContext(app))
109 109
     time.sleep(1)
110
-    s = json.dumps(hapic.generate_doc())
110
+    s = json.dumps(
111
+        hapic.generate_doc(
112
+            title='Fake API',
113
+            description='just an example of hapic API'
114
+        )
115
+    )
111 116
     time.sleep(1)
112 117
     # print swagger doc
113 118
     print(s)

+ 6 - 1
example/fake_api/flask_api.py View File

@@ -115,7 +115,12 @@ if __name__ == "__main__":
115 115
     controllers.bind(app)
116 116
     hapic.set_context(FlaskContext(app))
117 117
     time.sleep(1)
118
-    s = json.dumps(hapic.generate_doc())
118
+    s = json.dumps(
119
+        hapic.generate_doc(
120
+            title='Fake API',
121
+            description='just an example of hapic API'
122
+        )
123
+    )
119 124
     time.sleep(1)
120 125
     # print swagger doc
121 126
     print(s)

+ 6 - 1
example/fake_api/pyramid_api.py View File

@@ -118,7 +118,12 @@ if __name__ == "__main__":
118 118
     controllers.bind(configurator)
119 119
     hapic.set_context(PyramidContext(configurator))
120 120
     time.sleep(1)
121
-    s = json.dumps(hapic.generate_doc())
121
+    s = json.dumps(
122
+        hapic.generate_doc(
123
+            title='Fake API',
124
+            description='just an example of hapic API'
125
+        )
126
+    )
122 127
     time.sleep(1)
123 128
     # print swagger doc
124 129
     print(s)

+ 1 - 1
tests/func/fake_api/common.py View File

@@ -1,2 +1,2 @@
1 1
 from collections import OrderedDict
2
-SWAGGER_DOC_API = {'paths': OrderedDict([('/about', {'get': {'description': 'General information about this API.', 'responses': {200: {'schema': {'$ref': '#/definitions/AboutResponseSchema'}, 'description': 'HTTPStatus.OK'}}}}), ('/users', {'get': {'description': 'Obtain users list.', 'responses': {200: {'schema': {'$ref': '#/definitions/ListsUserSchema'}, 'description': 'HTTPStatus.OK'}}}}), ('/users/{id}', {'get': {'description': 'Obtain one user', 'responses': {200: {'schema': {'$ref': '#/definitions/UserSchema'}, 'description': 'HTTPStatus.OK'}}, 'parameters': [{'in': 'path', 'name': 'id', 'required': True, 'type': 'integer'}]}, 'delete': {'description': 'delete user', 'responses': {204: {'schema': {'$ref': '#/definitions/NoContentSchema'}, 'description': '204'}}, 'parameters': [{'in': 'path', 'name': 'id', 'required': True, 'type': 'integer'}]}}), ('/users/', {'post': {'description': 'Add new user', 'responses': {200: {'schema': {'$ref': '#/definitions/UserSchema'}, 'description': 'HTTPStatus.OK'}}, 'parameters': [{'in': 'body', 'name': 'body', 'schema': {'$ref': '#/definitions/UserSchema'}}]}})]), 'definitions': {'ListsUserSchema': {'properties': {'pagination': {'$ref': '#/definitions/PaginationSchema'}, 'items': {'type': 'array', 'items': {'$ref': '#/definitions/UserSchema'}}, 'item_nb': {'minimum': 0, 'type': 'integer', 'format': 'int32'}}, 'type': 'object', 'required': ['item_nb']}, 'AboutResponseSchema': {'properties': {'version': {'type': 'string'}, 'datetime': {'type': 'string', 'format': 'date-time'}}, 'type': 'object', 'required': ['datetime', 'version']}, 'NoContentSchema': {'properties': {}, 'type': 'object'}, 'UserSchema': {'properties': {'display_name': {'type': 'string'}, 'first_name': {'type': 'string'}, 'id': {'type': 'integer', 'format': 'int32'}, 'last_name': {'type': 'string'}, 'company': {'type': 'string'}, 'username': {'type': 'string'}, 'email_address': {'type': 'string', 'format': 'email'}}, 'type': 'object', 'required': ['company', 'display_name', 'email_address', 'first_name', 'id', 'last_name', 'username']}, 'PaginationSchema': {'properties': {'last_id': {'type': 'integer', 'format': 'int32'}, 'current_id': {'type': 'integer', 'format': 'int32'}, 'first_id': {'type': 'integer', 'format': 'int32'}}, 'type': 'object', 'required': ['current_id', 'first_id', 'last_id']}}, 'info': {'title': 'Swagger Petstore', 'version': '1.0.0'}, 'tags': [], 'swagger': '2.0', 'parameters': {}}
2
+SWAGGER_DOC_API = {'paths': OrderedDict([('/about', {'get': {'description': 'General information about this API.', 'responses': {200: {'schema': {'$ref': '#/definitions/AboutResponseSchema'}, 'description': 'HTTPStatus.OK'}}}}), ('/users', {'get': {'description': 'Obtain users list.', 'responses': {200: {'schema': {'$ref': '#/definitions/ListsUserSchema'}, 'description': 'HTTPStatus.OK'}}}}), ('/users/{id}', {'get': {'description': 'Obtain one user', 'responses': {200: {'schema': {'$ref': '#/definitions/UserSchema'}, 'description': 'HTTPStatus.OK'}}, 'parameters': [{'in': 'path', 'name': 'id', 'required': True, 'type': 'integer'}]}, 'delete': {'description': 'delete user', 'responses': {204: {'schema': {'$ref': '#/definitions/NoContentSchema'}, 'description': '204'}}, 'parameters': [{'in': 'path', 'name': 'id', 'required': True, 'type': 'integer'}]}}), ('/users/', {'post': {'description': 'Add new user', 'responses': {200: {'schema': {'$ref': '#/definitions/UserSchema'}, 'description': 'HTTPStatus.OK'}}, 'parameters': [{'in': 'body', 'name': 'body', 'schema': {'$ref': '#/definitions/UserSchema'}}]}})]), 'definitions': {'ListsUserSchema': {'properties': {'pagination': {'$ref': '#/definitions/PaginationSchema'}, 'items': {'type': 'array', 'items': {'$ref': '#/definitions/UserSchema'}}, 'item_nb': {'minimum': 0, 'type': 'integer', 'format': 'int32'}}, 'type': 'object', 'required': ['item_nb']}, 'AboutResponseSchema': {'properties': {'version': {'type': 'string'}, 'datetime': {'type': 'string', 'format': 'date-time'}}, 'type': 'object', 'required': ['datetime', 'version']}, 'NoContentSchema': {'properties': {}, 'type': 'object'}, 'UserSchema': {'properties': {'display_name': {'type': 'string'}, 'first_name': {'type': 'string'}, 'id': {'type': 'integer', 'format': 'int32'}, 'last_name': {'type': 'string'}, 'company': {'type': 'string'}, 'username': {'type': 'string'}, 'email_address': {'type': 'string', 'format': 'email'}}, 'type': 'object', 'required': ['company', 'display_name', 'email_address', 'first_name', 'id', 'last_name', 'username']}, 'PaginationSchema': {'properties': {'last_id': {'type': 'integer', 'format': 'int32'}, 'current_id': {'type': 'integer', 'format': 'int32'}, 'first_id': {'type': 'integer', 'format': 'int32'}}, 'type': 'object', 'required': ['current_id', 'first_id', 'last_id']}}, 'info': {'title': 'Fake API','description':'just an example of hapic API','version': '1.0.0'}, 'tags': [], 'swagger': '2.0', 'parameters': {}}

+ 4 - 1
tests/func/fake_api/test_bottle.py View File

@@ -14,7 +14,10 @@ def test_func_bottle_fake_api():
14 14
 
15 15
     hapic.set_context(BottleContext(bottle_app))
16 16
     app = TestApp(bottle_app)
17
-    doc = hapic.generate_doc()
17
+    doc = hapic.generate_doc(
18
+        title='Fake API',
19
+        description='just an example of hapic API'
20
+    )
18 21
 
19 22
     assert doc == SWAGGER_DOC_API
20 23
     resp = app.get('/about')

+ 4 - 1
tests/func/fake_api/test_flask.py View File

@@ -12,7 +12,10 @@ def test_func_flask_fake_api():
12 12
     controllers.bind(flask_app)
13 13
     hapic.set_context(FlaskContext(flask_app))
14 14
     app = TestApp(flask_app)
15
-    doc = hapic.generate_doc()
15
+    doc =  hapic.generate_doc(
16
+        title='Fake API',
17
+        description='just an example of hapic API'
18
+    )
16 19
 
17 20
     assert doc == SWAGGER_DOC_API
18 21
     resp = app.get('/about')

+ 4 - 1
tests/func/fake_api/test_pyramid.py View File

@@ -13,7 +13,10 @@ def test_func_pyramid_fake_api_doc():
13 13
     controllers.bind(configurator)
14 14
     hapic.set_context(PyramidContext(configurator))
15 15
     app = TestApp(configurator.make_wsgi_app())
16
-    doc = hapic.generate_doc()
16
+    doc = hapic.generate_doc(
17
+        title='Fake API',
18
+        description='just an example of hapic API'
19
+    )
17 20
 
18 21
     assert doc == SWAGGER_DOC_API
19 22
     resp = app.get('/about')