Example #1
0
    def test_unsupported(self, deserializer_factory):
        spec = {"name": "param", "in": "header", "style": "unsupported"}
        param = Spec.from_dict(spec)
        value = ""

        with pytest.warns(UserWarning):
            result = deserializer_factory(param)(value)

        assert result == value
Example #2
0
    def test_string_valid(self, unmarshaller_factory):
        schema = {
            "type": "string",
        }
        spec = Spec.from_dict(schema)
        value = "test"

        result = unmarshaller_factory(spec)(value)

        assert result == value
    def test_defaults_true(self, location):
        spec = {
            "name": "default",
            "in": location,
            "style": "form",
        }
        param = Spec.from_dict(spec)
        result = get_explode(param)

        assert result is True
Example #4
0
    def test_query_empty(self, deserializer_factory):
        spec = {
            "name": "param",
            "in": "query",
        }
        param = Spec.from_dict(spec)
        value = ""

        with pytest.raises(EmptyQueryParameterValue):
            deserializer_factory(param)(value)
    def test_defined(self, style, location):
        spec = {
            "name": "default",
            "in": location,
            "style": style,
        }
        param = Spec.from_dict(spec)
        result = get_style(param)

        assert result == style
Example #6
0
    def test_number_float(self, unmarshaller_factory):
        schema = {
            "type": "number",
        }
        spec = Spec.from_dict(schema)
        value = 1.2
        result = unmarshaller_factory(spec)(value)

        assert result == 1.2
        assert type(result) == float
Example #7
0
    def test_number_valid(self, unmarshaller_factory):
        schema = {
            "type": "number",
        }
        spec = Spec.from_dict(schema)
        value = 1.23

        result = unmarshaller_factory(spec)(value)

        assert result == value
Example #8
0
    def test_boolean_valid(self, unmarshaller_factory):
        schema = {
            "type": "boolean",
        }
        spec = Spec.from_dict(schema)
        value = True

        result = unmarshaller_factory(spec)(value)

        assert result == value
Example #9
0
    def test_integer_enum_string_invalid(self, unmarshaller_factory):
        schema = {
            "type": "integer",
            "enum": [1, 2, 3],
        }
        spec = Spec.from_dict(schema)
        value = "2"

        with pytest.raises(UnmarshalError):
            unmarshaller_factory(spec)(value)
Example #10
0
    def test_number_format_double(self, unmarshaller_factory):
        schema = {
            "type": "number",
            "format": "double",
        }
        spec = Spec.from_dict(schema)
        value = 1.2
        result = unmarshaller_factory(spec)(value)

        assert result == 1.2
Example #11
0
    def test_string_format_datetime_invalid(self, unmarshaller_factory):
        schema = {
            "type": "string",
            "format": "date-time",
        }
        spec = Spec.from_dict(schema)
        value = "2018-01-02T00:00:00"

        with pytest.raises(InvalidSchemaValue):
            unmarshaller_factory(spec)(value)
Example #12
0
    def test_number_exclusive_maximum_invalid(self, value, validator_factory):
        schema = {
            "type": "number",
            "maximum": 3,
            "exclusiveMaximum": True,
        }
        spec = Spec.from_dict(schema)

        with pytest.raises(InvalidSchemaValue):
            validator_factory(spec).validate(value)
Example #13
0
    def test_object_default_property(self, value, validator_factory):
        schema = {
            "type": "object",
            "default": "value1",
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #14
0
    def test_object_max_properties_invalid_schema(self, value,
                                                  validator_factory):
        schema = {
            "type": "object",
            "maxProperties": -1,
        }
        spec = Spec.from_dict(schema)

        with pytest.raises(InvalidSchemaValue):
            validator_factory(spec).validate(value)
Example #15
0
    def test_string_max_length(self, value, validator_factory):
        schema = {
            "type": "string",
            "maxLength": 1,
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #16
0
    def test_string_pattern(self, value, validator_factory):
        schema = {
            "type": "string",
            "pattern": "bar",
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #17
0
    def test_string_format_unknown(self, value, validator_factory):
        unknown_format = "unknown"
        schema = {
            "type": "string",
            "format": unknown_format,
        }
        spec = Spec.from_dict(schema)

        with pytest.raises(FormatterNotFoundError):
            validator_factory(spec).validate(value)
Example #18
0
    def test_number_multiple_of(self, value, validator_factory):
        schema = {
            "type": "number",
            "multipleOf": 3,
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #19
0
    def test_string_format_byte(self, value, validator_factory):
        schema = {
            "type": "string",
            "format": "byte",
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
    def test_defaults_false(self, style, location):
        spec = {
            "name": "default",
            "in": location,
            "style": style,
        }
        param = Spec.from_dict(spec)
        result = get_explode(param)

        assert result is False
Example #21
0
    def test_integer_maximum(self, value, validator_factory):
        schema = {
            "type": "integer",
            "maximum": 3,
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #22
0
    def test_object_additional_properties_false(self, value,
                                                validator_factory):
        schema = {
            "type": "object",
            "additionalProperties": False,
        }
        spec = Spec.from_dict(schema)

        with pytest.raises(InvalidSchemaValue):
            validator_factory(spec).validate(value)
Example #23
0
    def test_string_format_unknown(self, unmarshaller_factory):
        unknown_format = "unknown"
        schema = {
            "type": "string",
            "format": unknown_format,
        }
        spec = Spec.from_dict(schema)
        value = "x"

        with pytest.raises(FormatterNotFoundError):
            unmarshaller_factory(spec)(value)
Example #24
0
    def test_string_format_custom_missing(self, validator_factory):
        custom_format = "custom"
        schema = {
            "type": "string",
            "format": custom_format,
        }
        spec = Spec.from_dict(schema)
        value = "x"

        with pytest.raises(FormatterNotFoundError):
            validator_factory(spec).validate(value)
Example #25
0
    def test_nullable(self, schema_type, validator_factory):
        schema = {
            "type": schema_type,
            "nullable": True,
        }
        spec = Spec.from_dict(schema)
        value = None

        result = validator_factory(spec).validate(value)

        assert result is None
Example #26
0
    def test_string_format_datetime_strict_rfc3339(self, value,
                                                   validator_factory):
        schema = {
            "type": "string",
            "format": "date-time",
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #27
0
    def test_integer_enum(self, unmarshaller_factory):
        schema = {
            "type": "integer",
            "enum": [1, 2, 3],
        }
        spec = Spec.from_dict(schema)
        value = 2

        result = unmarshaller_factory(spec)(value)

        assert result == int(value)
Example #28
0
    def test_schema_free_form_object(
        self, value, additional_properties, unmarshaller_factory
    ):
        schema = {
            "type": "object",
            "additionalProperties": additional_properties,
        }
        spec = Spec.from_dict(schema)

        result = unmarshaller_factory(spec)(value)
        assert result == value
Example #29
0
    def test_number_exclusive_maximum(self, value, validator_factory):
        schema = {
            "type": "number",
            "maximum": 3,
            "exclusiveMaximum": True,
        }
        spec = Spec.from_dict(schema)

        result = validator_factory(spec).validate(value)

        assert result is None
Example #30
0
    def test_string_format_date(self, unmarshaller_factory):
        schema = {
            "type": "string",
            "format": "date",
        }
        spec = Spec.from_dict(schema)
        value = "2018-01-02"

        result = unmarshaller_factory(spec)(value)

        assert result == datetime.date(2018, 1, 2)