示例#1
0
def test_skips_validating_errors():
    fake_schema = mock.Mock(response_body_schema={'type': 'string'})
    fake_validator = mock.Mock(schema=fake_schema)
    fake_validator_map = mock.Mock(response=fake_validator)
    response = Response(
        body='abe1351f',
        status_code=403,
    )
    validate_response(response, fake_validator_map)
    assert not fake_validator.validate.called
示例#2
0
def test_skips_validating_errors():
    fake_schema = mock.Mock(response_body_schema={'type': 'string'})
    fake_validator = mock.Mock(schema=fake_schema)
    fake_validator_map = mock.Mock(response=fake_validator)
    response = Response(
        body='abe1351f',
        status_code=403,
    )
    validate_response(response, fake_validator_map)
    assert not fake_validator.validate.called
示例#3
0
def test_raw_string():
    fake_schema = mock.Mock(response_body_schema={'type': 'string'})
    fake_validator = mock.Mock(schema=fake_schema)
    response = Response(
        body='abe1351f',
        headers={'Content-Type': 'application/text; charset=UTF-8'},
    )
    validate_response(response, fake_validator)
    fake_validator.validate.assert_called_once_with(
        response.body.decode('utf-8'))
示例#4
0
def test_validation_content_type_with_json():
    fake_schema = mock.Mock(response_body_schema={'type': 'object'})
    fake_validator = mock.Mock(schema=fake_schema)
    body = {'status': 'good'}
    response = Response(
        body=simplejson.dumps(body),
        headers={'Content-Type': 'application/json; charset=UTF-8'},
    )
    validate_response(response, fake_validator)
    fake_validator.validate.assert_called_once_with(body)
示例#5
0
def test_raw_string():
    fake_schema = mock.Mock(response_body_schema={'type': 'string'})
    fake_validator = mock.Mock(spec=SchemaValidator, schema=fake_schema)
    response = Response(
        body='abe1351f',
        headers={'Content-Type': 'application/text; charset=UTF-8'},
    )
    validator_map = mock.Mock(spec=ValidatorMap, response=fake_validator)
    validate_response(response, validator_map)
    fake_validator.validate.assert_called_once_with(
        response.body.decode('utf-8'))
示例#6
0
def test_validation_content_type_with_json():
    fake_schema = mock.Mock(response_body_schema={'type': 'object'})
    fake_validator = mock.Mock(schema=fake_schema)
    body = {'status': 'good'}
    response = Response(
        body=simplejson.dumps(body),
        headers={'Content-Type': 'application/json; charset=UTF-8'},
    )
    validator_map = mock.Mock(spec=ValidatorMap, response=fake_validator)
    validate_response(response, validator_map)
    fake_validator.validate.assert_called_once_with(body)