Esempio n. 1
0
class TaskQuery(Query):
    title: str = fields.str_field(description="Task title")
    done: bool = fields.bool_field(description="done flag")
    type: TaskType = fields.enum_field(TaskType, description="Task type")
    severity: int = fields.integer_field(
        ops=("lt", "le", "gt", "ge", "ne"), description="Task severity"
    )
    story_points: Decimal = fields.decimal_field(description="Story points")
Esempio n. 2
0
def test_BoolValidator_valid():
    field = bool_field()
    validator = BoolValidator()
    assert validator(field, True) is True
    assert validator(field, False) is False
    assert validator(field, "TrUe") is True
    assert validator(field, "t") is True
    assert validator(field, "Yes") is True
    assert validator(field, "fAlSe") is False
    class MyClass:
        """Test data"""

        str_field: str = data_field(required=True,
                                    format="uuid",
                                    description="String field")
        int_field: int = data_field(format="uint64", description="Int field")
        float_field: float = number_field(description="Float field")
        boolean_field: bool = bool_field(description="Bool field")
        map_field: Dict[str, int] = data_field(description="Dict field")
        free_field: Dict[str, str] = data_field(description="Free field")
        datetime_field: datetime = date_time_field(
            description="Datetime field")
        ref_field: OtherClass = field(metadata={
            "required": True,
            "description": "Ref field"
        },
                                      default=None)
        list_ref_field: List[OtherClass] = data_field(description="List field")
Esempio n. 4
0
def test_additional_metadata():
    field = bool_field(meta=dict(ciao="luca"))
    assert field.metadata["ciao"] == "luca"
Esempio n. 5
0
def test_override_field_type():
    field = bool_field()
    assert not field.type
    field.type = bool
    with pytest.raises(RuntimeError):
        as_field(float, field=field)
Esempio n. 6
0
class Foo2:
    text: str = fields.str_field(min_length=3, description="Just some text")
    param: Union[str, int] = fields.integer_field(
        description="String accepted but convert to int")
    done: bool = fields.bool_field(description="Is Foo done?")
    value: float = fields.number_field()