예제 #1
0
def test_DateTimeValidator_timezone():
    value = datetime.now()
    field = date_time_field(timezone=True)
    validator = field.metadata[VALIDATOR]
    with pytest.raises(ValidationError):
        validator(field, value)
    value = datetime(2020, 1, 1)
    assert not value.tzinfo
    v2 = validator(field, value)
    assert v2.tzinfo
예제 #2
0
    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")
예제 #3
0
def test_DateTimeValidator_call_invalid():
    field = date_time_field()
    validator = DateTimeValidator()
    with pytest.raises(ValidationError):
        validator(field, "invalid_date")
예제 #4
0
def test_DateTimeValidator_call_valid():
    value = datetime.now()
    field = date_time_field()
    validator = DateTimeValidator()
    assert validator(field, value) == value
    assert validator(field, value.isoformat()) == value
예제 #5
0
class TaskUpdate(TaskAdd):
    done: datetime = fields.date_time_field(description="Done timestamp")
예제 #6
0
class Task(TaskAdd):
    id: str = fields.uuid_field(required=True, description="Task ID")
    done: datetime = fields.date_time_field(description="Done timestamp")
    story_points: Decimal = fields.decimal_field(description="Story points")