Пример #1
0
class SourcePrice:
    """An object containing prices for a single contract"""

    id: int = fields.integer_field(description="ID", required=True)
    extra: Dict = fields.data_field(description="JSON blob")
    prices: Dict[str, Decimal] = fields.data_field(
        description="source-price mapping",
        items=fields.decimal_field(
            min_value=0,
            max_value=100,
            precision=4,
            description="price",
        ),
        default_factory=dict,
    )
    foos: List[Foo] = fields.data_field(default_factory=list)
Пример #2
0
def test_ListValidator_call_invalid():
    value = [1, "string"]
    field = data_field()
    validator1 = FakeValidator()
    validator2 = FakeValidatorError()
    validator = ListValidator((validator1, validator2))
    with pytest.raises(ValidationError):
        validator(field, value)
Пример #3
0
def test_ListValidator_call_valid():
    value = "test"
    field = data_field()
    validator1 = FakeValidator()
    validator2 = FakeValidator()
    validator = ListValidator((validator1, validator2))
    assert validator(field, value) == "test"
    assert validator.dump(3) == "3"
Пример #4
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")
Пример #5
0
 class OtherClass:
     str_field: str = data_field(description="String field")
Пример #6
0
 class MyClass:
     map_field: Dict[int, str] = data_field(description="Map field")
Пример #7
0
 class MyClass:
     desc_field: str = data_field(description="Valid field")
     no_desc_field: str = data_field()
Пример #8
0
def test_base_validator():
    validator = Validator()
    field = data_field()
    with pytest.raises(ValidationError):
        validator(field, None)
Пример #9
0
def test_Choice_call_invalid():
    field = data_field()
    validator = Choice(["a", "b", "c"])
    with pytest.raises(ValidationError):
        validator(field, "d")
Пример #10
0
def test_Choice_call_valid():
    field = data_field()
    validator = Choice(["a", "b", "c"])
    assert validator(field, "a") == "a"
Пример #11
0
class Role:
    name: str = fields.str_field(required=True, description="Role name")
    permissions: List[Permission] = fields.data_field(
        required=True, description="List of permissions"
    )
Пример #12
0
class Permission:
    paths: List[str] = fields.data_field(description="Permition paths")
    methods: List[str] = fields.data_field(description="Permition methods")
    body: Dict[str, str] = fields.json_field(description="Permission body")
    action: str = fields.str_field(default="allow", description="Permition action")
Пример #13
0
class BundleUpload:
    files: List[bytes] = fields.data_field(description="list of bundles to upload")