| 1 |
|
| 2 |
from flex.core import validate |
| 3 |
from flex import load as validate_fully |
| 4 |
|
| 5 |
|
| 6 |
def test_validate_example_specs(test_data): |
| 7 |
""" |
| 8 |
This test is generated by conftest.py |
| 9 |
for each app in examples app and `test_data` param is: |
| 10 |
|
| 11 |
mod, client, specs_data, opts = test_data |
| 12 |
|
| 13 |
mod: examples.example_name (the test module) |
| 14 |
client: Flask app test client |
| 15 |
specs_data: {'url': {swag_specs}} for every spec in app |
| 16 |
opts: a dictionary of test metadata defined in the example |
| 17 |
|
| 18 |
:expectedresults: validate specs dictionary using flex |
| 19 |
""" |
| 20 |
mod, client, specs_data, opts = test_data |
| 21 |
skip_full_validation = opts.get('skip_full_validation', False) |
| 22 |
for url, spec in specs_data.items(): |
| 23 |
if 'openapi' not in spec and not skip_full_validation: |
| 24 |
|
| 25 |
|
| 26 |
validate_fully(spec) |
| 27 |
else: |
| 28 |
|
| 29 |
|
| 30 |
validate(spec) |
| 31 |
|
| 32 |
|
| 33 |
def test_required_attributes(test_data): |
| 34 |
""" |
| 35 |
This test is generated by conftest.py |
| 36 |
for each app in examples app and `test_data` param is: |
| 37 |
|
| 38 |
mod, client, specs_data, opts = test_data |
| 39 |
|
| 40 |
mod: examples.example_name (the test module) |
| 41 |
client: Flask app test client |
| 42 |
specs_data: {'url': {swag_specs}} for every spec in app |
| 43 |
opts: a dictionary of test metadata defined in the example |
| 44 |
|
| 45 |
:expectedresults: assert required attributes are present |
| 46 |
""" |
| 47 |
mod, client, specs_data, opts = test_data |
| 48 |
for url, spec in specs_data.items(): |
| 49 |
assert 'paths' in spec, 'paths is required' |
| 50 |
assert 'info' in spec, 'info is required' |
| 51 |
|
| 52 |
|
| 53 |
def test_example_swag(test_data): |
| 54 |
""" |
| 55 |
This test is generated by conftest.py |
| 56 |
for each app in examples app and `test_data` param is: |
| 57 |
|
| 58 |
mod, client, specs_data, opts = test_data |
| 59 |
|
| 60 |
mod: examples.example_name (the test module) |
| 61 |
client: Flask app test client |
| 62 |
specs_data: {'url': {swag_specs}} for every spec in app |
| 63 |
opts: a dictionary of test metadata defined in the example |
| 64 |
|
| 65 |
:expectedresults: run mod.test_swag with no errors |
| 66 |
""" |
| 67 |
mod, client, specs_data, opts = test_data |
| 68 |
if getattr(mod, 'test_swag', None) is not None: |
| 69 |
mod.test_swag(client, specs_data) |