test_web.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. threading.Thread(target=dul_server.serve_forever).start()
  59. self._server = dul_server
  60. _, port = dul_server.socket.getsockname()
  61. return port
  62. class SmartWebTestCase(WebTests, CompatTestCase):
  63. """Test cases for smart HTTP server.
  64. This server test case does not use side-band-64k in git-receive-pack.
  65. """
  66. min_git_version = (1, 6, 6)
  67. def _handlers(self):
  68. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  69. def _check_app(self, app):
  70. receive_pack_handler_cls = app.handlers['git-receive-pack']
  71. caps = receive_pack_handler_cls.capabilities()
  72. self.assertFalse('side-band-64k' in caps)
  73. def _make_app(self, backend):
  74. app = make_wsgi_chain(backend, handlers=self._handlers())
  75. to_check = app
  76. # peel back layers until we're at the base application
  77. while not issubclass(to_check.__class__, HTTPGitApplication):
  78. to_check = to_check.app
  79. self._check_app(to_check)
  80. return app
  81. class SmartWebSideBand64kTestCase(SmartWebTestCase):
  82. """Test cases for smart HTTP server with side-band-64k support."""
  83. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  84. min_git_version = (1, 7, 0, 2)
  85. def _handlers(self):
  86. return None # default handlers include side-band-64k
  87. def _check_app(self, app):
  88. receive_pack_handler_cls = app.handlers['git-receive-pack']
  89. caps = receive_pack_handler_cls.capabilities()
  90. self.assertTrue('side-band-64k' in caps)
  91. class DumbWebTestCase(WebTests, CompatTestCase):
  92. """Test cases for dumb HTTP server."""
  93. def _make_app(self, backend):
  94. return make_wsgi_chain(backend, dumb=True)
  95. def test_push_to_dulwich(self):
  96. # Note: remove this if dulwich implements dumb web pushing.
  97. raise SkipTest('Dumb web pushing not supported.')
  98. def test_push_to_dulwich_remove_branch(self):
  99. # Note: remove this if dumb pushing is supported
  100. raise SkipTest('Dumb web pushing not supported.')
  101. def test_new_shallow_clone_from_dulwich(self):
  102. # Note: remove this if C git and dulwich implement dumb web shallow
  103. # clones.
  104. raise SkipTest('Dumb web shallow cloning not supported.')
  105. def test_fetch_same_depth_into_shallow_clone_from_dulwich(self):
  106. # Note: remove this if C git and dulwich implement dumb web shallow
  107. # clones.
  108. raise SkipTest('Dumb web shallow cloning not supported.')
  109. def test_fetch_full_depth_into_shallow_clone_from_dulwich(self):
  110. # Note: remove this if C git and dulwich implement dumb web shallow
  111. # clones.
  112. raise SkipTest('Dumb web shallow cloning not supported.')