class ExampleSerializer(BaseSerializer): writable = RawField("testing writable field") readonly = RawField("testing readonly field", read_only=True) unsigned = IntField( "testing validated field", validators=[min_validator(0)] )
def test_raw_field_allow_null(): field = RawField("field that allows nulls", allow_null=True) assert field.from_representation(None) is None assert field.from_representation("foo") == "foo" assert field.to_representation(None) is None assert field.to_representation("foo") == "foo"
def test_raw_field(data_type): field = RawField(None, None) instance = data_type() representation = field.to_representation(instance) assert isinstance(representation, data_type) assert instance == representation recreated = field.from_representation(representation) assert isinstance(recreated, data_type) assert instance == recreated
def test_raw_field(data_type): field = RawField(None, None) instance = data_type() representation = field.to_representation(instance) assert isinstance(representation, data_type) assert instance == representation recreated = field.from_representation(representation) assert isinstance(recreated, data_type) assert instance == recreated
class CommitSerializer(BaseSerializer): id_loan = RawField("id_loan") opcode = RawField("opcode") timestamp = RawField("timestamp") order = RawField("order") proof = RawField("proof") address = RawField("address") data = RawField("data")
class StateSerializer(BaseSerializer): id = RawField("id") status = RawField("status") clock = RawField("clock") last_payment = RawField("last payment") paid = RawField("paid") paid_base = RawField("paid base") interest = RawField("interest")
class DebtSerializer(BaseSerializer): id = RawField("id") error = RawField("error") balance = RawField("balance") model = RawField("model") creator = RawField("creator") created = RawField("created") oracle = RawField("oracle")
class DescriptorSerializer(BaseSerializer): first_obligation = RawField("first_obligation") total_obligation = RawField("total_obligation") duration = RawField("duration") interest_rate = RawField("interest_rate") punitive_interest_rate = RawField("punitive_interest_rate") frequency = RawField("frecuency") installments = RawField("installments")
class DebtWithoutIDSerializer(BaseSerializer): error = RawField("error") balance = RawField("balance") model = RawField("model") creator = RawField("creator") created = RawField("created") oracle = RawField("oracle")
def test_raw_field_allow_null(): field = RawField("field that allows nulls", allow_null=True) assert field.from_representation(None) is None assert field.from_representation("foo") == "foo" assert field.to_representation(None) is None assert field.to_representation("foo") == "foo"
class URLSerializer(BaseSerializer): url = RawField("url", read_only=True)
class ConfigSerializer(BaseSerializer): id = RawField("id") data = RawField("data")
class CollateralSerializer(BaseSerializer): id = RawField("id") debt_id = RawField("debt_id") oracle = RawField("oracle") token = RawField("token") amount = RawField("amount") liquidation_ratio = RawField("liquidation_ratio") balance_ratio = RawField("balance_ratio") burn_fee = RawField("burn_fee") reward_fee = RawField("reward_fee") owner = RawField("owner") amount = RawField("amount") status = RawField("status")
class OracleHistorySerializer(BaseSerializer): id = RawField("id") tokens = RawField("discortokens") equivalent = RawField("equivalent") timestamp = RawField("timestamp")
class CompleteLoanSerializer(BaseSerializer): id = RawField("id", source="_id") open = RawField("open") approved = RawField("approved") position = RawField("position") expiration = RawField("expiration") amount = RawField("amount") cosigner = RawField("cosigner") model = RawField("model") creator = RawField("creator") oracle = RawField("oracle") borrower = RawField("borrower") callback = RawField("callback") salt = RawField("salt") loanData = RawField("loanData") created = RawField("created") descriptor = ObjectField("descriptor", serializer=DescriptorSerializer()) currency = RawField("currency") lender = RawField("Lender") status = RawField("status") canceled = RawField("canceled") debt = ObjectField("debt", serializer=DebtWithoutIDSerializer()) config = RawField("config") state = ObjectField("state", serializer=StateWithoutIDSerializer()) collaterals = ListField("collaterals", serializer=CollateralWithoutIDSerializer())
class LoanSerializer(BaseSerializer): id = RawField("id") open = RawField("open") approved = RawField("approved") position = RawField("position") expiration = RawField("expiration") amount = RawField("amount") cosigner = RawField("cosigner") model = RawField("model") creator = RawField("creator") oracle = RawField("oracle") borrower = RawField("borrower") callback = RawField("callback") salt = RawField("salt") loanData = RawField("loanData") created = RawField("created") descriptor = ObjectField("descriptor", serializer=DescriptorSerializer()) currency = RawField("currency") lender = RawField("Lender") status = RawField("status") canceled = RawField("canceled")
class CatSerializer(BaseSerializer): id = IntField("cat identification number", read_only=True) name = RawField("cat name", validators=[is_lower_case]) breed = RawField("official breed name")
class CatSerializer(BaseSerializer): id = IntField("cat identification number", read_only=True) name = RawField("cat name") breed = RawField("official breed name")