Exemplo n.º 1
0
    def test_datetime_field_new_dt_format(self):

        boring_format = "%Y-%m-%d %H:%M:%S"
        field = DateTimeField(dt_format=boring_format)

        dt_str = '2010-06-02 16:30:06'
        expected_dt = datetime.datetime(year=2010,
                                        month=6,
                                        day=2,
                                        hour=16,
                                        minute=30,
                                        second=6)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        field = DateTimeField(dt_formats=(boring_format, "%Y-%m-%dT%H:%M:%S"))
        dt_str2 = '2010-06-02T16:30:06'
        bad_string = "2010/06/02 16:30 06 seconds"
        expected_dt = datetime.datetime(year=2010,
                                        month=6,
                                        day=2,
                                        hour=16,
                                        minute=30,
                                        second=6)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.scrub_value(dt_str2) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        with pytest.raises(ValueError):
            field.scrub_value(bad_string)

        # make sure microseconds is stripped
        micro_dt_str = '2010-06-02 16:30:06.24234234'
        assert field.scrub_value(micro_dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str
Exemplo n.º 2
0
    def test_datetime_field_new_dt_format(self):

        boring_format = "%Y-%m-%d %H:%M:%S"
        field = DateTimeField(dt_format=boring_format)

        dt_str = '2010-06-02 16:30:06'
        expected_dt = datetime.datetime(year=2010, month=6, day=2,
                                        hour=16, minute=30, second=6)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        field = DateTimeField(dt_formats=(boring_format, "%Y-%m-%dT%H:%M:%S"))
        dt_str2 = '2010-06-02T16:30:06'
        bad_string = "2010/06/02 16:30 06 seconds"
        expected_dt = datetime.datetime(year=2010, month=6, day=2,
                                        hour=16, minute=30, second=6)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.scrub_value(dt_str2) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        with pytest.raises(ValueError):
            field.scrub_value(bad_string)

        # make sure microseconds is stripped
        micro_dt_str = '2010-06-02 16:30:06.24234234'
        assert field.scrub_value(micro_dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str
Exemplo n.º 3
0
    def test_datetime_field(self):

        field = DateTimeField()

        dt_str = '2012-08-21T22:30:14'
        expected_dt = datetime.datetime(year=2012, month=8, day=21,
                                        hour=22, minute=30, second=14)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        # make sure microseconds is stripped
        micro_dt_str = '2012-08-21T22:30:14.24234234'
        assert field.scrub_value(micro_dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str
Exemplo n.º 4
0
    def test_datetime_field_new_dt_format(self):

        boring_format = "%Y-%m-%d %H:%M:%S"
        field = DateTimeField(dt_format=boring_format)

        dt_str = '2010-06-02 16:30:06'
        expected_dt = datetime.datetime(year=2010, month=6, day=2,
                                        hour=16, minute=30, second=6)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        # make sure microseconds is stripped
        micro_dt_str = '2010-06-02 16:30:06.24234234'
        assert field.scrub_value(micro_dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str
Exemplo n.º 5
0
    def test_datetime_field(self):

        field = DateTimeField()

        dt_str = '2012-08-21T22:30:14'
        expected_dt = datetime.datetime(year=2012,
                                        month=8,
                                        day=21,
                                        hour=22,
                                        minute=30,
                                        second=14)
        assert field.scrub_value(dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str

        # make sure microseconds is stripped
        micro_dt_str = '2012-08-21T22:30:14.24234234'
        assert field.scrub_value(micro_dt_str) == expected_dt
        assert field.descrub_value(expected_dt) == dt_str
Exemplo n.º 6
0
    def test_empty_datetime_field(self):

        field = DateTimeField()
        assert field.scrub_value(None) is None
        assert field.descrub_value(None) is None
Exemplo n.º 7
0
    def test_empty_datetime_field(self):

        field = DateTimeField()
        assert field.scrub_value(None) is None
        assert field.descrub_value(None) is None