test_porcelain.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # test_porcelain .py -- Tests for dulwich.porcelain/CGit compatibility
  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. """Compatibility tests for dulwich.porcelain."""
  21. import os
  22. import platform
  23. import sys
  24. from unittest import skipIf
  25. from dulwich import porcelain
  26. from dulwich.tests.compat.utils import CompatTestCase, run_git_or_fail
  27. from dulwich.tests.test_porcelain import PorcelainGpgTestCase
  28. from dulwich.tests.utils import build_commit_graph
  29. @skipIf(platform.python_implementation() == "PyPy" or sys.platform == "win32", "gpgme not easily available or supported on Windows and PyPy")
  30. class TagCreateSignTestCase(PorcelainGpgTestCase, CompatTestCase):
  31. def setUp(self):
  32. super().setUp()
  33. def test_sign(self):
  34. # Test that dulwich signatures can be verified by CGit
  35. c1, c2, c3 = build_commit_graph(
  36. self.repo.object_store, [[1], [2, 1], [3, 1, 2]]
  37. )
  38. self.repo.refs[b"HEAD"] = c3.id
  39. cfg = self.repo.get_config()
  40. cfg.set(("user",), "signingKey", PorcelainGpgTestCase.DEFAULT_KEY_ID)
  41. self.import_default_key()
  42. porcelain.tag_create(
  43. self.repo.path,
  44. b"tryme",
  45. b"foo <foo@bar.com>",
  46. b"bar",
  47. annotated=True,
  48. sign=True,
  49. )
  50. run_git_or_fail(
  51. [
  52. f"--git-dir={self.repo.controldir()}",
  53. "tag",
  54. "-v",
  55. "tryme"
  56. ],
  57. env={'GNUPGHOME': os.environ['GNUPGHOME']},
  58. )
  59. def test_verify(self):
  60. # Test that CGit signatures can be verified by dulwich
  61. c1, c2, c3 = build_commit_graph(
  62. self.repo.object_store, [[1], [2, 1], [3, 1, 2]]
  63. )
  64. self.repo.refs[b"HEAD"] = c3.id
  65. self.import_default_key()
  66. run_git_or_fail(
  67. [
  68. f"--git-dir={self.repo.controldir()}",
  69. "tag",
  70. "-u",
  71. PorcelainGpgTestCase.DEFAULT_KEY_ID,
  72. "-m",
  73. "foo",
  74. "verifyme",
  75. ],
  76. env={
  77. 'GNUPGHOME': os.environ['GNUPGHOME'],
  78. 'GIT_COMMITTER_NAME': 'Joe Example',
  79. 'GIT_COMMITTER_EMAIL': 'joe@example.com',
  80. },
  81. )
  82. tag = self.repo[b"refs/tags/verifyme"]
  83. self.assertNotEqual(tag.signature, None)
  84. tag.verify()