How to use the jsonmodels.fields.DateField function in jsonmodels

To help you get started, we’ve selected a few jsonmodels 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 jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_schema_for_list_and_primitives(self):

        class Event(models.Base):

            time = fields.TimeField()
            date = fields.DateField()
            end = fields.DateTimeField()

        class Person(models.Base):

            names = fields.ListField([str, int, Event])

        schema = Person.to_json_schema()

        pattern = get_fixture('schema_with_list.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_datetime_fields(self):

        class Event(models.Base):

            time = fields.TimeField()
            date = fields.DateField()
            end = fields.DateTimeField()

        schema = Event.to_json_schema()

        pattern = get_fixture('schema4.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_datetime_fields.py View on Github external
def test_date_field_to_struct():

    field = fields.DateField()

    assert field.str_format is None

    tt = datetime.date(2000, 1, 1)
    assert '2000-01-01' == field.to_struct(tt)

    tt = datetime.date(2491, 5, 6)
    assert '2491-05-06' == field.to_struct(tt)
github jazzband / jsonmodels / tests / test_datetime_fields.py View on Github external
def test_date_field_to_struct_with_format():

    field = fields.DateField(str_format='%Y/%m/%d')

    assert '%Y/%m/%d' == field.str_format

    tt = datetime.date(2244, 5, 7)
    assert '2244/05/07' == field.to_struct(tt)
github jazzband / jsonmodels / tests / test_datetime_fields.py View on Github external
def test_date_field_not_required():

    class Event(models.Base):

        date = fields.DateField(required=False)

    event = Event()

    event.date = None
    assert event.date is None
github jazzband / jsonmodels / tests / test_struct.py View on Github external
def test_to_struct_date():

    class Event(models.Base):
        start = fields.DateField()

    event = Event()
    event.start = '2014-04-21'

    pattern = {
        'start': '2014-04-21'
    }
    assert pattern == event.to_struct()
github jazzband / jsonmodels / tests / test_data_initialization.py View on Github external
default_age = 18
    default_name = "John Doe"
    default_height = 1.70
    default_hobbies = ["eating", "reading"]
    default_last_ate = datetime.time()
    default_birthday = datetime.date.today()
    default_time_of_death = datetime.datetime.now()

    class Person(models.Base):
        name = fields.StringField(default=default_name)
        age = fields.IntField(default=default_age)
        height = fields.FloatField(default=default_height)
        job = fields.EmbeddedField(Job, default=default_job)
        hobbies = fields.ListField(items_types=str, default=default_hobbies)
        last_ate = fields.TimeField(default=default_last_ate)
        birthday = fields.DateField(default=default_birthday)
        time_of_death = fields.DateTimeField(default=default_time_of_death)

    p = Person()
    assert p.name == default_name
    assert p.age == default_age
    assert p.height == default_height
    assert p.hobbies == default_hobbies
    assert p.job == default_job
    assert p.last_ate == default_last_ate
    assert p.birthday == default_birthday
    assert p.time_of_death == default_time_of_death
github jazzband / jsonmodels / jsonmodels / fields.py View on Github external
def __init__(self, str_format=None, *args, **kwargs):
        """Init.

        :param str str_format: Format to cast date to (if `None` - casting to
            %Y-%m-%d format).

        """
        self.str_format = str_format
        super(DateField, self).__init__(*args, **kwargs)