예제 #1
0
def test_validate_swagger_spec_failure(petstore_dict):
    # induce failure
    del petstore_dict['swagger']
    spec = Spec(petstore_dict)
    with pytest.raises(SwaggerValidationError) as excinfo:
        spec.build()
    assert "'swagger' is a required property" in str(excinfo.value)
예제 #2
0
def test_validate_swagger_spec_failure(petstore_dict):
    # induce failure
    del petstore_dict['swagger']
    spec = Spec(petstore_dict)
    with pytest.raises(SwaggerValidationError) as excinfo:
        spec.build()
    assert "'swagger' is a required property" in str(excinfo.value)
예제 #3
0
def test_build_with_internally_dereference_refs(petstore_dict,
                                                internally_dereference_refs):
    spec = Spec(
        petstore_dict,
        config={'internally_dereference_refs': internally_dereference_refs})
    assert spec.deref == spec._force_deref
    spec.build()
    assert (spec.deref == spec._force_deref) == (
        not internally_dereference_refs)
예제 #4
0
def test_not_object_x_models_are_not_generating_models(minimal_swagger_dict):
    minimal_swagger_dict['definitions']['Pets'] = {
        'type': 'array',
        'items': {
            'type': 'string',
        },
        'x-model': 'Pets',
    }
    swagger_spec = Spec(minimal_swagger_dict)
    swagger_spec.build()
    assert not swagger_spec.definitions
예제 #5
0
def test_build_with_internally_dereference_refs(petstore_abspath,
                                                petstore_dict,
                                                internally_dereference_refs):
    spec = Spec(
        petstore_dict,
        origin_url=get_url(petstore_abspath),
        config={'internally_dereference_refs': internally_dereference_refs})
    assert spec.deref == spec._force_deref
    spec.build()
    assert (spec.deref == spec._force_deref) == (
        not internally_dereference_refs)
예제 #6
0
def test_flattened_spec_raises_if_specs_are_not_built_and_validated(
    mock_flattened_dict,
    mock_build_api_serving_url,
    petstore_spec,
    build_spec_object,
):
    petstore_spec = Spec(mock_flattened_dict,
                         config=dict(
                             CONFIG_DEFAULTS,
                             validate_swagger_spec=not build_spec_object))
    if build_spec_object:
        petstore_spec.build()

    with pytest.raises(RuntimeError) as excinfo:
        petstore_spec.flattened_spec
    assert 'Swagger Specs have to be built and validated before flattening.' == str(
        excinfo.value)
예제 #7
0
def test_build_using_spec_url_for_base_path(petstore_abspath, petstore_dict,
                                            use_spec_url_for_base_path):
    # use_spec_url_for_base_path is only effective when basePath is not present
    # in the spec, so remove it
    del petstore_dict['basePath']

    origin_url = get_url(petstore_abspath)
    spec = Spec(
        petstore_dict,
        origin_url=origin_url,
        config={'use_spec_url_for_base_path': use_spec_url_for_base_path},
    )

    spec.build()

    base_url = 'http://' + petstore_dict['host']
    if not use_spec_url_for_base_path:
        assert spec.api_url == base_url + '/'
    else:
        petstore_path = get_url_path(origin_url)
        assert spec.api_url == '{}/{}'.format(
            base_url,
            pathname2url(petstore_path).lstrip('/'))
예제 #8
0
def assert_validate_call_count(expected_call_count, config, petstore_dict):
    spec = Spec(petstore_dict, config=config)
    with patch('bravado_core.spec.validator20.validate_spec') as m_validate:
        spec.build()
    assert expected_call_count == m_validate.call_count
예제 #9
0
def assert_validate_call_count(expected_call_count, config, petstore_dict):
    spec = Spec(petstore_dict, config=config)
    with patch('bravado_core.spec.validator20.validate_spec') as m_validate:
        spec.build()
    assert expected_call_count == m_validate.call_count