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
     controllers.bind(app)
107
     controllers.bind(app)
108
     hapic.set_context(BottleContext(app))
108
     hapic.set_context(BottleContext(app))
109
     time.sleep(1)
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
     time.sleep(1)
116
     time.sleep(1)
112
     # print swagger doc
117
     # print swagger doc
113
     print(s)
118
     print(s)

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

115
     controllers.bind(app)
115
     controllers.bind(app)
116
     hapic.set_context(FlaskContext(app))
116
     hapic.set_context(FlaskContext(app))
117
     time.sleep(1)
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
     time.sleep(1)
124
     time.sleep(1)
120
     # print swagger doc
125
     # print swagger doc
121
     print(s)
126
     print(s)

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

118
     controllers.bind(configurator)
118
     controllers.bind(configurator)
119
     hapic.set_context(PyramidContext(configurator))
119
     hapic.set_context(PyramidContext(configurator))
120
     time.sleep(1)
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
     time.sleep(1)
127
     time.sleep(1)
123
     # print swagger doc
128
     # print swagger doc
124
     print(s)
129
     print(s)

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

1
 from collections import OrderedDict
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
 
14
 
15
     hapic.set_context(BottleContext(bottle_app))
15
     hapic.set_context(BottleContext(bottle_app))
16
     app = TestApp(bottle_app)
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
     assert doc == SWAGGER_DOC_API
22
     assert doc == SWAGGER_DOC_API
20
     resp = app.get('/about')
23
     resp = app.get('/about')

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

12
     controllers.bind(flask_app)
12
     controllers.bind(flask_app)
13
     hapic.set_context(FlaskContext(flask_app))
13
     hapic.set_context(FlaskContext(flask_app))
14
     app = TestApp(flask_app)
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
     assert doc == SWAGGER_DOC_API
20
     assert doc == SWAGGER_DOC_API
18
     resp = app.get('/about')
21
     resp = app.get('/about')

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

13
     controllers.bind(configurator)
13
     controllers.bind(configurator)
14
     hapic.set_context(PyramidContext(configurator))
14
     hapic.set_context(PyramidContext(configurator))
15
     app = TestApp(configurator.make_wsgi_app())
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
     assert doc == SWAGGER_DOC_API
21
     assert doc == SWAGGER_DOC_API
19
     resp = app.get('/about')
22
     resp = app.get('/about')