class ProjectResourceSerializer(ZopsBaseSerializer): name = StringField("Project name.Max length 70 Character") description = StringField("Project description.Max length 200 Character") id = StringField("ID", read_only=True) userLimit = IntField("User limit of service.", read_only=True, source='user_limit') userUsed = IntField("User used of service.", read_only=True, source='user_used') services = ZopsListOfStringsField("Project's active services", read_only=True)
class ServiceSerializer(ZopsBaseSerializer): id = StringField("ID", read_only=True) itemLimit = IntField("Item limit of service.", read_only=True, source='item_limit') itemUsed = IntField("Item used of service.", read_only=True, source='item_used') name = StringField("Service name.Max length 70 Character") description = StringField("Service description.Max length 200 Character") serviceCatalogCode = StringField("Code name of the service.", validators=[is_service_code], source="service_catalog_code")
class SubscriptionSerializer(BaseSerializer): #TODO: ADD VALIDATORS email = StringField("Email to send repository reports") subscriptions = JsonField("List of subscribed github ids") period = StringField("Notification period e.g. daily, or weekly") telegramID = StringField("Telegram ID") repoCount = IntField("Number of suggestions each time")
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)] )
class MeLastReadMessageSerializer(ZopsBaseDBSerializer): lastReadMessageId = ZopsAlphaNumericStringField( "Unique identifier of the message") numberOfUnreadMessage = IntField("Number of unread message", source="number_of_unread_message", read_only=True)
class CatSerializer(BaseSerializer): id = IntField("cat identification number", read_only=True) name = StringField("cat name", validators=[is_lower_case]) breed = StringField("official breed name")
def test_int_field(): field = IntField("test int field", max_value=100, min_value=0) # note: constraints (validators) does not affect conversions # between internal value and representation and this is fine # because we need to have value converted from representation # to be able to do validation assert field.from_representation(123) == 123 assert field.from_representation('123') == 123 assert field.to_representation(123) == 123 assert field.to_representation('123') == 123 # accept only explicit integers with pytest.raises(ValueError): field.to_representation('123.0213') with pytest.raises(ValueError): field.from_representation('123.0213') # accept only numbers with pytest.raises(ValueError): field.to_representation('foo') with pytest.raises(ValueError): field.from_representation('foo') # test validation with pytest.raises(ValidationError): field.validate(-10) with pytest.raises(ValidationError): field.validate(123)
def test_int_field(): field = IntField("test int field", max_value=100, min_value=0) # note: constraints (validators) does not affect conversions # between internal value and representation and this is fine # because we need to have value converted from representation # to be able to do validation assert field.from_representation(123) == 123 assert field.from_representation('123') == 123 assert field.to_representation(123) == 123 assert field.to_representation('123') == 123 # accept only explicit integers with pytest.raises(ValueError): field.to_representation('123.0213') with pytest.raises(ValueError): field.from_representation('123.0213') # accept only numbers with pytest.raises(ValueError): field.to_representation('foo') with pytest.raises(ValueError): field.from_representation('foo') # test validation with pytest.raises(ValidationError): field.validate(-10) with pytest.raises(ValidationError): field.validate(123)
class CollateralCountSerializer(BaseSerializer): count = IntField("State count")
class CommitCountSerializer(BaseSerializer): count = IntField("State count")
class ConfigCountSerializer(BaseSerializer): count = IntField("Config count")
class DebtCountSerializer(BaseSerializer): count = IntField("Debt count")
class LoanCountSerializer(BaseSerializer): count = IntField("Loan count")
class CatSerializer(BaseSerializer): id = IntField("cat identification number", read_only=True) name = RawField("cat name") breed = RawField("official breed name")