2
0

test_web.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 Ctrl-C'ed.
  22. On *nix, 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. TestSkipped,
  31. )
  32. from dulwich.web import (
  33. HTTPGitApplication,
  34. )
  35. from server_utils import (
  36. ServerTests,
  37. ShutdownServerMixIn,
  38. )
  39. from utils import (
  40. CompatTestCase,
  41. )
  42. if getattr(simple_server.WSGIServer, 'shutdown', None):
  43. WSGIServer = simple_server.WSGIServer
  44. else:
  45. class WSGIServer(ShutdownServerMixIn, simple_server.WSGIServer):
  46. """Subclass of WSGIServer that can be shut down."""
  47. def __init__(self, *args, **kwargs):
  48. # BaseServer is old-style so we have to call both __init__s
  49. ShutdownServerMixIn.__init__(self)
  50. simple_server.WSGIServer.__init__(self, *args, **kwargs)
  51. serve = ShutdownServerMixIn.serve_forever
  52. class WebTests(ServerTests):
  53. """Base tests for web server tests.
  54. Contains utility and setUp/tearDown methods, but does non inherit from
  55. TestCase so tests are not automatically run.
  56. """
  57. protocol = 'http'
  58. def _start_server(self, repo):
  59. backend = DictBackend({'/': repo})
  60. app = self._make_app(backend)
  61. dul_server = simple_server.make_server('localhost', 0, app,
  62. server_class=WSGIServer)
  63. threading.Thread(target=dul_server.serve_forever).start()
  64. self._server = dul_server
  65. _, port = dul_server.socket.getsockname()
  66. return port
  67. class SmartWebTestCase(WebTests, CompatTestCase):
  68. """Test cases for smart HTTP server."""
  69. min_git_version = (1, 6, 6)
  70. def setUp(self):
  71. WebTests.setUp(self)
  72. CompatTestCase.setUp(self)
  73. def tearDown(self):
  74. WebTests.tearDown(self)
  75. CompatTestCase.tearDown(self)
  76. def _make_app(self, backend):
  77. return HTTPGitApplication(backend)
  78. class DumbWebTestCase(WebTests, CompatTestCase):
  79. """Test cases for dumb HTTP server."""
  80. def setUp(self):
  81. WebTests.setUp(self)
  82. CompatTestCase.setUp(self)
  83. def tearDown(self):
  84. WebTests.tearDown(self)
  85. CompatTestCase.tearDown(self)
  86. def _make_app(self, backend):
  87. return HTTPGitApplication(backend, dumb=True)
  88. def test_push_to_dulwich(self):
  89. # Note: remove this if dumb pushing is supported
  90. raise TestSkipped('Dumb web pushing not supported.')