How to use the jsonmodels.fields.TimeField 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_struct.py View on Github external
def test_to_struct_time():

    class Clock(models.Base):
        time = fields.TimeField()

    clock = Clock()
    clock.time = '12:03:34'

    pattern = {
        'time': '12:03:34'
    }
    assert pattern == clock.to_struct()
github jazzband / jsonmodels / tests / test_datetime_fields.py View on Github external
def test_time_field():

    class Event(models.Base):

        time = fields.TimeField()

    event = Event()

    event.time = '12:03:34'
    assert isinstance(event.time, datetime.time)
    event.time = datetime.time()
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_data_initialization.py View on Github external
default_job = Job(tile="Unemployed", company="N/A")
    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 / tests / test_datetime_fields.py View on Github external
def test_time_field_parse_value():

    field = fields.TimeField()

    assert datetime.time() == field.parse_value('00:00:00')
    assert (
        datetime.time(2, 34, 45, tzinfo=tzoffset(None, 7200)) ==
        field.parse_value('2:34:45+02:00')
    )

    with pytest.raises(ValueError):
        field.parse_value('not a time')
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_time_field_to_struct_with_tz():

    field = fields.TimeField()

    tt = datetime.time(tzinfo=_TestCet())
    assert '00:00:00+02:00' == field.to_struct(tt)

    tt = datetime.time(12, 34, 56, tzinfo=_TestCet())
    assert '12:34:56+02:00' == field.to_struct(tt)

    tt = datetime.time(tzinfo=_TestUtc())
    assert '00:00:00+00:00' == field.to_struct(tt)

    tt = datetime.time(12, 34, 56, tzinfo=_TestUtc())
    assert '12:34:56+00:00' == field.to_struct(tt)