"""ValidatorLoader tests. Testing generic validator methods """ import pytest from ows_product_physical.constant import header from ows_product_physical.validation.raml_utils import find_in_raml from ows_product_physical.validation.validation import api_definition def test_header_validator_builds_proper_schema(): """Test the method that converts RAML parsed headers into JSON schema. For our Draft3Validator class. """ schema = find_in_raml(api_definition, '/product', 'post').header_schema() assert schema.get('properties').get(header.CORRELATION_ID).\ get('type') == 'string' assert schema.get('properties').get(header.CONTENT_TYPE).\ get('type') == 'string' assert schema.get('properties').get(header.GRASS_ACCOUNT_TYPE).\ get('type') == 'string' assert schema.get('properties').get(header.GRASS_ACCOUNT_ID).\ get('type') == 'string' def test_header_validator_doesnt_load_properties_set_to_none(): """Test that the converted RAML to JSON Schema loads. Should load into a Draft3Validator, and test that it didn't load any properties set to None. """ schema = find_in_raml(api_definition, '/product', 'post').header_schema() # we know we didn't set the pattern property of Correlation-Id assert schema.get('properties').get('Correlation-Id').\ get('pattern') is None def test_body_validator_loads_from_raml(): """Test that body validator loads with expected value.""" schema = find_in_raml(api_definition, '/product', 'post').body_schema() assert schema.get('properties').get('product_code').get('type') == 'string' def test_find_in_raml_loading_unknown_path_gets_key_error(): """Test that error is raised with unknown path.""" with pytest.raises(KeyError): find_in_raml(api_definition, '/foobarbaz', 'post') def test_find_in_raml_loading_unknown_method_gets_key_error(): """Test that error is raised with unknown method.""" with pytest.raises(KeyError): find_in_raml(api_definition, '/product', 'patch')