Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit dc73c15

Browse files
committed
format files
1 parent 6169155 commit dc73c15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1462
-1542
lines changed

ci/scripts/increment_version.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import os
22

33
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
4-
EXISTING_VERSION_DEF_LOCATION = os.path.join(REPO_ROOT, 'src/flask_openapi/__init__.py')
4+
EXISTING_VERSION_DEF_LOCATION = os.path.join(REPO_ROOT, "src/flask_openapi/__init__.py")
55

66

77
def main() -> None:
8-
read_file = ''
8+
read_file = ""
99

10-
with open(EXISTING_VERSION_DEF_LOCATION, 'r') as file:
10+
with open(EXISTING_VERSION_DEF_LOCATION, "r") as file:
1111
for line in file.readlines():
12-
if '__version__' in line:
12+
if "__version__" in line:
1313
read_file = line
1414

1515
version = read_file.split("= '")[1]
16-
parts = version.split('.')
16+
parts = version.split(".")
1717

1818
major = int(parts[0])
1919
minor = int(parts[1])
2020
patch = int(parts[2].split("'")[0])
2121

2222
minor = minor + 1
2323

24-
print(f'{major}.{minor}.{patch}')
24+
print(f"{major}.{minor}.{patch}")
2525

2626

27-
if __name__ == '__main__':
27+
if __name__ == "__main__":
2828
main()

ci/tests/conftest.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from flask_openapi.utils import is_python_file, remove_suffix
1010

1111
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
12-
TEST_SUITE = os.path.join(REPO_ROOT, 'ci/tests/suite')
12+
TEST_SUITE = os.path.join(REPO_ROOT, "ci/tests/suite")
1313

1414

1515
def get_specs_data(mod):
@@ -21,31 +21,31 @@ def get_specs_data(mod):
2121
# init swag if not yet inititalized (no-routes example)
2222
specs_route = None
2323
specs_data = {}
24-
if getattr(mod.app, 'swag', None) is None:
24+
if getattr(mod.app, "swag", None) is None:
2525
_swag = Swagger()
26-
_swag.config['endpoint'] = str(random.randint(1, 5000))
26+
_swag.config["endpoint"] = str(random.randint(1, 5000))
2727
_swag.init_app(mod.app)
2828
# get all the specs defined for the example app
2929
else:
3030
try:
3131
flasgger_config = mod.swag.config
3232

33-
if flasgger_config.get('swagger_ui') is False:
33+
if flasgger_config.get("swagger_ui") is False:
3434
return specs_data
3535

36-
specs_route = flasgger_config.get('specs_route', '/apidocs/')
36+
specs_route = flasgger_config.get("specs_route", "/apidocs/")
3737
except AttributeError:
3838
pass
3939

4040
if specs_route is None:
41-
specs_route = '/apidocs/'
41+
specs_route = "/apidocs/"
4242

43-
apidocs = client.get('?'.join((specs_route, 'json=true')))
44-
specs = json.loads(apidocs.data.decode("utf-8")).get('specs')
43+
apidocs = client.get("?".join((specs_route, "json=true")))
44+
specs = json.loads(apidocs.data.decode("utf-8")).get("specs")
4545

4646
for spec in specs:
4747
# for each spec get the spec url
48-
url = spec['url']
48+
url = spec["url"]
4949
response = client.get(url)
5050
decoded = response.data.decode("utf-8")
5151
print(mod)
@@ -65,11 +65,8 @@ def get_examples(examples_dir=TEST_SUITE): # pragma: no cover
6565
all_files = os.listdir(examples_dir)
6666
python_files = [f for f in all_files if is_python_file(f)]
6767
basenames = [remove_suffix(f) for f in python_files]
68-
modules = [import_module(f'suite.{module}') for module in basenames]
69-
return [
70-
module for module in modules
71-
if getattr(module, 'app', None) is not None
72-
]
68+
modules = [import_module(f"suite.{module}") for module in basenames]
69+
return [module for module in modules if getattr(module, "app", None) is not None]
7370

7471

7572
def get_test_metadata(mod):
@@ -82,10 +79,12 @@ def get_test_metadata(mod):
8279
Example: '_TEST_META_SKIP_FULL_VALIDATION' -> 'skip_full_validation'
8380
"""
8481

85-
test_metadata_prefix = '_TEST_META_'
86-
return {key[len(test_metadata_prefix):].lower(): getattr(mod, key)
87-
for key in mod.__dict__
88-
if key.startswith(test_metadata_prefix)}
82+
test_metadata_prefix = "_TEST_META_"
83+
return {
84+
key[len(test_metadata_prefix) :].lower(): getattr(mod, key)
85+
for key in mod.__dict__
86+
if key.startswith(test_metadata_prefix)
87+
}
8988

9089

9190
def pytest_generate_tests(metafunc):
@@ -94,18 +93,13 @@ def pytest_generate_tests(metafunc):
9493
to generate one test for each examples/
9594
"""
9695

97-
if 'test_data' in metafunc.fixturenames:
96+
if "test_data" in metafunc.fixturenames:
9897
test_data = [
99-
(mod, mod.app.test_client(),
100-
get_specs_data(mod), get_test_metadata(mod))
98+
(mod, mod.app.test_client(), get_specs_data(mod), get_test_metadata(mod))
10199
for mod in get_examples()
102100
]
103101

104-
metafunc.parametrize(
105-
'test_data',
106-
test_data,
107-
ids=lambda x: x[0].__name__
108-
)
102+
metafunc.parametrize("test_data", test_data, ids=lambda x: x[0].__name__)
109103

110104

111105
@pytest.fixture(scope="function")

ci/tests/suite/test_base_model_view.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ModelAPIView(BaseAPIView):
1616

1717

1818
class PostAPIView(ModelAPIView):
19-
2019
def get(self, team_id):
2120
"""
2221
Get a list of users
@@ -57,7 +56,7 @@ def get(self, team_id):
5756
"users": [
5857
{"name": "Steven Wilson", "team": team_id},
5958
{"name": "Mikael Akerfeldt", "team": team_id},
60-
{"name": "Daniel Gildenlow", "team": team_id}
59+
{"name": "Daniel Gildenlow", "team": team_id},
6160
]
6261
}
6362
return jsonify(data)
@@ -67,9 +66,7 @@ def get(self, team_id):
6766
swag = Swagger(app)
6867

6968
app.add_url_rule(
70-
'/user/<team_id>',
71-
view_func=PostAPIView.as_view('user'),
72-
methods=['GET']
69+
"/user/<team_id>", view_func=PostAPIView.as_view("user"), methods=["GET"]
7370
)
7471

7572
if __name__ == "__main__":

ci/tests/suite/test_basic_auth.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from flask_openapi import Swagger
1717

18+
1819
def requires_basic_auth(f):
1920
"""Decorator to require HTTP Basic Auth for your endpoint."""
2021

@@ -23,7 +24,8 @@ def check_auth(username, password):
2324

2425
def authenticate():
2526
return Response(
26-
"Authentication required.", 401,
27+
"Authentication required.",
28+
401,
2729
{"WWW-Authenticate": "Basic realm='Login Required'"},
2830
)
2931

@@ -44,13 +46,15 @@ def decorated(*args, **kwargs):
4446

4547
return decorated
4648

49+
4750
app = Flask(__name__)
4851
app.config["SWAGGER"] = {
4952
"title": "Swagger Basic Auth App",
5053
"uiversion": 2,
5154
}
52-
swag = Swagger(app,
53-
decorators=[ requires_basic_auth ],
55+
swag = Swagger(
56+
app,
57+
decorators=[requires_basic_auth],
5458
template={
5559
"swagger": "2.0",
5660
"info": {
@@ -66,6 +70,7 @@ def decorated(*args, **kwargs):
6670
},
6771
)
6872

73+
6974
@app.route("/echo/<name>", methods=["GET", "POST"])
7075
def echo(name):
7176
"""
@@ -110,9 +115,11 @@ def echo(name):
110115
}
111116
return jsonify(data)
112117

118+
113119
@app.route("/")
114120
def index():
115121
return redirect("/apidocs")
116122

123+
117124
if __name__ == "__main__":
118125
app.run(debug=True)

ci/tests/suite/test_callbacks.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
from flask_openapi import Swagger
88

99
app = Flask(__name__)
10-
app.config['SWAGGER'] = {
11-
'title': 'OA3 Callbacks',
12-
'openapi': '3.0.2'
13-
}
10+
app.config["SWAGGER"] = {"title": "OA3 Callbacks", "openapi": "3.0.2"}
1411
Swagger(app)
1512

1613

17-
@app.route('/run_callback/', methods=['POST'])
14+
@app.route("/run_callback/", methods=["POST"])
1815
def run_callback():
1916
"""Example endpoint that specifies OA3 callbacks
2017
This is using docstring for specifications
@@ -46,7 +43,7 @@ def run_callback():
4643
type: string
4744
"""
4845

49-
return jsonify({'result': 'ok'})
46+
return jsonify({"result": "ok"})
5047

5148

5249
def test_swag(client, specs_data):
@@ -55,12 +52,11 @@ def test_swag(client, specs_data):
5552
:param specs_data: {'url': {swag_specs}} for every spec in app
5653
"""
5754
for url, spec in specs_data.items():
58-
assert 'openapi' in spec
59-
assert spec['openapi'] == '3.0.2'
55+
assert "openapi" in spec
56+
assert spec["openapi"] == "3.0.2"
6057

61-
assert 'callbacks' in spec['paths']['/run_callback/']['post']
62-
assert 'onSomeEvent' in \
63-
spec['paths']['/run_callback/']['post']['callbacks']
58+
assert "callbacks" in spec["paths"]["/run_callback/"]["post"]
59+
assert "onSomeEvent" in spec["paths"]["/run_callback/"]["post"]["callbacks"]
6460

6561

6662
if __name__ == "__main__":

ci/tests/suite/test_colors.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
from flask_openapi import Swagger
88

99
app = Flask(__name__)
10-
app.config['SWAGGER'] = {
11-
'title': 'Colors API'
12-
}
10+
app.config["SWAGGER"] = {"title": "Colors API"}
1311
Swagger(app)
1412

1513

16-
@app.route('/colors/<palette>/')
14+
@app.route("/colors/<palette>/")
1715
def colors(palette):
1816
"""Example endpoint return a list of colors by palette
1917
This is using docstring for specifications
@@ -61,10 +59,10 @@ def colors(palette):
6159
rgb: ['red', 'green', 'blue']
6260
"""
6361
all_colors = {
64-
'cmyk': ['cyan', 'magenta', 'yellow', 'black'],
65-
'rgb': ['red', 'green', 'blue']
62+
"cmyk": ["cyan", "magenta", "yellow", "black"],
63+
"rgb": ["red", "green", "blue"],
6664
}
67-
if palette == 'all':
65+
if palette == "all":
6866
result = all_colors
6967
else:
7068
result = {palette: all_colors.get(palette)}
@@ -78,9 +76,9 @@ def test_swag(client, specs_data):
7876
:param specs_data: {'url': {swag_specs}} for every spec in app
7977
"""
8078
for url, spec in specs_data.items():
81-
assert 'Palette' in spec['definitions']
82-
assert 'Color' in spec['definitions']
83-
assert 'colors' in spec['paths']['/colors/{palette}/']['get']['tags']
79+
assert "Palette" in spec["definitions"]
80+
assert "Color" in spec["definitions"]
81+
assert "colors" in spec["paths"]["/colors/{palette}/"]["get"]["tags"]
8482

8583

8684
if __name__ == "__main__":

ci/tests/suite/test_colors_external_js.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
from flask_openapi import Swagger
88

99
app = Flask(__name__)
10-
app.config['SWAGGER'] = {
11-
'title': 'Colors API'
12-
}
10+
app.config["SWAGGER"] = {"title": "Colors API"}
1311
swagger_config = Swagger.DEFAULT_CONFIG
14-
swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js'
15-
swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js'
16-
swagger_config['jquery_js'] = '//unpkg.com/[email protected]/dist/jquery.min.js'
17-
swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css'
12+
swagger_config[
13+
"swagger_ui_bundle_js"
14+
] = "//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"
15+
swagger_config[
16+
"swagger_ui_standalone_preset_js"
17+
] = "//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js"
18+
swagger_config["jquery_js"] = "//unpkg.com/[email protected]/dist/jquery.min.js"
19+
swagger_config["swagger_ui_css"] = "//unpkg.com/swagger-ui-dist@3/swagger-ui.css"
1820
Swagger(app, config=swagger_config)
1921

20-
@app.route('/colors/<palette>/')
22+
23+
@app.route("/colors/<palette>/")
2124
def colors(palette):
2225
"""Example endpoint return a list of colors by palette
2326
This is using docstring for specifications
@@ -65,10 +68,10 @@ def colors(palette):
6568
rgb: ['red', 'green', 'blue']
6669
"""
6770
all_colors = {
68-
'cmyk': ['cyan', 'magenta', 'yellow', 'black'],
69-
'rgb': ['red', 'green', 'blue']
71+
"cmyk": ["cyan", "magenta", "yellow", "black"],
72+
"rgb": ["red", "green", "blue"],
7073
}
71-
if palette == 'all':
74+
if palette == "all":
7275
result = all_colors
7376
else:
7477
result = {palette: all_colors.get(palette)}
@@ -82,9 +85,9 @@ def test_swag(client, specs_data):
8285
:param specs_data: {'url': {swag_specs}} for every spec in app
8386
"""
8487
for url, spec in specs_data.items():
85-
assert 'Palette' in spec['definitions']
86-
assert 'Color' in spec['definitions']
87-
assert 'colors' in spec['paths']['/colors/{palette}/']['get']['tags']
88+
assert "Palette" in spec["definitions"]
89+
assert "Color" in spec["definitions"]
90+
assert "colors" in spec["paths"]["/colors/{palette}/"]["get"]["tags"]
8891

8992

9093
if __name__ == "__main__":

0 commit comments

Comments
 (0)