Esempio n. 1
0
 def test_lifespan_invalid(self):
     app = async_asgi.ASGIApp('eio')
     handler = app({'type': 'lifespan'})
     receive = AsyncMock(return_value={'type': 'lifespan.foo'})
     send = AsyncMock()
     _run(handler(receive, send))
     send.mock.assert_not_called()
Esempio n. 2
0
 def test_lifespan_shutdown(self):
     app = async_asgi.ASGIApp('eio')
     handler = app({'type': 'lifespan'})
     receive = AsyncMock(return_value={'type': 'lifespan.shutdown'})
     send = AsyncMock()
     _run(handler(receive, send))
     send.mock.assert_called_once_with(
         {'type': 'lifespan.shutdown.complete'})
Esempio n. 3
0
 def test_engineio_routing(self):
     mock_server = mock.MagicMock()
     mock_server.handle_request = AsyncMock()
     app = async_asgi.ASGIApp(mock_server)
     scope = {'type': 'http', 'path': '/engine.io/'}
     handler = app(scope)
     _run(handler('receive', 'send'))
     mock_server.handle_request.mock.assert_called_once_with(
         scope, 'receive', 'send')
Esempio n. 4
0
 def test_create_app(self):
     app = async_asgi.ASGIApp('eio',
                              'other_app',
                              static_files='static_files',
                              engineio_path='/foo')
     self.assertEqual(app.engineio_server, 'eio')
     self.assertEqual(app.other_asgi_app, 'other_app')
     self.assertEqual(app.static_files, 'static_files')
     self.assertEqual(app.engineio_path, 'foo'),
Esempio n. 5
0
 def test_not_found(self):
     app = async_asgi.ASGIApp('eio')
     handler = app({'type': 'http', 'path': '/foo'})
     receive = AsyncMock(return_value={'type': 'http.request'})
     send = AsyncMock()
     _run(handler(receive, send))
     send.mock.assert_any_call({
         'type': 'http.response.start',
         'status': 404,
         'headers': [(b'Content-Type', b'text/plain')]
     })
     send.mock.assert_any_call({
         'type': 'http.response.body',
         'body': b'not found'
     })
Esempio n. 6
0
 def test_static_file_routing(self):
     root_dir = os.path.dirname(__file__)
     app = async_asgi.ASGIApp('eio',
                              static_files={
                                  '/foo': {
                                      'content_type': 'text/html',
                                      'filename': root_dir + '/index.html'
                                  }
                              })
     handler = app({'type': 'http', 'path': '/foo'})
     receive = AsyncMock(return_value={'type': 'http.request'})
     send = AsyncMock()
     _run(handler(receive, send))
     send.mock.assert_called_with({
         'type': 'http.response.body',
         'body': b'<html></html>\n'
     })
Esempio n. 7
0
 def test_other_app_routing(self):
     other_app = mock.MagicMock()
     app = async_asgi.ASGIApp('eio', other_app)
     scope = {'type': 'http', 'path': '/foo'}
     app(scope)
     other_app.assert_called_once_with(scope)