class ConfigSchema(Schema): log_level = EnumField(LogLevel, load_default=LogLevel.WARNING) listen_addr = fields.IP(required=True) log_port_range = fields.Tuple((fields.Integer(), fields.Integer()), required=True) @post_load def make_config(self, data, **kwargs): return Config(**data)
def test_ip_address_field(self, user): ipv4_string = "192.168.0.1" ipv6_string = "ffff::ffff" ipv6_exploded_string = ipaddress.ip_address("ffff::ffff").exploded user.ipv4 = ipaddress.ip_address(ipv4_string) user.ipv6 = ipaddress.ip_address(ipv6_string) user.empty_ip = None field_compressed = fields.IP() assert isinstance(field_compressed.serialize("ipv4", user), str) assert field_compressed.serialize("ipv4", user) == ipv4_string assert isinstance(field_compressed.serialize("ipv6", user), str) assert field_compressed.serialize("ipv6", user) == ipv6_string assert field_compressed.serialize("empty_ip", user) is None field_exploded = fields.IP(exploded=True) assert isinstance(field_exploded.serialize("ipv6", user), str) assert field_exploded.serialize("ipv6", user) == ipv6_exploded_string
class DnsUpdateSchema(Schema): username = fields.Email(required=True) password = fields.Str(required=True) hostname = fields.Str(required=True) ip_address = fields.IP(required=True)