class Config(Model): # misc mode: fields.Str() log_level: fields.Str() logger_name: fields.Optional(fields.Str) sleep_interval: fields.Float(normalizers=[float]) keys_base_path: fields.Str() path_to_keys: fields.Optional(fields.Str) # Only used in tests # db stuff db_name: fields.Str() db_uri: fields.Optional(fields.Str) db_host: fields.Optional(fields.Str) db_password: fields.Optional(fields.Str) db_username: fields.Optional(fields.Str) # multisig stuff signatures_threshold: fields.Int(normalizers=[int]) signatures_threshold_eth: fields.Optional(fields.Int(normalizers=[int])) multisig_wallet_address: fields.Str() # Ethereum address multisig_acc_addr: fields.Str() # SN address multisig_key_name: fields.Str() secret_signers: fields.Str() # ethereum stuff eth_node: fields.Str() network: fields.Str() eth_start_block: fields.Int(normalizers=[int]) eth_confirmations: fields.Int(normalizers=[int]) # eth account stuff eth_address: fields.Optional(fields.Str) eth_private_key: fields.Optional(fields.Str) pkcs11_module: fields.Optional(fields.Str) token: fields.Optional(fields.Str) user_pin: fields.Optional(fields.Str) label: fields.Optional(fields.Str) # oracle stuff ethgastation_api_key: fields.Optional(fields.Str) # secret network stuff secretcli_home: fields.Str() secret_node: fields.Str() enclave_key: fields.Str() chain_id: fields.Str() scrt_swap_address: fields.Str() swap_code_hash: fields.Str() # scrt account stuff secret_key_file: fields.Str() secret_key_name: fields.Str() secret_key_password: fields.Optional(fields.Str) # warnings eth_funds_warning_threshold: fields.Float(normalizers=[float]) scrt_funds_warning_threshold: fields.Float(normalizers=[float])
class Example(Model): a = fields.Int() def validate(self): if self.a == 0: raise ValidationError('invalid value') assert self.a != 0
def test___new___subclassed_basic(self): # When extending a Model the parent field attributes should also be # present. class Example(Model): a = fields.Int() b = fields.Bool() class Example2(Example): pass assert Example2.__fields__.a == fields.Int() assert Example2.__fields__.b == fields.Bool()
def test___new__subclassed_overriding_model_methods(self): # Subclassed Models can easily call override Model methods and call # super() if they so wish. class Example(Model): a = fields.Int() class Example2(Example): def __init__(self): super(Example2, self).__init__(a=5) assert Example2.__fields__.a == fields.Int() assert Example2().a == 5
def test___new___annotations_basic(self): # Check that basic annotations can be used. class Example(Model): a: fields.Int() b: fields.Bool() # The field attributes should not be present on the final class. assert not hasattr(Example, 'a') assert not hasattr(Example, 'b') # But they should be in the `__fields__` attribute assert Example.__fields__.a == fields.Int() assert Example.__fields__.b == fields.Bool()
def test___new___basic(self): # Check that the ModelType basic usage works, Fields should be pulled # off the class and added as a `__fields__` attribute. class Example(Model): a = fields.Int() b = fields.Bool() # The field attributes should not be present on the final class. assert not hasattr(Example, 'a') assert not hasattr(Example, 'b') # But they should be in the `__fields__` attribute assert Example.__fields__.a == fields.Int() assert Example.__fields__.b == fields.Bool()
def test___new___subclassed_overriding_fields(self): # Subclassed Models with Fields of the same name should override the # parent Fields. class Example(Model): a = fields.Int() b = fields.Int() class Example2(Example): b = fields.Float() c = fields.Float() assert Example2.__fields__.a == fields.Int() assert Example2.__fields__.b == fields.Float() assert Example2.__fields__.c == fields.Float()
def test___new___annotations_resolved(self): # Check that annotations that require resolving can be used. class NestedExample(Model): a = fields.Int() class Example(Model): a: int nested: NestedExample # The field attributes should not be present on the final class. assert not hasattr(Example, 'a') assert not hasattr(Example, 'nested') # But they should be in the `__fields__` attribute assert Example.__fields__.a == fields.Int() assert Example.__fields__.nested == fields.Nested(NestedExample)
class Version(Model): major = fields.Int() minor = fields.Int() patch = fields.Optional(fields.Int, default=0)
class Example(Model): b = fields.Str() a = fields.Int()
class Example(Model): a = fields.Int()
class NestedExample(Model): a = fields.Int()
class Player(Model): key = MyUuid(default=uuid4) name = fields.Tuple(str, str) age = fields.Int() rating = fields.Float()
class Login(Generatable): c = fields.Int()
class Example(Model): class Meta: tag = External() a = fields.Int()
class Example(Model): a = fields.Int(rename='b')
class Example(Model): a = fields.Int() b = fields.Optional(fields.Bool)
class Example(Model): a = fields.Int() def __init__(self): super(Example, self).__init__(a=5)
class Example(Model): a = fields.Int(default=5)
class Secret(Model): class Meta: abstract = True tag = CustomTag(tag='kind', recurse=True) a = fields.Int()
class Generatable(Secret): b = fields.Int()
class Example(Model): class Meta: tag = Internal(tag='kind') a = fields.Int()
class Encrypted(Secret): d = fields.Int()
class Example(Model): a: fields.Int() b: fields.Bool()
class Example(Model): a = fields.Int(validators=[validators.Between(100, 200)])
class Example(Model): a = fields.Int() b = fields.Bool() c = fields.Str()
class Example(Model): class Meta: tag = Adjacent(tag='kind', content='data') a = fields.Int()
class Example(Model): a = fields.Int(validators=[validators.Min(100)])
class Example(Model): class Meta: tag = ExampleTag(tag='kind') a = fields.Int()
class TokenRefreshResponse(Model): access_token: str = fields.Str() refresh_token: str = fields.Str() expires_in: int = fields.Int()