def test_boolean_header_type_for_invalid_value(): header_definition = single_header_validator({ 'type': BOOLEAN, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor('not-a-known-boolean') assert actual == 'not-a-known-boolean'
def test_number_header_type_with_invalid_value(): header_definition = single_header_validator({ 'type': NUMBER, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor('abc') assert actual == 'abc'
def test_boolean_header_type(input_, expected): header_definition = single_header_validator({ 'type': BOOLEAN, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor(input_) assert actual == expected
def test_integer_header_type_with_invalid_values(value): header_definition = single_header_validator({ 'type': INTEGER, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor(value) assert actual == value
def test_number_header_type(): header_definition = single_header_validator({ 'type': NUMBER, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor('10.5') expected = 10.5 assert actual == expected
def test_integer_header_type(): header_definition = single_header_validator({ 'type': INTEGER, }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor('123') expected = 123 assert actual == expected
def test_array_header_type_casting_with_single_tems(format_, input_): header_definition = single_header_validator({ 'type': ARRAY, 'collectionFormat': format_, 'items': {'type': INTEGER} }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor(input_) expected = [1, 2, 3] assert actual == expected
def test_header_type_validation_for_invalid_values(type_, value): header_definition = single_header_validator({ 'type': type_, }) validators = construct_header_validators(header_definition=header_definition, context={}) with pytest.raises(ValidationError) as err: validate_object(value, validators) assert 'type' in err.value.detail assert_error_message_equal( err.value.detail['type'][0], MESSAGES['type']['invalid'], )
def test_array_header_type_casting_with_multiple_items(): header_definition = single_header_validator({ 'type': ARRAY, 'collectionFormat': CSV, 'items': [ {'type': INTEGER}, {'type': STRING}, {'type': BOOLEAN}, ] }) value_processor = generate_value_processor(context={}, **header_definition) actual = value_processor('1,a,true,2') expected = [1, 'a', True, '2'] assert actual == expected
def test_header_type_validation_for_invalid_values(type_, value): header_definition = single_header_validator({ 'type': type_, }) validators = construct_header_validators( header_definition=header_definition, context={}) with pytest.raises(ValidationError) as err: validate_object(value, validators) assert 'type' in err.value.detail assert_error_message_equal( err.value.detail['type'][0], MESSAGES['type']['invalid'], )