1 # test_web.py -- Compatibilty 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 """Compatibilty 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.web import (
37 from server_utils import (
47 if getattr(simple_server.WSGIServer, 'shutdown', None):
48 WSGIServer = simple_server.WSGIServer
50 class WSGIServer(ShutdownServerMixIn, simple_server.WSGIServer):
51 """Subclass of WSGIServer that can be shut down."""
53 def __init__(self, *args, **kwargs):
54 # BaseServer is old-style so we have to call both __init__s
55 ShutdownServerMixIn.__init__(self)
56 simple_server.WSGIServer.__init__(self, *args, **kwargs)
58 serve = ShutdownServerMixIn.serve_forever
61 class WebTests(ServerTests):
62 """Base tests for web server tests.
64 Contains utility and setUp/tearDown methods, but does non inherit from
65 TestCase so tests are not automatically run.
70 def _start_server(self, repo):
71 app = self._make_app(GitBackend(repo))
72 dul_server = simple_server.make_server('localhost', 0, app,
73 server_class=WSGIServer)
74 threading.Thread(target=dul_server.serve_forever).start()
75 self._server = dul_server
76 _, port = dul_server.socket.getsockname()
80 class SmartWebTestCase(WebTests, CompatTestCase):
81 """Test cases for smart HTTP server."""
83 min_git_version = (1, 6, 6)
87 CompatTestCase.setUp(self)
90 WebTests.tearDown(self)
91 CompatTestCase.tearDown(self)
93 def _make_app(self, backend):
94 return HTTPGitApplication(backend)
96 def test_push_to_dulwich(self):
97 # TODO(dborowitz): enable after merging thin pack fixes.
98 raise SkipTest('Skipping push test due to known pack bug.')
101 class DumbWebTestCase(WebTests, CompatTestCase):
102 """Test cases for dumb HTTP server."""
106 CompatTestCase.setUp(self)
109 WebTests.tearDown(self)
110 CompatTestCase.tearDown(self)
112 def _make_app(self, backend):
113 return HTTPGitApplication(backend, dumb=True)
115 def test_push_to_dulwich(self):
116 # Note: remove this if dumb pushing is supported
117 raise SkipTest('Dumb web pushing not supported.')