File: package_example.py

package info (click to toggle)
python-flasgger 0.9.5%2Bdfsg.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,152 kB
  • sloc: javascript: 6,403; python: 3,665; makefile: 9; sh: 1
file content (61 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding: utf-8
"""
This tests the use of a view coming from installed
package.
"""

from flask import Flask, jsonify
from flasgger import Swagger
from flasgger_package import package_view


app = Flask(__name__)
swag = Swagger(app)

app.add_url_rule(
    '/v1/decorated/<username>',
    view_func=package_view
)


@app.route('/v2/decorated/<username>')
def package_view_2(username):
    """
    This is the summary defined in yaml file
    First line is the summary
    All following lines until the hyphens is added to description
    the format of the first lines until 3 hyphens will be not yaml compliant
    but everything below the 3 hyphens should be.
    ---
    tags:
      - users
    import: "flasgger_package/parameters.yml"
    responses:
      200:
        description: A single user item
        schema:
          id: rec_username
          properties:
            username:
              type: string
              description: The name of the user
              default: 'steve-harris 2'
    """
    return jsonify({'username': username})


def test_swag(client, specs_data):
    """
    This test is runs automatically in Travis CI

    :param client: Flask app test client
    :param specs_data: {'url': {swag_specs}} for every spec in app
    """
    for url, spec in specs_data.items():
        assert 'rec_username' in spec['definitions']
        assert 'users' in spec['paths'][
            '/v1/decorated/{username}'
        ]['get']['tags']

if __name__ == "__main__":
    app.run(debug=True)