Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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
Example #6
0
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)
Example #7
0
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)
Example #8
0
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
Example #9
0
def test_array_in_response(httprettified, swagger_dict):
    response_spec = {
        'type': 'array',
        'items': {
            'type': 'string',
        },
    }
    register_spec(swagger_dict, response_spec)
    expected_array = ['inky', 'dinky', 'doo']
    register_test_http(body=json.dumps(expected_array))
    assert_result(expected_array)
Example #10
0
def test_primitive_types_returned_in_response(httprettified, swagger_dict):
    rtypes = {
        'string': '"test"',
        'integer': 42,
        'number': 3.4,
        'boolean': True
    }
    for rtype, rvalue in rtypes.items():
        register_spec(swagger_dict, {'type': rtype})
        register_test_http(body=json.dumps(rvalue))
        assert_result(rvalue)
Example #11
0
def test_array_in_response(httprettified, swagger_dict):
    response_spec = {
        'type': 'array',
        'items': {
            'type': 'string',
        },
    }
    register_spec(swagger_dict, response_spec)
    expected_array = ['inky', 'dinky', 'doo']
    register_test_http(body=json.dumps(expected_array))
    assert_result(expected_array)
Example #12
0
def test_primitive_types_returned_in_response(httprettified, swagger_dict):
    rtypes = {
        'string': '"test"',
        'integer': 42,
        'number': 3.4,
        'boolean': True
    }
    for rtype, rvalue in rtypes.iteritems():
        register_spec(swagger_dict, {'type': rtype})
        register_test_http(body=json.dumps(rvalue))
        assert_result(rvalue)
Example #13
0
def test_invalid_primitive_types_in_response_raises_ValidationError(
        httprettified, swagger_dict):
    rtypes = {
        'string': 42,
        'integer': 3.4,
        'number': 'foo',
        'boolean': '"NOT_BOOL"'
    }
    for rtype, rvalue in rtypes.items():
        register_spec(swagger_dict, {'type': rtype})
        register_test_http(body=json.dumps(rvalue))
        assert_raises_and_matches(ValidationError, 'is not of type')
Example #14
0
def test_invalid_primitive_types_in_response_raises_ValidationError(
        httprettified, swagger_dict):
    rtypes = {
        'string': 42,
        'integer': 3.4,
        'number': 'foo',
        'boolean': '"NOT_BOOL"'
    }
    for rtype, rvalue in rtypes.iteritems():
        register_spec(swagger_dict, {'type': rtype})
        register_test_http(body=json.dumps(rvalue))
        assert_raises_and_matches(ValidationError, 'is not of type')
Example #15
0
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
Example #16
0
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
Example #17
0
def test_date_format_in_reponse(httprettified, swagger_dict):
    response_spec = {'type': 'string', 'format': 'date'}
    register_spec(swagger_dict, response_spec)
    register_test_http(body=json.dumps("2014-06-10"))
    assert_result(datetime.date(2014, 6, 10))
Example #18
0
def test_date_format_in_reponse(httprettified, swagger_dict):
    response_spec = {'type': 'string', 'format': 'date'}
    register_spec(swagger_dict, response_spec)
    register_test_http(body=json.dumps("2014-06-10"))
    assert_result(datetime.date(2014, 6, 10))