def test_2dot0_schema_validated_on_include(_, _mock):
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/2.0/',
    }
    mock_config = mock.Mock(spec=Configurator,
                            registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
Ejemplo n.º 2
0
def test_bad_schema_not_validated_if_spec_validation_is_disabled():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
        'pyramid_swagger.enable_swagger_spec_validation': False,
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
Ejemplo n.º 3
0
def test_bad_schema_validated_on_include():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    with pytest.raises(jsonschema.exceptions.ValidationError):
        pyramid_swagger.includeme(mock_config)
def test_2dot0_schema_validated_on_include(_, _mock):
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/2.0/',
    }
    mock_config = mock.Mock(
        spec=Configurator, registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
Ejemplo n.º 5
0
def test_bad_schema_validated_on_include():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
        'pyramid_swagger.enable_swagger_spec_validation': True,
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    with pytest.raises(SwaggerValidationError):
        pyramid_swagger.includeme(mock_config)
Ejemplo n.º 6
0
def test_bad_schema_validated_on_include():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
        'pyramid_swagger.enable_swagger_spec_validation': True,
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    with pytest.raises(SwaggerValidationError):
        pyramid_swagger.includeme(mock_config)
Ejemplo n.º 7
0
def test_swagger_12_only(mock_register):
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/good_app/',
        'pyramid_swagger.swagger_versions': ['1.2']
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
    assert isinstance(settings['pyramid_swagger.schema12'], SwaggerSchema)
    assert mock_register.call_count == 1
Ejemplo n.º 8
0
def test_swagger_12_only(mock_register):
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/good_app/',
        'pyramid_swagger.swagger_versions': ['1.2']
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
    assert isinstance(settings['pyramid_swagger.schema12'], SwaggerSchema)
    assert mock_register.call_count == 1
def test_bad_schema_validated_on_include():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
    }
    mock_config = mock.Mock(spec=Configurator,
                            registry=mock.Mock(settings=settings))
    with pytest.raises(ValidationError) as excinfo:
        pyramid_swagger.includeme(mock_config)
    assert "'nickname' is a required property" in str(excinfo.value)
Ejemplo n.º 10
0
def test_disable_api_doc_views(_, mock_register):
    settings = {
        'pyramid_swagger.enable_api_doc_views': False,
        'pyramid_swagger.enable_swagger_spec_validation': False,
        'pyramid_swagger.schema': None,
    }
    mock_config = mock.Mock(registry=mock.Mock(settings=settings))
    pyramid_swagger.includeme(mock_config)
    assert not mock_register.called
Ejemplo n.º 11
0
def test_bad_schema_validated_on_include():
    settings = {
        'pyramid_swagger.schema_directory': 'tests/sample_schemas/bad_app/',
    }
    mock_config = mock.Mock(
        spec=Configurator, registry=mock.Mock(settings=settings))
    with pytest.raises(ValidationError) as excinfo:
        pyramid_swagger.includeme(mock_config)
    assert "'nickname' is a required property" in str(excinfo.value)
Ejemplo n.º 12
0
def test_disable_api_doc_views(_1, _2, mock_register):
    settings = {
        'pyramid_swagger.enable_api_doc_views': False,
        'pyramid_swagger.enable_swagger_spec_validation': False,
    }

    mock_config = mock.Mock(spec=Configurator,
                            registry=mock.Mock(spec=Registry,
                                               settings=settings))

    pyramid_swagger.includeme(mock_config)
    assert not mock_register.called
Ejemplo n.º 13
0
def test_disable_api_doc_views(_1, _2, mock_register):
    settings = {
        'pyramid_swagger.enable_api_doc_views': False,
        'pyramid_swagger.enable_swagger_spec_validation': False,
    }

    mock_config = mock.Mock(
        spec=Configurator,
        registry=mock.Mock(spec=Registry, settings=settings))

    pyramid_swagger.includeme(mock_config)
    assert not mock_register.called
Ejemplo n.º 14
0
def test_pyramid_swagger_import():
    registry = Registry('testing')
    config = Configurator(registry=registry)
    pyramid_swagger.includeme(config)