test_web.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # test_web.py -- Compatibilty 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. """Compatibilty 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 sys
  25. import threading
  26. import unittest
  27. from wsgiref import simple_server
  28. import nose
  29. from dulwich.repo import (
  30. Repo,
  31. )
  32. from dulwich.server import (
  33. GitBackend,
  34. )
  35. from dulwich.web import (
  36. HTTPGitApplication,
  37. )
  38. from dulwich.tests.utils import (
  39. open_repo,
  40. tear_down_repo,
  41. )
  42. from server_utils import (
  43. ServerTests,
  44. ShutdownServerMixIn,
  45. )
  46. from utils import (
  47. CompatTestCase,
  48. )
  49. if getattr(simple_server.WSGIServer, 'shutdown', None):
  50. WSGIServer = simple_server.WSGIServer
  51. else:
  52. class WSGIServer(ShutdownServerMixIn, simple_server.WSGIServer):
  53. """Subclass of WSGIServer that can be shut down."""
  54. def __init__(self, *args, **kwargs):
  55. # BaseServer is old-style so we have to call both __init__s
  56. ShutdownServerMixIn.__init__(self)
  57. simple_server.WSGIServer.__init__(self, *args, **kwargs)
  58. serve = ShutdownServerMixIn.serve_forever
  59. class WebTests(ServerTests):
  60. """Base tests for web server tests.
  61. Contains utility and setUp/tearDown methods, but does non inherit from
  62. TestCase so tests are not automatically run.
  63. """
  64. protocol = 'http'
  65. def _start_server(self, repo):
  66. app = self._make_app(GitBackend(repo))
  67. dul_server = simple_server.make_server('localhost', 0, app,
  68. server_class=WSGIServer)
  69. threading.Thread(target=dul_server.serve_forever).start()
  70. self._server = dul_server
  71. _, port = dul_server.socket.getsockname()
  72. return port
  73. class SmartWebTestCase(WebTests, CompatTestCase):
  74. """Test cases for smart HTTP server."""
  75. min_git_version = (1, 6, 6)
  76. def setUp(self):
  77. WebTests.setUp(self)
  78. CompatTestCase.setUp(self)
  79. def tearDown(self):
  80. WebTests.tearDown(self)
  81. CompatTestCase.tearDown(self)
  82. def _make_app(self, backend):
  83. return HTTPGitApplication(backend)
  84. def test_push_to_dulwich(self):
  85. # TODO(dborowitz): enable after merging thin pack fixes.
  86. raise nose.SkipTest('Skipping push test due to known pack bug.')
  87. class DumbWebTestCase(WebTests, CompatTestCase):
  88. """Test cases for dumb HTTP server."""
  89. def setUp(self):
  90. WebTests.setUp(self)
  91. CompatTestCase.setUp(self)
  92. def tearDown(self):
  93. WebTests.tearDown(self)
  94. CompatTestCase.tearDown(self)
  95. def _make_app(self, backend):
  96. return HTTPGitApplication(backend, dumb=True)
  97. def test_push_to_dulwich(self):
  98. # Note: remove this if dumb pushing is supported
  99. raise nose.SkipTest('Dumb web pushing not supported.')