<s> import unittest <EOL> import six <EOL> if six . PY3 : <EOL> from unittest import mock <EOL> else : <EOL> import mock <EOL> from engineio import middleware <EOL> class TestMiddleware ( unittest . TestCase ) : <EOL> def test_wsgi_routing ( self ) : <EOL> mock_wsgi_app = mock . MagicMock ( ) <EOL> mock_eio_app = '<STR_LIT:foo>' <EOL> m = middleware . Middleware ( mock_eio_app , mock_wsgi_app ) <EOL> environ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> start_response = "<STR_LIT:foo>" <EOL> m ( environ , start_response ) <EOL> mock_wsgi_app . assert_called_once_with ( environ , start_response ) <EOL> def test_eio_routing ( self ) : <EOL> mock_wsgi_app = '<STR_LIT:foo>' <EOL> mock_eio_app = mock . Mock ( ) <EOL> mock_eio_app . handle_request = mock . MagicMock ( ) <EOL> m = middleware . Middleware ( mock_eio_app , mock_wsgi_app ) <EOL> environ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> start_response = "<STR_LIT:foo>" <EOL> m ( environ , start_response ) <EOL> mock_eio_app . handle_request . assert_called_once_with ( environ , <EOL> start_response ) <EOL> def test_404 ( self ) : <EOL> mock_wsgi_app = None <EOL> mock_eio_app = mock . Mock ( ) <EOL> m = middleware . Middleware ( mock_eio_app , mock_wsgi_app ) <EOL> environ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> start_response = mock . MagicMock ( ) <EOL> r = m ( environ , start_response ) <EOL> self . assertEqual ( r , [ '<STR_LIT>' ] ) <EOL> start_response . assert_called_once_with ( <EOL> "<STR_LIT>" , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_gunicorn_socket ( self ) : <EOL> mock_wsgi_app = None <EOL> mock_eio_app = mock . Mock ( ) <EOL> m = middleware . Middleware ( mock_eio_app , mock_wsgi_app ) <EOL> environ = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> start_response = mock . MagicMock ( ) <EOL> m ( environ , start_response ) <EOL> self . assertIn ( '<STR_LIT>' , environ ) <EOL> self . assertEqual ( environ [ '<STR_LIT>' ] . get_socket ( ) , <NUM_LIT> ) </s>
