gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / dulwich / tests / compat / test_web.py @ 959
History | View | Annotate | Download (7.12 KB)
1 |
# test_web.py -- Compatibility tests for the git web server.
|
---|---|
2 |
# Copyright (C) 2010 Google, Inc.
|
3 |
#
|
4 |
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
|
5 |
# General Public License as public by the Free Software Foundation; version 2.0
|
6 |
# or (at your option) any later version. You can redistribute it and/or
|
7 |
# modify it under the terms of either of these two licenses.
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
#
|
15 |
# You should have received a copy of the licenses; if not, see
|
16 |
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
|
17 |
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
|
18 |
# License, Version 2.0.
|
19 |
#
|
20 |
|
21 |
"""Compatibility tests between Dulwich and the cgit HTTP server.
|
22 |
|
23 |
warning: these tests should be fairly stable, but when writing/debugging new
|
24 |
tests, deadlocks may freeze the test process such that it cannot be
|
25 |
Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
|
26 |
"""
|
27 |
|
28 |
import threading |
29 |
from wsgiref import simple_server |
30 |
import sys |
31 |
|
32 |
from dulwich.server import ( |
33 |
DictBackend, |
34 |
UploadPackHandler, |
35 |
ReceivePackHandler, |
36 |
) |
37 |
from dulwich.tests import ( |
38 |
SkipTest, |
39 |
skipIf, |
40 |
) |
41 |
from dulwich.web import ( |
42 |
make_wsgi_chain, |
43 |
HTTPGitApplication, |
44 |
WSGIRequestHandlerLogger, |
45 |
WSGIServerLogger, |
46 |
) |
47 |
|
48 |
from dulwich.tests.compat.server_utils import ( |
49 |
ServerTests, |
50 |
NoSideBand64kReceivePackHandler, |
51 |
) |
52 |
from dulwich.tests.compat.utils import ( |
53 |
CompatTestCase, |
54 |
) |
55 |
|
56 |
|
57 |
@skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.') |
58 |
class WebTests(ServerTests): |
59 |
"""Base tests for web server tests.
|
60 |
|
61 |
Contains utility and setUp/tearDown methods, but does non inherit from
|
62 |
TestCase so tests are not automatically run.
|
63 |
"""
|
64 |
|
65 |
protocol = 'http'
|
66 |
|
67 |
def _start_server(self, repo): |
68 |
backend = DictBackend({'/': repo})
|
69 |
app = self._make_app(backend)
|
70 |
dul_server = simple_server.make_server( |
71 |
'localhost', 0, app, server_class=WSGIServerLogger, |
72 |
handler_class=WSGIRequestHandlerLogger) |
73 |
self.addCleanup(dul_server.shutdown)
|
74 |
self.addCleanup(dul_server.server_close)
|
75 |
threading.Thread(target=dul_server.serve_forever).start() |
76 |
self._server = dul_server
|
77 |
_, port = dul_server.socket.getsockname() |
78 |
return port
|
79 |
|
80 |
|
81 |
@skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.') |
82 |
class SmartWebTestCase(WebTests, CompatTestCase): |
83 |
"""Test cases for smart HTTP server.
|
84 |
|
85 |
This server test case does not use side-band-64k in git-receive-pack.
|
86 |
"""
|
87 |
|
88 |
min_git_version = (1, 6, 6) |
89 |
|
90 |
def _handlers(self): |
91 |
return {b'git-receive-pack': NoSideBand64kReceivePackHandler} |
92 |
|
93 |
def _check_app(self, app): |
94 |
receive_pack_handler_cls = app.handlers[b'git-receive-pack']
|
95 |
caps = receive_pack_handler_cls.capabilities() |
96 |
self.assertNotIn(b'side-band-64k', caps) |
97 |
|
98 |
def _make_app(self, backend): |
99 |
app = make_wsgi_chain(backend, handlers=self._handlers())
|
100 |
to_check = app |
101 |
# peel back layers until we're at the base application
|
102 |
while not issubclass(to_check.__class__, HTTPGitApplication): |
103 |
to_check = to_check.app |
104 |
self._check_app(to_check)
|
105 |
return app
|
106 |
|
107 |
|
108 |
def patch_capabilities(handler, caps_removed): |
109 |
# Patch a handler's capabilities by specifying a list of them to be
|
110 |
# removed, and return the original classmethod for restoration.
|
111 |
original_capabilities = handler.capabilities |
112 |
filtered_capabilities = tuple(
|
113 |
i for i in original_capabilities() if i not in caps_removed) |
114 |
def capabilities(cls): |
115 |
return filtered_capabilities
|
116 |
handler.capabilities = classmethod(capabilities)
|
117 |
return original_capabilities
|
118 |
|
119 |
|
120 |
@skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.') |
121 |
class SmartWebSideBand64kTestCase(SmartWebTestCase): |
122 |
"""Test cases for smart HTTP server with side-band-64k support."""
|
123 |
|
124 |
# side-band-64k in git-receive-pack was introduced in git 1.7.0.2
|
125 |
min_git_version = (1, 7, 0, 2) |
126 |
|
127 |
def setUp(self): |
128 |
self.o_uph_cap = patch_capabilities(UploadPackHandler, (b"no-done",)) |
129 |
self.o_rph_cap = patch_capabilities(ReceivePackHandler, (b"no-done",)) |
130 |
super(SmartWebSideBand64kTestCase, self).setUp() |
131 |
|
132 |
def tearDown(self): |
133 |
super(SmartWebSideBand64kTestCase, self).tearDown() |
134 |
UploadPackHandler.capabilities = self.o_uph_cap
|
135 |
ReceivePackHandler.capabilities = self.o_rph_cap
|
136 |
|
137 |
def _handlers(self): |
138 |
return None # default handlers include side-band-64k |
139 |
|
140 |
def _check_app(self, app): |
141 |
receive_pack_handler_cls = app.handlers[b'git-receive-pack']
|
142 |
caps = receive_pack_handler_cls.capabilities() |
143 |
self.assertIn(b'side-band-64k', caps) |
144 |
self.assertNotIn(b'no-done', caps) |
145 |
|
146 |
|
147 |
class SmartWebSideBand64kNoDoneTestCase(SmartWebTestCase): |
148 |
"""Test cases for smart HTTP server with side-band-64k and no-done
|
149 |
support.
|
150 |
"""
|
151 |
|
152 |
# no-done was introduced in git 1.7.4
|
153 |
min_git_version = (1, 7, 4) |
154 |
|
155 |
def _handlers(self): |
156 |
return None # default handlers include side-band-64k |
157 |
|
158 |
def _check_app(self, app): |
159 |
receive_pack_handler_cls = app.handlers[b'git-receive-pack']
|
160 |
caps = receive_pack_handler_cls.capabilities() |
161 |
self.assertIn(b'side-band-64k', caps) |
162 |
self.assertIn(b'no-done', caps) |
163 |
|
164 |
|
165 |
@skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.') |
166 |
class DumbWebTestCase(WebTests, CompatTestCase): |
167 |
"""Test cases for dumb HTTP server."""
|
168 |
|
169 |
def _make_app(self, backend): |
170 |
return make_wsgi_chain(backend, dumb=True) |
171 |
|
172 |
def test_push_to_dulwich(self): |
173 |
# Note: remove this if dulwich implements dumb web pushing.
|
174 |
raise SkipTest('Dumb web pushing not supported.') |
175 |
|
176 |
def test_push_to_dulwich_remove_branch(self): |
177 |
# Note: remove this if dumb pushing is supported
|
178 |
raise SkipTest('Dumb web pushing not supported.') |
179 |
|
180 |
def test_new_shallow_clone_from_dulwich(self): |
181 |
# Note: remove this if C git and dulwich implement dumb web shallow
|
182 |
# clones.
|
183 |
raise SkipTest('Dumb web shallow cloning not supported.') |
184 |
|
185 |
def test_shallow_clone_from_git_is_identical(self): |
186 |
# Note: remove this if C git and dulwich implement dumb web shallow
|
187 |
# clones.
|
188 |
raise SkipTest('Dumb web shallow cloning not supported.') |
189 |
|
190 |
def test_fetch_same_depth_into_shallow_clone_from_dulwich(self): |
191 |
# Note: remove this if C git and dulwich implement dumb web shallow
|
192 |
# clones.
|
193 |
raise SkipTest('Dumb web shallow cloning not supported.') |
194 |
|
195 |
def test_fetch_full_depth_into_shallow_clone_from_dulwich(self): |
196 |
# Note: remove this if C git and dulwich implement dumb web shallow
|
197 |
# clones.
|
198 |
raise SkipTest('Dumb web shallow cloning not supported.') |
199 |
|
200 |
def test_push_to_dulwich_issue_88_standard(self): |
201 |
raise SkipTest('Dumb web pushing not supported.') |
202 |
|