Пример #1
0
 def test_simple_json_as_list(self):
     response = wsgi.Json({'bla': 'foo'}, as_list=True)
     self.assertEqual(len(response.children), 1)
     self.assertEqual(response.content_type,
                      'application/json; charset=utf-8')
     self.assertTrue(response.as_list)
     self.assertEqual(response.render(), json.dumps([{'bla': 'foo'}]))
Пример #2
0
 def test_json_with_async_string(self):
     astr = wsgi.String('ciao')
     response = wsgi.Json({'bla': astr})
     self.assertEqual(len(response.children), 1)
     self.assertEqual(response.content_type,
                      'application/json; charset=utf-8')
     self.assertEqual(response.render(), json.dumps({'bla': 'ciao'}))
Пример #3
0
 async def test_json_with_async_string2(self):
     d = Future()
     astr = wsgi.String(d)
     response = wsgi.Json({'bla': astr})
     self.assertEqual(len(response.children), 1)
     result = response.render()
     self.assertIsInstance(result, Future)
     d.set_result('ciao')
     result = await result
     self.assertEqual(result, json.dumps({'bla': 'ciao'}))
Пример #4
0
 def test_json_with_async_string2(self):
     d = Deferred()
     astr = wsgi.AsyncString(d)
     response = wsgi.Json({'bla': astr})
     self.assertEqual(len(response.children), 1)
     result = response.render()
     self.assertIsInstance(result, Deferred)
     d.callback('ciao')
     result = yield result
     self.assertEqual(result, json.dumps({'bla': 'ciao'}))