def test_writing_datetimes(self): res = QueryResult(SimpleQueryFactory(sql='select 1 as "a", 2 as "b"').sql, connections[CONN]) res.execute_query() res.process() res._data = [[1, date.today()]] res = JSONExporter(query=None)._get_output(res).getvalue() expected = [{'a': 1, 'b': date.today()}] self.assertEqual(res, json.dumps(expected, cls=DjangoJSONEncoder))
def test_writing_json(self): res = QueryResult(SimpleQueryFactory(sql='select 1 as "a", 2 as ""').sql, connections[CONN]) res.execute_query() res.process() res._data = [[1, None], [u"Jenét", '1']] res = JSONExporter(query=None)._get_output(res).getvalue() expected = [{'a': 1, '': None}, {'a': 'Jenét', '': '1'}] self.assertEqual(res, json.dumps(expected))