Example #1
0
class ConfigSchema(Schema):
    heartbeats = fields.List(fields.Nested(HeartbeatSchema),
                             required=False,
                             missing=[])
    ip = fields.IPv4(required=True)
    listeners = fields.List(fields.Nested(ListenerSchema),
                            required=False,
                            missing=[])
    logging = fields.List(fields.Nested(LoggingSchema),
                          required=False,
                          missing=[])
    notifiers = fields.List(fields.Nested(NotifierSchema),
                            required=False,
                            missing=[])
    partitions = fields.Mapping(
        keys=fields.String(required=True),
        values=fields.String(required=True),
        required=True,
    )
    password = fields.String(missing="")
    port = fields.Integer(required=False, missing=4025)
    storage = fields.List(fields.Nested(StorageSchema),
                          required=False,
                          missing=[])
    zones = fields.Mapping(
        keys=fields.String(required=True),
        values=fields.String(required=True),
        required=True,
    )

    @post_load
    def make_config(self, data, **kwargs):
        return Config(**data)
Example #2
0
class ServerSchema(Schema):
    id = fields.Int(dump_only=True)
    ip = fields.IPv4()
    port = fields.Int()
    nickname = fields.Str()

    @post_load
    def make_server(self, data, **kwargs):
        return Server(**data)
Example #3
0
    def test_ipv4_address_field(self, user):

        ipv4_string = "192.168.0.1"

        user.ipv4 = ipaddress.ip_address(ipv4_string)
        user.empty_ip = None

        field = fields.IPv4()
        assert isinstance(field.serialize("ipv4", user), str)
        assert field.serialize("ipv4", user) == ipv4_string
        assert field.serialize("empty_ip", user) is None
Example #4
0
class PaymentSchema(Schema):
    createdAt = fields.DateTime()
    merchantCode = fields.Str()
    customerCode = fields.Str()
    token = fields.Str()
    ip = fields.IPv4()
    amount = fields.Decimal()
    currency = fields.Str()
    status = fields.Str()
    orderId = fields.UUID()
    bankTransactionId = fields.Str()
    gatewayResponseCode = fields.Str()
    errorCode = fields.Str(required=False)

    @post_load
    def load_model(self, data, **kwargs):
        return Payment(**data, response=data)