def test_deserialization_fails(self): ts = time.time() dt = datetime.datetime.fromtimestamp(ts) loaded = JSTimestampField()._deserialize(ts * 1000, None, None) assert isinstance(loaded, datetime.date) assert abs(loaded - dt) < datetime.timedelta(seconds=60)
class WorkspaceDurationSchema(Schema): start_date = JSTimestampField(attribute='start_date') end_date = JSTimestampField(attribute='end_date')
def test_parses_null_datetime(self): assert JSTimestampField()._serialize(None, None, None) is None
def test_parses_current_datetime(self): ts = time.time() dt = datetime.datetime.fromtimestamp(ts) parsed = JSTimestampField()._serialize(dt, None, None) assert parsed == int(ts) * 1000 assert isinstance(parsed, int)