def test_has_form(self): req = HttpRequest(ENVIRON) self.assertTrue(req._has_form()) env = ENVIRON.copy() env['HTTP_CONTENT_TYPE'] = "application/json" req = HttpRequest(env) self.assertFalse(req._has_form())
def test_maybe_init_post(self): req = HttpRequest(ENVIRON) env = ENVIRON.copy() loop = asyncio.new_event_loop() stream = asyncio.StreamReader(loop=loop) env['wsgi.input'] = stream req = HttpRequest(env) task = asyncio.Task(req._maybe_init_post(), loop=loop) def feed(): stream.feed_data(b'foo=bar&baz=far') stream.feed_eof() loop.call_soon(feed) loop.run_until_complete(task) self.assertEqual(req.POST, MultiDict(foo=['bar'], baz=['far'])) task = asyncio.Task(req._maybe_init_post(), loop=loop) def feed(): stream.feed_data(b'foo=bar&baz=far') stream.feed_eof() loop.call_soon(feed) loop.run_until_complete(task) env['HTTP_CONTENT_TYPE'] = 'application/json' req = HttpRequest(env) task = asyncio.Task(req._maybe_init_post(), loop=loop) loop.call_soon(feed) loop.run_until_complete(task) self.assertEqual(req.POST, MultiDict())