2
0

test_web.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # test_web.py -- Compatibility tests for the git web server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  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
  8. # the License.
  9. #
  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.
  14. #
  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,
  18. # MA 02110-1301, USA.
  19. """Compatibility tests between Dulwich and the cgit HTTP server.
  20. warning: these tests should be fairly stable, but when writing/debugging new
  21. tests, deadlocks may freeze the test process such that it cannot be
  22. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  23. """
  24. import threading
  25. from wsgiref import simple_server
  26. from dulwich.server import (
  27. DictBackend,
  28. )
  29. from dulwich.tests import (
  30. SkipTest,
  31. )
  32. from dulwich.web import (
  33. make_wsgi_chain,
  34. HTTPGitApplication,
  35. WSGIRequestHandlerLogger,
  36. WSGIServerLogger,
  37. )
  38. from dulwich.tests.compat.server_utils import (
  39. ServerTests,
  40. NoSideBand64kReceivePackHandler,
  41. )
  42. from dulwich.tests.compat.utils import (
  43. CompatTestCase,
  44. )
  45. class WebTests(ServerTests):
  46. """Base tests for web server tests.
  47. Contains utility and setUp/tearDown methods, but does non inherit from
  48. TestCase so tests are not automatically run.
  49. """
  50. protocol = 'http'
  51. def _start_server(self, repo):
  52. backend = DictBackend({'/': repo})
  53. app = self._make_app(backend)
  54. dul_server = simple_server.make_server(
  55. 'localhost', 0, app, server_class=WSGIServerLogger,
  56. handler_class=WSGIRequestHandlerLogger)
  57. self.addCleanup(dul_server.shutdown)
  58. self.addCleanup(dul_server.server_close)
  59. threading.Thread(target=dul_server.serve_forever).start()
  60. self._server = dul_server
  61. _, port = dul_server.socket.getsockname()
  62. return port
  63. class SmartWebTestCase(WebTests, CompatTestCase):
  64. """Test cases for smart HTTP server.
  65. This server test case does not use side-band-64k in git-receive-pack.
  66. """
  67. min_git_version = (1, 6, 6)
  68. def _handlers(self):
  69. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  70. def _check_app(self, app):
  71. receive_pack_handler_cls = app.handlers['git-receive-pack']
  72. caps = receive_pack_handler_cls.capabilities()
  73. self.assertFalse('side-band-64k' in caps)
  74. def _make_app(self, backend):
  75. app = make_wsgi_chain(backend, handlers=self._handlers())
  76. to_check = app
  77. # peel back layers until we're at the base application
  78. while not issubclass(to_check.__class__, HTTPGitApplication):
  79. to_check = to_check.app
  80. self._check_app(to_check)
  81. return app
  82. class SmartWebSideBand64kTestCase(SmartWebTestCase):
  83. """Test cases for smart HTTP server with side-band-64k support."""
  84. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  85. min_git_version = (1, 7, 0, 2)
  86. def _handlers(self):
  87. return None # default handlers include side-band-64k
  88. def _check_app(self, app):
  89. receive_pack_handler_cls = app.handlers['git-receive-pack']
  90. caps = receive_pack_handler_cls.capabilities()
  91. self.assertTrue('side-band-64k' in caps)
  92. class DumbWebTestCase(WebTests, CompatTestCase):
  93. """Test cases for dumb HTTP server."""
  94. def _make_app(self, backend):
  95. return make_wsgi_chain(backend, dumb=True)
  96. def test_push_to_dulwich(self):
  97. # Note: remove this if dulwich implements dumb web pushing.
  98. raise SkipTest('Dumb web pushing not supported.')
  99. def test_push_to_dulwich_remove_branch(self):
  100. # Note: remove this if dumb pushing is supported
  101. raise SkipTest('Dumb web pushing not supported.')
  102. def test_new_shallow_clone_from_dulwich(self):
  103. # Note: remove this if C git and dulwich implement dumb web shallow
  104. # clones.
  105. raise SkipTest('Dumb web shallow cloning not supported.')
  106. def test_fetch_same_depth_into_shallow_clone_from_dulwich(self):
  107. # Note: remove this if C git and dulwich implement dumb web shallow
  108. # clones.
  109. raise SkipTest('Dumb web shallow cloning not supported.')
  110. def test_fetch_full_depth_into_shallow_clone_from_dulwich(self):
  111. # Note: remove this if C git and dulwich implement dumb web shallow
  112. # clones.
  113. raise SkipTest('Dumb web shallow cloning not supported.')