Example #1
0
def test_datetime_time_iso():
    isodates_encoder = jsonify.JSONEncoder(isodates=True)

    d = datetime.utcnow().time()
    encoded = jsonify.encode({'date': d}, encoder=isodates_encoder)

    isoformat_without_millis = json.dumps({'date': d.isoformat()[:8]})
    assert isoformat_without_millis == encoded, (isoformat_without_millis,
                                                 encoded)
Example #2
0
 def test_select_rows_datetime():
     s = create_session()
     t = test5.select().execute()
     encoded = jsonify.encode(dict(results=t),
                              encoder=jsonify.JSONEncoder(isodates=True))
     expected = """{"results": {"count": -1, "rows": [{"count": 1, "rows": {"date": "2016-12-11T10:09:08", "id": 1, "val": "sometime", "time": "21:20:19"}}]}}"""
     encoded = json.loads(encoded)
     expected = json.loads(expected)
     assert encoded == expected, encoded
def test_date_iso():
    isodates_encoder = jsonify.JSONEncoder(isodates=True)

    d = datetime.utcnow().date()
    encoded = jsonify.encode({'date': d}, encoder=isodates_encoder)

    isoformat_without_millis = json.dumps({'date': d.isoformat()})
    assert isoformat_without_millis == encoded, (isoformat_without_millis,
                                                 encoded)

    loaded_date = json.loads(encoded)
    assert len(loaded_date['date'].split('-')) == 3
def test_list_allowed_iter():
    lists_encoder = jsonify.JSONEncoder(allow_lists=True)
    d = list(range(3))
    encoded = jsonify.encode_iter(d, lists_encoder)
    assert ''.join(encoded) == '[0, 1, 2]'
def test_list_allowed_iter():
    lists_encoder = jsonify.JSONEncoder(allow_lists=True)
    d = ['a', 1, 'b', 2]
    encoded = jsonify.encode(d, lists_encoder)
    assert encoded == '["a", 1, "b", 2]'