1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
# -*- coding: utf-8 -*-
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
3 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
4 |
# This program is free software; you can redistribute it and/or modify
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
8 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
9 |
# This program is distributed in the hope that it will be useful,
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
13 |
#
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
14 |
# You should have received a copy of the GNU General Public License
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
1185.79.3
by John Arbash Meinel
cleanups from Robert |
18 |
"""Black-box tests for bzr sign-my-commits."""
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
19 |
|
20 |
import os |
|
21 |
||
22 |
import bzrlib.gpg |
|
23 |
from bzrlib.testament import Testament |
|
1185.79.3
by John Arbash Meinel
cleanups from Robert |
24 |
from bzrlib.tests import TestCaseWithTransport |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
25 |
from bzrlib.workingtree import WorkingTree |
26 |
||
27 |
||
1185.79.3
by John Arbash Meinel
cleanups from Robert |
28 |
class SignMyCommits(TestCaseWithTransport): |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
29 |
|
30 |
def monkey_patch_gpg(self): |
|
31 |
"""Monkey patch the gpg signing strategy to be a loopback.
|
|
32 |
||
33 |
This also registers the cleanup, so that we will revert to
|
|
34 |
the original gpg strategy when done.
|
|
35 |
"""
|
|
36 |
self._oldstrategy = bzrlib.gpg.GPGStrategy |
|
37 |
||
38 |
# monkey patch gpg signing mechanism
|
|
39 |
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy |
|
40 |
||
41 |
self.addCleanup(self._fix_gpg_strategy) |
|
42 |
||
43 |
def _fix_gpg_strategy(self): |
|
44 |
bzrlib.gpg.GPGStrategy = self._oldstrategy |
|
45 |
||
1185.79.3
by John Arbash Meinel
cleanups from Robert |
46 |
def setup_tree(self, location='.'): |
47 |
wt = self.make_branch_and_tree(location) |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
48 |
wt.commit("base A", allow_pointless=True, rev_id='A') |
49 |
wt.commit("base B", allow_pointless=True, rev_id='B') |
|
50 |
wt.commit("base C", allow_pointless=True, rev_id='C') |
|
51 |
wt.commit("base D", allow_pointless=True, rev_id='D', |
|
52 |
committer='Alternate <alt@foo.com>') |
|
53 |
||
54 |
return wt |
|
55 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
56 |
def assertUnsigned(self, repo, revision_id): |
57 |
"""Assert that revision_id is not signed in repo."""
|
|
58 |
self.assertFalse(repo.has_signature_for_revision_id(revision_id)) |
|
59 |
||
60 |
def assertSigned(self, repo, revision_id): |
|
61 |
"""Assert that revision_id is signed in repo."""
|
|
62 |
self.assertTrue(repo.has_signature_for_revision_id(revision_id)) |
|
63 |
||
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
64 |
def test_sign_my_commits(self): |
65 |
#Test re signing of data.
|
|
66 |
wt = self.setup_tree() |
|
67 |
repo = wt.branch.repository |
|
68 |
||
69 |
self.monkey_patch_gpg() |
|
70 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
71 |
self.assertUnsigned(repo, 'A') |
72 |
self.assertUnsigned(repo, 'B') |
|
73 |
self.assertUnsigned(repo, 'C') |
|
74 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
75 |
|
76 |
self.run_bzr('sign-my-commits') |
|
77 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
78 |
self.assertSigned(repo, 'A') |
79 |
self.assertSigned(repo, 'B') |
|
80 |
self.assertSigned(repo, 'C') |
|
81 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
82 |
|
83 |
def test_sign_my_commits_location(self): |
|
1185.79.3
by John Arbash Meinel
cleanups from Robert |
84 |
wt = self.setup_tree('other') |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
85 |
repo = wt.branch.repository |
86 |
||
87 |
self.monkey_patch_gpg() |
|
88 |
||
89 |
self.run_bzr('sign-my-commits', 'other') |
|
90 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
91 |
self.assertSigned(repo, 'A') |
92 |
self.assertSigned(repo, 'B') |
|
93 |
self.assertSigned(repo, 'C') |
|
94 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
95 |
|
96 |
def test_sign_diff_committer(self): |
|
97 |
wt = self.setup_tree() |
|
98 |
repo = wt.branch.repository |
|
99 |
||
100 |
self.monkey_patch_gpg() |
|
101 |
||
102 |
self.run_bzr('sign-my-commits', '.', 'Alternate <alt@foo.com>') |
|
103 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
104 |
self.assertUnsigned(repo, 'A') |
105 |
self.assertUnsigned(repo, 'B') |
|
106 |
self.assertUnsigned(repo, 'C') |
|
107 |
self.assertSigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
108 |
|
109 |
def test_sign_dry_run(self): |
|
110 |
wt = self.setup_tree() |
|
111 |
repo = wt.branch.repository |
|
112 |
||
113 |
self.monkey_patch_gpg() |
|
114 |
||
115 |
out = self.run_bzr('sign-my-commits', '--dry-run')[0] |
|
116 |
||
117 |
self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
118 |
self.assertUnsigned(repo, 'A') |
119 |
self.assertUnsigned(repo, 'B') |
|
120 |
self.assertUnsigned(repo, 'C') |
|
121 |
self.assertUnsigned(repo, 'D') |