2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005 Canonical Ltd
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
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 |
||
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
22 |
from bzrlib import ( |
23 |
gpg, |
|
24 |
tests, |
|
25 |
)
|
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
26 |
from bzrlib.testament import Testament |
27 |
from bzrlib.workingtree import WorkingTree |
|
28 |
||
29 |
||
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
30 |
class SignMyCommits(tests.TestCaseWithTransport): |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
31 |
|
32 |
def monkey_patch_gpg(self): |
|
33 |
"""Monkey patch the gpg signing strategy to be a loopback.
|
|
34 |
||
35 |
This also registers the cleanup, so that we will revert to
|
|
36 |
the original gpg strategy when done.
|
|
37 |
"""
|
|
38 |
# monkey patch gpg signing mechanism
|
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
39 |
self.overrideAttr(gpg, 'GPGStrategy', gpg.LoopbackGPGStrategy) |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
40 |
|
1185.79.3
by John Arbash Meinel
cleanups from Robert |
41 |
def setup_tree(self, location='.'): |
42 |
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. |
43 |
wt.commit("base A", allow_pointless=True, rev_id='A') |
44 |
wt.commit("base B", allow_pointless=True, rev_id='B') |
|
45 |
wt.commit("base C", allow_pointless=True, rev_id='C') |
|
46 |
wt.commit("base D", allow_pointless=True, rev_id='D', |
|
47 |
committer='Alternate <alt@foo.com>') |
|
48 |
||
49 |
return wt |
|
50 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
51 |
def assertUnsigned(self, repo, revision_id): |
52 |
"""Assert that revision_id is not signed in repo."""
|
|
53 |
self.assertFalse(repo.has_signature_for_revision_id(revision_id)) |
|
54 |
||
55 |
def assertSigned(self, repo, revision_id): |
|
56 |
"""Assert that revision_id is signed in repo."""
|
|
57 |
self.assertTrue(repo.has_signature_for_revision_id(revision_id)) |
|
58 |
||
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
59 |
def test_sign_my_commits(self): |
60 |
#Test re signing of data.
|
|
61 |
wt = self.setup_tree() |
|
62 |
repo = wt.branch.repository |
|
63 |
||
64 |
self.monkey_patch_gpg() |
|
65 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
66 |
self.assertUnsigned(repo, 'A') |
67 |
self.assertUnsigned(repo, 'B') |
|
68 |
self.assertUnsigned(repo, 'C') |
|
69 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
70 |
|
71 |
self.run_bzr('sign-my-commits') |
|
72 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
73 |
self.assertSigned(repo, 'A') |
74 |
self.assertSigned(repo, 'B') |
|
75 |
self.assertSigned(repo, 'C') |
|
76 |
self.assertUnsigned(repo, 'D') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
77 |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
78 |
def test_sign_my_commits_location(self): |
1185.79.3
by John Arbash Meinel
cleanups from Robert |
79 |
wt = self.setup_tree('other') |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
80 |
repo = wt.branch.repository |
81 |
||
82 |
self.monkey_patch_gpg() |
|
83 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
84 |
self.run_bzr('sign-my-commits other') |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
85 |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
86 |
self.assertSigned(repo, 'A') |
87 |
self.assertSigned(repo, 'B') |
|
88 |
self.assertSigned(repo, 'C') |
|
89 |
self.assertUnsigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
90 |
|
91 |
def test_sign_diff_committer(self): |
|
92 |
wt = self.setup_tree() |
|
93 |
repo = wt.branch.repository |
|
94 |
||
95 |
self.monkey_patch_gpg() |
|
96 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
97 |
self.run_bzr(['sign-my-commits', '.', 'Alternate <alt@foo.com>']) |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
98 |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
99 |
self.assertUnsigned(repo, 'A') |
100 |
self.assertUnsigned(repo, 'B') |
|
101 |
self.assertUnsigned(repo, 'C') |
|
102 |
self.assertSigned(repo, 'D') |
|
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
103 |
|
104 |
def test_sign_dry_run(self): |
|
105 |
wt = self.setup_tree() |
|
106 |
repo = wt.branch.repository |
|
107 |
||
108 |
self.monkey_patch_gpg() |
|
109 |
||
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
110 |
out = self.run_bzr('sign-my-commits --dry-run')[0] |
1185.78.6
by John Arbash Meinel
Adding sign-my-commits as a builtin, along with some simple tests. |
111 |
|
112 |
self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
113 |
self.assertUnsigned(repo, 'A') |
114 |
self.assertUnsigned(repo, 'B') |
|
115 |
self.assertUnsigned(repo, 'C') |
|
116 |
self.assertUnsigned(repo, 'D') |