1 # test_web.py -- Compatibility tests for the git web server.
2 # Copyright (C) 2010 Google, Inc.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 2
7 # of the License or (at your option) any later version of
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 """Compatibility tests between Dulwich and the cgit HTTP server.
22 Warning: these tests should be fairly stable, but when writing/debugging new
23 tests, deadlocks may freeze the test process such that it cannot be Ctrl-C'ed.
24 On *nix, you can kill the tests with Ctrl-Z, "kill %".
28 from wsgiref import simple_server
30 from dulwich.server import (
33 from dulwich.tests import (
36 from dulwich.web import (
40 from server_utils import (
49 if getattr(simple_server.WSGIServer, 'shutdown', None):
50 WSGIServer = simple_server.WSGIServer
52 class WSGIServer(ShutdownServerMixIn, simple_server.WSGIServer):
53 """Subclass of WSGIServer that can be shut down."""
55 def __init__(self, *args, **kwargs):
56 # BaseServer is old-style so we have to call both __init__s
57 ShutdownServerMixIn.__init__(self)
58 simple_server.WSGIServer.__init__(self, *args, **kwargs)
60 serve = ShutdownServerMixIn.serve_forever
63 class WebTests(ServerTests):
64 """Base tests for web server tests.
66 Contains utility and setUp/tearDown methods, but does non inherit from
67 TestCase so tests are not automatically run.
72 def _start_server(self, repo):
73 backend = DictBackend({'/': repo})
74 app = self._make_app(backend)
75 dul_server = simple_server.make_server('localhost', 0, app,
76 server_class=WSGIServer)
77 threading.Thread(target=dul_server.serve_forever).start()
78 self._server = dul_server
79 _, port = dul_server.socket.getsockname()
83 class SmartWebTestCase(WebTests, CompatTestCase):
84 """Test cases for smart HTTP server."""
86 min_git_version = (1, 6, 6)
90 CompatTestCase.setUp(self)
93 WebTests.tearDown(self)
94 CompatTestCase.tearDown(self)
96 def _make_app(self, backend):
97 return HTTPGitApplication(backend)
100 class DumbWebTestCase(WebTests, CompatTestCase):
101 """Test cases for dumb HTTP server."""
105 CompatTestCase.setUp(self)
108 WebTests.tearDown(self)
109 CompatTestCase.tearDown(self)
111 def _make_app(self, backend):
112 return HTTPGitApplication(backend, dumb=True)
114 def test_push_to_dulwich(self):
115 # Note: remove this if dumb pushing is supported
116 raise TestSkipped('Dumb web pushing not supported.')