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
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'))
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)
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'))
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)