Exemplo n.º 1
0
def test_register_openapi_spec_yaml_3_and_json_2():
    """Successfully register both OpenAPI2 and OpenAPI3 specs with Connexion
    app."""
    app = App(__name__)
    spec_configs = [
        SpecConfig(path=PATH_SPECS_3_YAML_MODIFIED),
        SpecConfig(
            path=PATH_SPECS_2_JSON,
            add_operation_fields=OPERATION_FIELDS,
        ),
    ]
    res = register_openapi(app=app, specs=spec_configs)
    assert isinstance(res, App)
Exemplo n.º 2
0
def test_spec_config_rel_in_no_out():
    """Test creation of the SpecConfig model with valid data."""
    res = SpecConfig(**SPEC_CONFIG_REL_IN_NO_OUT)
    assert isinstance(res, SpecConfig)
    assert Path(res.path).is_absolute()
    assert res.path_out is not None
    assert Path(res.path_out).is_absolute()
Exemplo n.º 3
0
def test_spec_config_rel_out():
    """Test creation of the SpecConfig model with relative output file path."""
    res = SpecConfig(**SPEC_CONFIG_REL_OUT)
    assert isinstance(res, SpecConfig)
    assert Path(res.path).is_absolute()
    assert res.path_out is not None
    assert Path(res.path_out).is_absolute()
Exemplo n.º 4
0
def test_register_openapi_spec_file_not_found():
    """Registering OpenAPI specs fails because the spec file is not available.
    """
    app = App(__name__)
    spec_configs = [SpecConfig(path=PATH_SPECS_NOT_EXIST)]
    with pytest.raises(OSError):
        register_openapi(app=app, specs=spec_configs)
Exemplo n.º 5
0
def test_register_openapi_spec_no_operation_id():
    """Registering OpenAPI specs fails because of invalid OpenAPI format"""
    app = App(__name__)
    spec_configs = [
        SpecConfig(
            path=PATH_SPECS_INVALID_OPENAPI,
            add_operation_fields=OPERATION_FIELDS,
        )
    ]
    with pytest.raises(InvalidSpecification):
        register_openapi(app=app, specs=spec_configs)
Exemplo n.º 6
0
def test_register_openapi_spec_cannot_serialize():
    """Registering OpenAPI specs fails because the modified specs cannot be
    serialized."""
    app = App(__name__)
    app = App(__name__)
    spec_configs = [
        SpecConfig(
            path=PATH_SPECS_2_YAML_MODIFIED,
            add_operation_fields=OPERATION_FIELDS_NOT_SERIALIZABLE,
        )
    ]
    with pytest.raises(YAMLError):
        register_openapi(app=app, specs=spec_configs)
Exemplo n.º 7
0
def test_register_openapi_spec_cannot_write():
    """Registering OpenAPI specs fails because modified specs cannot be
    written.
    """
    app = App(__name__)
    spec_configs = [
        SpecConfig(
            path=PATH_SPECS_2_YAML,
            path_out=PATH_SPECS_NOT_EXIST,
            add_operation_fields=OPERATION_FIELDS,
        )
    ]
    with pytest.raises(OSError):
        register_openapi(app=app, specs=spec_configs)
Exemplo n.º 8
0
def test_spec_config_no_in():
    """Test creation of the SpecConfig model with valid data."""
    with pytest.raises(ValidationError):
        SpecConfig(**SPEC_CONFIG_NO_IN)
Exemplo n.º 9
0
def test_register_openapi_spec_yaml_2_modified():
    """Successfully register modified OpenAPI specs with Connexion app."""
    app = App(__name__)
    spec_configs = [SpecConfig(path=PATH_SPECS_2_YAML_MODIFIED)]
    res = register_openapi(app=app, specs=spec_configs)
    assert isinstance(res, App)
Exemplo n.º 10
0
def test_register_openapi_spec_yaml_2():
    """Successfully register OpenAPI specs with Connexion app."""
    app = App(__name__)
    spec_configs = [SpecConfig(**SPEC_CONFIG)]
    res = register_openapi(app=app, specs=spec_configs)
    assert isinstance(res, App)
Exemplo n.º 11
0
def test_SpecConfig_class_extra_arg():
    """Test SpecConfig instantiation; extra argument."""
    with pytest.raises(ValidationError):
        SpecConfig(non_existing=PATH_SPECS_2_YAML)
Exemplo n.º 12
0
def test_SpecConfig_class_minimal():
    """Test SpecConfig instantiation; minimal example"""
    res = SpecConfig(path=PATH_SPECS_2_YAML)
    assert res.path_out == PATH_SPECS_2_YAML_MODIFIED
Exemplo n.º 13
0
def test_SpecConfig_class():
    """Test SpecConfig instantiation; full example"""
    res = SpecConfig(**SPEC_CONFIG)
    assert res.path_out == SPEC_CONFIG['path_out']
Exemplo n.º 14
0
def test_register_openapi_spec_invalid_yaml_json():
    """Registering OpenAPI specs fails because of invalid file format."""
    app = App(__name__)
    spec_configs = [SpecConfig(path=PATH_SPECS_INVALID_JSON)]
    with pytest.raises(YAMLError):
        register_openapi(app=app, specs=spec_configs)