コード例 #1
0
ファイル: spec_func_test.py プロジェクト: althor880/bravado
def test_basePath_works(httprettified, swagger_dict):
    swagger_dict["basePath"] = "/append"
    register_spec(swagger_dict)
    register_get("http://localhost/append/test_http?test_param=foo")
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP(test_param="foo").result()
    assert ["foo"] == httpretty.last_request().querystring['test_param']
コード例 #2
0
def test_default_value_in_request(httprettified, swagger_dict):
    swagger_dict['paths']['/test_http']['get']['parameters'][0]['default'] = 'X'
    register_spec(swagger_dict)
    register_get("http://localhost/test_http?")
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP().result()
    assert ['X'] == httpretty.last_request().querystring['test_param']
コード例 #3
0
ファイル: model_func_test.py プロジェクト: Yelp/bravado
def test_invalid_type_in_response_raises_ValidationError(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    register_get("http://localhost/test_http", body='"NOT_COMPLEX_TYPE"')
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'NOT_COMPLEX_TYPE' is not of type" in str(excinfo.value)
コード例 #4
0
async def test_correct_route_with_basePath_no_slash(swagger_dict, http_client):
    register_get("http://localhost/lame/test/test_http?test_param=foo",
                 body=u'""')
    swagger_dict["basePath"] = "/lame/test"
    register_spec(swagger_dict)
    client = await swagger_client(http_client)
    assert await client.api_test.testHTTP(test_param="foo").result() is None
コード例 #5
0
def test_basePath_works(httprettified, swagger_dict):
    swagger_dict["basePath"] = "/append"
    register_spec(swagger_dict)
    register_get("http://localhost/append/test_http?test_param=foo")
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP(test_param="foo").result()
    assert ["foo"] == httpretty.last_request().querystring['test_param']
コード例 #6
0
async def test_basePath_works(swagger_dict, http_client):
    swagger_dict["basePath"] = "/append"
    register_spec(swagger_dict)
    register_get("http://localhost/append/test_http?test_param=foo")
    client = await swagger_client(http_client)
    await client.api_test.testHTTP(test_param="foo").result()
    assert ["foo"] == HTTPretty.last_request.querystring['test_param']
コード例 #7
0
def test_hostname_if_passed_overrides_origin_url(httprettified, swagger_dict):
    register_get("http://foo/test_http?", body='')
    swagger_dict['host'] = 'foo'
    register_spec(swagger_dict)
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP(test_param="foo").result()
    assert ["foo"] == httpretty.last_request().querystring['test_param']
コード例 #8
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_invalid_type_in_response_raises_ValidationError(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    register_get("http://localhost/test_http", body='"NOT_COMPLEX_TYPE"')
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'NOT_COMPLEX_TYPE' is not of type" in str(excinfo.value)
コード例 #9
0
ファイル: spec_func_test.py プロジェクト: althor880/bravado
def test_hostname_if_passed_overrides_origin_url(httprettified, swagger_dict):
    register_get("http://foo/test_http?", body='')
    swagger_dict['host'] = 'foo'
    register_spec(swagger_dict)
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP(test_param="foo").result()
    assert ["foo"] == httpretty.last_request().querystring['test_param']
コード例 #10
0
def test_correct_route_with_basePath_no_slash(httprettified, swagger_dict):
    register_get("http://localhost/lame/test/test_http?test_param=foo",
                 body=u'""')
    swagger_dict["basePath"] = "/lame/test"
    register_spec(swagger_dict)
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param="foo").result() is None
コード例 #11
0
async def test_hostname_if_passed_overrides_origin_url(swagger_dict,
                                                       http_client):
    register_get("http://foo/test_http?", body='')
    swagger_dict['host'] = 'foo'
    register_spec(swagger_dict)
    client = await swagger_client(http_client)
    await client.api_test.testHTTP(test_param="foo").result()
    assert ["foo"] == HTTPretty.last_request.querystring['test_param']
コード例 #12
0
def test_default_value_in_request(httprettified, swagger_dict):
    swagger_dict['paths']['/test_http']['get']['parameters'][0][
        'default'] = 'X'
    register_spec(swagger_dict)
    register_get("http://localhost/test_http?")
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP().result()
    assert ['X'] == httpretty.last_request().querystring['test_param']
コード例 #13
0
ファイル: spec_func_test.py プロジェクト: althor880/bravado
def test_correct_route_with_basePath_no_slash(httprettified, swagger_dict):
    register_get(
        "http://localhost/lame/test/test_http?test_param=foo",
        body=u'""')
    swagger_dict["basePath"] = "/lame/test"
    register_spec(swagger_dict)
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param="foo").result() is None
コード例 #14
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_invalid_type_in_response_raises_ValidationError(
        swagger_dict, sample_model, http_client):
    register_spec(swagger_dict)
    register_get("http://localhost/test_http", body='"NOT_COMPLEX_TYPE"')
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'NOT_COMPLEX_TYPE' is not of type" in str(excinfo.value)
コード例 #15
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_error_on_wrong_type_inside_complex_type(httprettified, swagger_dict,
                                                 sample_model):
    register_spec(swagger_dict)
    sample_model["id"] = "Not Integer"
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'Not Integer' is not of type" in str(excinfo.value)
コード例 #16
0
ファイル: model_func_test.py プロジェクト: Yelp/bravado
def test_error_on_missing_type_in_model(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    sample_model["schools"][0] = {}  # Omit 'name'
    register_get("http://localhost/test_http", body=simplejson.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'name' is a required property" in str(excinfo.value)
コード例 #17
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_error_on_missing_type_in_model(httprettified, swagger_dict,
                                        sample_model):
    register_spec(swagger_dict)
    sample_model["schools"][0] = {}  # Omit 'name'
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'name' is a required property" in str(excinfo.value)
コード例 #18
0
ファイル: model_func_test.py プロジェクト: Yelp/bravado
def test_model_missing_required_property_in_response_raises_ValidationError(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    sample_model.pop("id")
    register_get("http://localhost/test_http", body=simplejson.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'id' is a required property" in str(excinfo.value)
コード例 #19
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_additionalProperty_in_model_in_response(httprettified, swagger_dict,
                                                 sample_model):
    register_spec(swagger_dict)
    sample_model["extra"] = 42
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    result = resource.testHTTP().result()
    assert result.extra == 42
コード例 #20
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_model_missing_required_property_in_response_raises_ValidationError(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    sample_model.pop("id")
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'id' is a required property" in str(excinfo.value)
コード例 #21
0
ファイル: model_func_test.py プロジェクト: Yelp/bravado
def test_error_on_wrong_type_inside_complex_type(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    sample_model["id"] = "Not Integer"
    register_get("http://localhost/test_http", body=simplejson.dumps(sample_model))
    with pytest.raises(ValidationError) as excinfo:
        SwaggerClient.from_url(API_DOCS_URL).api_test.testHTTP().result()
    assert "'Not Integer' is not of type" in str(excinfo.value)
コード例 #22
0
ファイル: model_func_test.py プロジェクト: Yelp/bravado
def test_additionalProperty_in_model_in_response(
        httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    sample_model["extra"] = 42
    register_get("http://localhost/test_http", body=simplejson.dumps(sample_model))
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    result = resource.testHTTP().result()
    assert result.extra == 42
コード例 #23
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_model_missing_required_property_in_response_raises_ValidationError(
        swagger_dict, sample_model, http_client):
    register_spec(swagger_dict)
    sample_model.pop("id")
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'id' is a required property" in str(excinfo.value)
コード例 #24
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_additionalProperty_in_model_in_response(swagger_dict,
                                                       sample_model,
                                                       http_client):
    register_spec(swagger_dict)
    sample_model["extra"] = 42
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    result = await client.api_test.testHTTP().result()
    assert result.extra == 42
コード例 #25
0
async def test_default_value_not_in_request(swagger_dict, http_client):
    # Default should be applied on the server side so no need to send it in
    # the request.
    swagger_dict['paths']['/test_http']['get']['parameters'][0]['default'] = 'X'
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?')
    client = await swagger_client(http_client)
    await client.api_test.testHTTP().result()
    assert 'test_param' not in HTTPretty.last_request.querystring
コード例 #26
0
ファイル: request_func_test.py プロジェクト: analogue/bravado
def test_default_value_not_in_request(httprettified, swagger_dict):
    # Default should be applied on the server side so no need to send it in
    # the request.
    swagger_dict['paths']['/test_http']['get']['parameters'][0]['default'] = 'X'
    register_spec(swagger_dict)
    register_get("http://localhost/test_http?")
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP().result()
    assert 'test_param' not in httpretty.last_request().querystring
コード例 #27
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_error_on_missing_type_in_model(swagger_dict, sample_model,
                                              http_client):
    register_spec(swagger_dict)
    sample_model["schools"][0] = {}  # Omit 'name'
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'name' is a required property" in str(excinfo.value)
コード例 #28
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_error_on_wrong_type_inside_complex_type(swagger_dict,
                                                       sample_model,
                                                       http_client):
    register_spec(swagger_dict)
    sample_model["id"] = "Not Integer"
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'Not Integer' is not of type" in str(excinfo.value)
コード例 #29
0
def test_parameter_in_path_of_request(httprettified, swagger_dict):
    path_param_spec = {"in": "path", "name": "param_id", "type": "string"}
    paths_spec = swagger_dict['paths']
    paths_spec['/test_http/{param_id}'] = paths_spec.pop('/test_http')
    paths_spec['/test_http/{param_id}']['get']['parameters'].append(
        path_param_spec)
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/42?test_param=foo')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param="foo", param_id="42").result() is None
コード例 #30
0
def test_default_value_not_in_request(httprettified, swagger_dict):
    # Default should be applied on the server side so no need to send it in
    # the request.
    swagger_dict['paths']['/test_http']['get']['parameters'][0][
        'default'] = 'X'
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    resource.testHTTP().result()
    assert 'test_param' not in httpretty.last_request().querystring
コード例 #31
0
def test_500_error_raises_HTTPError(httprettified, swagger_dict):
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?test_param=foo', status=500)

    with pytest.raises(HTTPError) as excinfo:
        _resource().testHTTP(test_param='foo').result()

    match_str = '500 Internal Server Error'
    assert match_str in str(excinfo.value)

    response_text = '{"message": "HTTPretty :)"}'
    assert response_text in str(excinfo.value)
コード例 #32
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_model_in_response(httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = SwaggerClient.from_url(API_DOCS_URL)
    result = client.api_test.testHTTP().result()
    User = client.get_model('User')
    School = client.get_model('School')
    assert isinstance(result, User)
    for school in result.schools:
        assert isinstance(school, School)
    assert User(id=42,
                schools=[School(name="School1"),
                         School(name="School2")]) == result
コード例 #33
0
ファイル: model_func_test.py プロジェクト: iCodeIN/aiobravado
async def test_model_in_response(swagger_dict, sample_model, spec_type,
                                 http_client):
    register_spec(swagger_dict, spec_type=spec_type)
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    result = await client.api_test.testHTTP().result()
    User = client.get_model('User')
    School = client.get_model('School')
    assert isinstance(result, User)
    for school in result.schools:
        assert isinstance(school, School)
    assert User(id=42,
                schools=[School(name="School1"),
                         School(name="School2")]) == result
コード例 #34
0
ファイル: request_func_test.py プロジェクト: analogue/bravado
def test_parameter_in_path_of_request(httprettified, swagger_dict):
    path_param_spec = {
        "in": "path",
        "name": "param_id",
        "type": "string"
    }
    paths_spec = swagger_dict['paths']
    paths_spec['/test_http/{param_id}'] = paths_spec.pop('/test_http')
    paths_spec['/test_http/{param_id}']['get']['parameters'].append(
        path_param_spec)
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/42?test_param=foo')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param="foo", param_id="42").result() is None
コード例 #35
0
async def test_parameter_in_path_of_request(swagger_dict, http_client):
    path_param_spec = {
        'in': 'path',
        'name': 'param_id',
        'required': True,
        'type': 'string',
    }
    paths_spec = swagger_dict['paths']
    paths_spec['/test_http/{param_id}'] = paths_spec.pop('/test_http')
    paths_spec['/test_http/{param_id}']['get']['parameters'].append(
        path_param_spec)
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/42?test_param=foo')
    client = await swagger_client(http_client)
    assert await client.api_test.testHTTP(test_param='foo', param_id='42').result() is None
コード例 #36
0
ファイル: request_func_test.py プロジェクト: Yelp/bravado
def test_parameter_in_path_of_request(httprettified, swagger_dict):
    path_param_spec = {
        'in': 'path',
        'name': 'param_id',
        'required': True,
        'type': 'string',
    }
    paths_spec = swagger_dict['paths']
    paths_spec['/test_http/{param_id}'] = paths_spec.pop('/test_http')
    paths_spec['/test_http/{param_id}']['get']['parameters'].append(
        path_param_spec)
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/42?test_param=foo')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param='foo', param_id='42').result() is None
コード例 #37
0
def test_parameter_in_path_of_request(httprettified, swagger_dict):
    path_param_spec = {
        'in': 'path',
        'name': 'param_id',
        'required': True,
        'type': 'string',
    }
    paths_spec = swagger_dict['paths']
    paths_spec['/test_http/{param_id}'] = paths_spec.pop('/test_http')
    paths_spec['/test_http/{param_id}']['get']['parameters'].append(
        path_param_spec)
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/42?test_param=foo')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(test_param='foo', param_id='42').result() is None
コード例 #38
0
ファイル: model_func_test.py プロジェクト: ealter/bravado
def test_model_in_response(httprettified, swagger_dict, sample_model):
    register_spec(swagger_dict)
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = SwaggerClient.from_url(API_DOCS_URL)
    result = client.api_test.testHTTP().result()
    User = client.get_model('User')
    School = client.get_model('School')
    assert isinstance(result, User)
    for school in result.schools:
        assert isinstance(school, School)
    assert User(
        id=42,
        schools=[
            School(name="School1"),
            School(name="School2")
        ]) == result
コード例 #39
0
def test_array_with_collection_format_in_path_of_request(
        httprettified, swagger_dict):
    path_param_spec = {
        'in': 'path',
        'name': 'param_ids',
        'type': 'array',
        'items': {
            'type': 'integer'
        },
        'collectionFormat': 'csv',
    }
    swagger_dict['paths']['/test_http/{param_ids}'] = \
        swagger_dict['paths'].pop('/test_http')
    swagger_dict['paths']['/test_http/{param_ids}']['get']['parameters'] = \
        [path_param_spec]
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/40,41,42')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(param_ids=[40, 41, 42]).result() is None
コード例 #40
0
ファイル: request_func_test.py プロジェクト: analogue/bravado
def test_array_with_collection_format_in_path_of_request(
        httprettified, swagger_dict):
    path_param_spec = {
        'in': 'path',
        'name': 'param_ids',
        'type': 'array',
        'items': {
            'type': 'integer'
        },
        'collectionFormat': 'csv',
    }
    swagger_dict['paths']['/test_http/{param_ids}'] = \
        swagger_dict['paths'].pop('/test_http')
    swagger_dict['paths']['/test_http/{param_ids}']['get']['parameters'] = \
        [path_param_spec]
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/40,41,42')
    resource = SwaggerClient.from_url(API_DOCS_URL).api_test
    assert resource.testHTTP(param_ids=[40, 41, 42]).result() is None
コード例 #41
0
async def test_array_with_collection_format_in_path_of_request(
        swagger_dict, http_client):
    path_param_spec = {
        'in': 'path',
        'name': 'param_ids',
        'type': 'array',
        'items': {
            'type': 'integer'
        },
        'collectionFormat': 'csv',
        'required': True,
    }
    swagger_dict['paths']['/test_http/{param_ids}'] = \
        swagger_dict['paths'].pop('/test_http')
    swagger_dict['paths']['/test_http/{param_ids}']['get']['parameters'] = \
        [path_param_spec]
    register_spec(swagger_dict)
    register_get('http://localhost/test_http/40,41,42')
    client = await swagger_client(http_client)
    assert await client.api_test.testHTTP(param_ids=[40, 41, 42]).result() is None
コード例 #42
0
ファイル: response_func_test.py プロジェクト: trezorg/bravado
def test_500_error_raises_HTTPError(httprettified, swagger_dict):
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?test_param=foo', status=500)
    assert_raises_and_matches(HTTPError, '500 Internal Server Error')
コード例 #43
0
async def test_500_error_raises_HTTPError(swagger_dict, http_client):
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?test_param=foo', status=500)
    await assert_raises_and_matches(HTTPError, '500 Internal Server Error', http_client)
コード例 #44
0
ファイル: response_func_test.py プロジェクト: bpicolo/bravado
def test_500_error_raises_HTTPError(httprettified, swagger_dict):
    register_spec(swagger_dict)
    register_get('http://localhost/test_http?test_param=foo', status=500)
    assert_raises_and_matches(HTTPError, '500 Server Error')