How to use the schematics.types.IntType function in schematics

To help you get started, we’ve selected a few schematics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github schematics / schematics / tests / test_list_type.py View on Github external
def test_mock_object():
    assert ListType(IntType, required=True).mock() is not None

    with pytest.raises(MockCreationError) as exception:
        ListType(IntType, min_size=10, max_size=1, required=True).mock()
github schematics / schematics / tests / test_validation.py View on Github external
def test_validate_convert():

    class M(Model):
        field1 = IntType()

    m = M()
    m.field1 = "1"
    m.validate()
    assert m.field1 == 1

    m = M()
    m.field1 = "foo"
    m.validate(convert=False)
    assert m.field1 == "foo"
github schematics / schematics / tests / test_functional.py View on Github external
def test_validate_strict_with_trusted_data():
    class Player(Model):
        id = IntType()

    try:
        validate(Player, {'id': 4}, strict=True, trusted_data={'name': 'Arthur'})
    except ValidationError as e:
        assert 'name' in e.messages
github tgonzales / mingus / mingus / service / models.py View on Github external
#import motor
from schematics.models import Model
from schematics.types import (StringType, IntType, UUIDType, DateTimeType)
from schematics.contrib.mongo import ObjectIdType
from schematics.transforms import blacklist, whitelist

 
class BaseModel(Model):
    _id = ObjectIdType()

class Song(BaseModel):
    slug = StringType(max_length=20)
    song = StringType(max_length=40, required=True)
    artist = StringType(max_length=40)
    rank = IntType()
    score = IntType()
    created = DateTimeType()

    '''
    def queryset(self):
        query = {'slug':"2"}
        return query
    '''

    class Options:
        roles = {
            #'public': blacklist('created','song','rank'),
            #'owner': blacklist('created'),
        }

    """
github hotosm / tasking-manager / server / models / dtos / message_dto.py View on Github external
""" DTO used to return all user messages """

    def __init__(self):
        """ DTO constructor initialise all arrays to empty"""
        super().__init__()
        self.user_messages = []

    pagination = ModelType(Pagination)
    user_messages = ListType(ModelType(MessageDTO), serialized_name="userMessages")


class ChatMessageDTO(Model):
    """ DTO describing an individual project chat message """

    message = StringType(required=True)
    user_id = IntType(required=True, serialize_when_none=False)
    project_id = IntType(required=True, serialize_when_none=False)
    timestamp = DateTimeType()
    username = StringType()


class ProjectChatDTO(Model):
    """ DTO describing all chat messages on one project """

    def __init__(self):
        """ DTO constructor initialise all arrays to empty"""
        super().__init__()
        self.chat = []

    chat = ListType(ModelType(ChatMessageDTO))
    pagination = ModelType(Pagination)
github tgonzales / mingus / mingus / service / models.py View on Github external
#import motor
from schematics.models import Model
from schematics.types import (StringType, IntType, UUIDType, DateTimeType)
from schematics.contrib.mongo import ObjectIdType
from schematics.transforms import blacklist, whitelist

 
class BaseModel(Model):
    _id = ObjectIdType()

class Song(BaseModel):
    slug = StringType(max_length=20)
    song = StringType(max_length=40, required=True)
    artist = StringType(max_length=40)
    rank = IntType()
    score = IntType()
    created = DateTimeType()

    '''
    def queryset(self):
        query = {'slug':"2"}
        return query
    '''

    class Options:
        roles = {
            #'public': blacklist('created','song','rank'),
            #'owner': blacklist('created'),
        }

    """
    Is Simple
github hotosm / tasking-manager / server / models / dtos / user_dto.py View on Github external
class UserDTO(Model):
    """ DTO for User """

    validation_message = BooleanType(default=True)
    id = LongType()
    username = StringType()
    role = StringType()
    mapping_level = StringType(
        serialized_name="mappingLevel", validators=[is_known_mapping_level]
    )
    date_registered = StringType(serialized_name="dateRegistered")
    total_time_spent = IntType(serialized_name="totalTimeSpent")
    time_spent_mapping = IntType(serialized_name="timeSpentMapping")
    time_spent_validating = IntType(serialized_name="timeSpentValidating")
    projects_mapped = IntType(serialized_name="projectsMapped")
    tasks_mapped = IntType(serialized_name="tasksMapped")
    tasks_validated = IntType(serialized_name="tasksValidated")
    tasks_invalidated = IntType(serialized_name="tasksInvalidated")
    email_address = EmailType(serialized_name="emailAddress")
    is_email_verified = EmailType(
        serialized_name="isEmailVerified", serialize_when_none=False
    )
    is_expert = BooleanType(serialized_name="isExpert", serialize_when_none=False)
    twitter_id = StringType(serialized_name="twitterId")
    facebook_id = StringType(serialized_name="facebookId")
    linkedin_id = StringType(serialized_name="linkedinId")
    slack_id = StringType(serialized_name="slackId")
    irc_id = StringType(serialized_name="ircId")
    skype_id = StringType(serialized_name="skypeId")
    city = StringType(serialized_name="city")
github binderclip / code-snippets-python / packages / schematics_snippets / schematics_demo.py View on Github external
from schematics.models import Model
from schematics.types import StringType, IntType, DateTimeType, ModelType


class HelloSchematics(Model):

    foo = StringType()


class MyDefault(Model):

    s1 = StringType()
    s2 = StringType(default="")
    s3 = StringType(default="x")

    i1 = IntType()
    i2 = IntType(default=0)
    i3 = IntType(default=1)


class MyFields(Model):

    s = StringType(default="s")
    d = DateTimeType(default=datetime.datetime.now)


class MyValidate(Model):
    city = StringType(required=True)
    taken_at = DateTimeType(default=datetime.datetime.now)


class ModelDetail(Model):
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_em.py View on Github external
index = types.PolyModelType(optplan.ComplexNumber)


class GdsMaterialStackLayer(schema_utils.Model):
    """Defines a single layer in a material stack.

    Attributes:
        foreground: Material to fill any structure in the layer.
        background: Material to fill any non-structure areas in the layer.
        extents: Start and end coordiantes of the layer stack.
        gds_layer: Name of GDS layer that contains the polygons for this layer.
    """
    foreground = types.ModelType(Material)
    background = types.ModelType(Material)
    extents = optplan.vec2d()
    gds_layer = types.ListType(types.IntType())


class GdsMaterialStack(schema_utils.Model):
    """Defines a material stack.

    This is used by `GdsEps` to define the permittivity distribution.

    Attributes:
        background: Material to fill any regions that are not covered by
            a material stack layer.
        stack: A list of `MaterialStackLayer` that defines permittivity for
            each layer.
    """
    background = types.ModelType(Material)
    stack = types.ListType(types.ModelType(GdsMaterialStackLayer))
github hotosm / tasking-manager / server / models / dtos / stats_dto.py View on Github external
def __init__(self, paginated_result):
        """ Instantiate from a Flask-SQLAlchemy paginated result"""
        super().__init__()

        self.has_next = paginated_result.has_next
        self.has_prev = paginated_result.has_prev
        self.next_num = paginated_result.next_num
        self.page = paginated_result.page
        self.pages = paginated_result.pages
        self.prev_num = paginated_result.prev_num
        self.per_page = paginated_result.per_page
        self.total = paginated_result.total

    has_next = BooleanType(serialized_name='hasNext')
    has_prev = BooleanType(serialized_name='hasPrev')
    next_num = IntType(serialized_name='nextNum')
    page = IntType()
    pages = IntType()
    prev_num = IntType(serialized_name='prevNum')
    per_page = IntType(serialized_name='perPage')
    total = IntType()


class ProjectActivityDTO(Model):
    """ DTO to hold all project activity """
    def __init__(self):
        super().__init__()
        self.activity = []

    pagination = ModelType(Pagination)
    activity = ListType(ModelType(TaskHistoryDTO))