Debian Codegraph @

examples/package_example.py

raw symbols SCIP
1 # coding: utf-8
2 """
3 This tests the use of a view coming from installed
4 package.
5 """
6
7 from flask import Flask, jsonify
8 from flasgger import Swagger
9 from flasgger_package import package_view
10
11
12 app = Flask(__name__)
13 swag = Swagger(app)
14
15 app.add_url_rule(
16 '/v1/decorated/<username>',
17 view_func=package_view
18 )
19
20
21 @app.route('/v2/decorated/<username>')
22 def package_view_2(username):
23 """
24 This is the summary defined in yaml file
25 First line is the summary
26 All following lines until the hyphens is added to description
27 the format of the first lines until 3 hyphens will be not yaml compliant
28 but everything below the 3 hyphens should be.
29 ---
30 tags:
31 - users
32 import: "flasgger_package/parameters.yml"
33 responses:
34 200:
35 description: A single user item
36 schema:
37 id: rec_username
38 properties:
39 username:
40 type: string
41 description: The name of the user
42 default: 'steve-harris 2'
43 """
44 return jsonify({'username': username})
45
46
47 def test_swag(client, specs_data):
48 """
49 This test is runs automatically in Travis CI
50
51 :param client: Flask app test client
52 :param specs_data: {'url': {swag_specs}} for every spec in app
53 """
54 for url, spec in specs_data.items():
55 assert 'rec_username' in spec['definitions']
56 assert 'users' in spec['paths'][
57 '/v1/decorated/{username}'
58 ]['get']['tags']
59
60 if __name__ == "__main__":
61 app.run(debug=True)