def test_multi_format_invalid_in_values(in_): parameter = ParameterFactory(**{"collectionFormat": MULTI, "in": in_}) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter) assert_message_in_errors( MESSAGES["collection_format"]["invalid_based_on_in_value"], err.value.detail, "collectionFormat" )
def test_in_must_be_one_of_valid_values(): with pytest.raises(ValidationError) as err: single_parameter_validator({'in': 'not-a-valid-in-value'}) assert_message_in_errors( MESSAGES['enum']['invalid'], err.value.detail, 'in.enum', )
def test_collection_format_with_invalid_value(): with pytest.raises(ValidationError) as err: single_parameter_validator({'collectionFormat': 'not-a-collection-format'}) assert_message_in_errors( MESSAGES['enum']['invalid'], err.value.detail, 'collectionFormat.enum', )
def test_collection_format_is_not_required(): try: single_parameter_validator({}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors("collectionFormat", errors)
def test_name_with_invalid_types(value): with pytest.raises(ValidationError) as err: single_parameter_validator({'name': value}) assert_message_in_errors( MESSAGES['type']['invalid'], err.value.detail, 'name.type', )
def test_description_with_invalid_types(value): with pytest.raises(ValidationError) as err: single_parameter_validator({'description': value}) assert_message_in_errors( MESSAGES['type']['invalid'], err.value.detail, 'description.type', )
def test_collection_format_with_valid_values(): try: single_parameter_validator({"collectionFormat": CSV}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors("collectionFormat", errors)
def test_collection_format_with_invalid_types(value): with pytest.raises(ValidationError) as err: single_parameter_validator({'collectionFormat': value}) assert_message_in_errors( MESSAGES['type']['invalid'], err.value.detail, 'collectionFormat.type', )
def test_that_when_type_is_array_items_is_required(): parameter = ParameterFactory(type=ARRAY) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter) assert_message_in_errors( MESSAGES['items']['items_required_for_type_array'], err.value.detail, 'items', )
def test_name_is_required(): context = {'deferred_references': set()} with pytest.raises(ValidationError) as err: single_parameter_validator({}, context=context) assert_message_in_errors( MESSAGES['required']['required'], err.value.detail, 'name', )
def test_multi_format_valid_in_values(in_): parameter = ParameterFactory(**{"collectionFormat": MULTI, "in": in_}) try: single_parameter_validator(parameter) except ValidationError as err: errors = err.detail else: errors = {} assert_message_not_in_errors(MESSAGES["collection_format"]["invalid_based_on_in_value"], errors)
def test_in_with_valid_values(value): try: single_parameter_validator({'in': value}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'in.enum', errors, )
def test_in_with_valid_values(): try: single_parameter_validator({'description': 'The description'}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'description', errors, )
def test_name_with_valid_values(): try: single_parameter_validator({'name': 'page_size'}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'name', errors, )
def test_when_in_value_is_path_required_must_be_true(): with pytest.raises(ValidationError) as err: single_parameter_validator(ParameterFactory(**{ 'in': PATH, 'required': False, })) assert_message_in_errors( MESSAGES['required']['path_parameters_must_be_required'], err.value.detail, '^required', )
def test_parameter_validation_with_default_present(): context = {'deferred_references': set()} parameter = ParameterFactory(default='0') assert 'default' in parameter try: single_parameter_validator(parameter, context=context) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors('default', errors)
def test_collection_format_with_valid_values(): try: single_parameter_validator({'collectionFormat': CSV}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'collectionFormat', errors, )
def test_collection_format_is_not_required(): try: single_parameter_validator({}) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'collectionFormat', errors, )
def test_description_is_not_required(): context = {'deferred_references': set()} try: single_parameter_validator({}, context=context) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'description', errors, )
def test_when_in_value_is_body_a_schema_is_required(): parameter = ParameterFactory(**{ 'in': BODY, }) parameter.pop('schema', None) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter) assert_message_in_errors( MESSAGES['schema']['body_parameters_must_include_a_schema'], err.value.detail, '^schema', )
def test_when_in_value_is_not_body_type_is_required(in_): parameter = ParameterFactory(**{ 'in': in_, }) parameter.pop('type', None) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter) assert_message_in_errors( MESSAGES['type']['non_body_parameters_must_declare_a_type'], err.value.detail, '^type', )
def test_when_in_value_is_path_required_must_be_true(): with pytest.raises(ValidationError) as err: single_parameter_validator( ParameterFactory(**{ 'in': PATH, 'required': False, })) assert_message_in_errors( MESSAGES['required']['path_parameters_must_be_required'], err.value.detail, '^required', )
def test_multi_format_invalid_in_values(in_): parameter = ParameterFactory(**{ 'collectionFormat': MULTI, 'in': in_, }) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter) assert_message_in_errors( MESSAGES['collection_format']['invalid_based_on_in_value'], err.value.detail, 'collectionFormat', )
def test_parameter_validation_with_default_present(): context = {'deferred_references': set()} parameter = ParameterFactory(default='0') assert 'default' in parameter try: single_parameter_validator(parameter, context=context) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'default', errors )
def test_multi_format_valid_in_values(in_): parameter = ParameterFactory(**{ 'collectionFormat': MULTI, 'in': in_, }) try: single_parameter_validator(parameter) except ValidationError as err: errors = err.detail else: errors = {} assert_message_not_in_errors( MESSAGES['collection_format']['invalid_based_on_in_value'], errors, )
def test_collection_format_defaults_to_csv(): raw_parameter = ParameterFactory() raw_parameter.pop('collectionFormat', None) value = single_parameter_validator(raw_parameter) with pytest.raises(AssertionError): # TODO: how do we set a default in the return object. assert value.get('collectionFormat') == CSV
def test_collection_format_defaults_to_csv(): raw_parameter = ParameterFactory() raw_parameter.pop("collectionFormat", None) value = single_parameter_validator(raw_parameter) with pytest.raises(AssertionError): # TODO: how do we set a default in the return object. assert value.get("collectionFormat") == CSV
def test_default_as_non_array_is_invalid(): """ https://github.com/swagger-api/swagger-spec/issues/343#issuecomment-128792251 """ context = {'deferred_references': set()} parameter = ParameterFactory( name="status", type=ARRAY, items={"type": STRING}, collectionFormat=MULTI, default="active", ) with pytest.raises(ValidationError) as err: single_parameter_validator(parameter, context=context) assert_message_in_errors( MESSAGES['default']['invalid_type'], err.value.detail, 'default', )
def test_default_as_array_is_valid(): """ https://github.com/swagger-api/swagger-spec/issues/343#issuecomment-128792251 """ context = {'deferred_references': set()} parameter = ParameterFactory( name="status", type=ARRAY, items={"type": STRING}, collectionFormat=MULTI, default=["active"], ) try: single_parameter_validator(parameter, context=context) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors('default', errors)
def test_default_as_array_is_valid(): """ https://github.com/swagger-api/swagger-spec/issues/343#issuecomment-128792251 """ context = {'deferred_references': set()} parameter = ParameterFactory( name="status", type=ARRAY, items={"type": STRING}, collectionFormat=MULTI, default=["active"], ) try: single_parameter_validator(parameter, context=context) except ValidationError as err: errors = err.detail else: errors = {} assert_path_not_in_errors( 'default', errors )
def test_collection_format_with_invalid_value(): with pytest.raises(ValidationError) as err: single_parameter_validator({"collectionFormat": "not-a-collection-format"}) assert_message_in_errors(MESSAGES["enum"]["invalid"], err.value.detail, "collectionFormat.enum")
def test_collection_format_with_invalid_types(value): with pytest.raises(ValidationError) as err: single_parameter_validator({"collectionFormat": value}) assert_message_in_errors(MESSAGES["type"]["invalid"], err.value.detail, "collectionFormat.type")