34
class FakeConfig(object):
36
def gpg_signing_key(self):
37
return "amy@example.com"
39
def gpg_signing_command(self):
42
def acceptable_keys(self):
46
class TestCommandLine(TestCase):
37
class FakeConfig(config.Stack):
40
store = config.IniFileStore()
41
store._load_from_string('''
42
gpg_signing_key=amy@example.com
43
gpg_signing_command=false''')
44
super(FakeConfig, self).__init__([store.get_sections])
47
class TestCommandLine(tests.TestCase):
50
super(TestCommandLine, self).setUp()
51
self.my_gpg = gpg.GPGStrategy(FakeConfig())
48
53
def test_signing_command_line(self):
49
my_gpg = gpg.GPGStrategy(FakeConfig())
50
54
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
51
my_gpg._command_line())
55
self.my_gpg._command_line())
53
57
def test_checks_return_code(self):
54
58
# This test needs a unix like platform - one with 'false' to run.
55
59
# if you have one, please make this work :)
56
my_gpg = gpg.GPGStrategy(FakeConfig())
57
self.assertRaises(errors.SigningFailed, my_gpg.sign, 'content')
60
self.assertRaises(errors.SigningFailed, self.my_gpg.sign, 'content')
59
62
def assertProduces(self, content):
60
63
# This needs a 'cat' command or similar to work.
61
my_gpg = gpg.GPGStrategy(FakeConfig())
62
64
if sys.platform == 'win32':
63
65
# Windows doesn't come with cat, and we don't require it
64
66
# so lets try using python instead.
65
67
# But stupid windows and line-ending conversions.
66
68
# It is too much work to make sys.stdout be in binary mode.
67
69
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
68
my_gpg._command_line = lambda:[sys.executable, '-c',
70
self.my_gpg._command_line = lambda:[sys.executable, '-c',
69
71
'import sys; sys.stdout.write(sys.stdin.read())']
70
72
new_content = content.replace('\n', '\r\n')
72
self.assertEqual(new_content, my_gpg.sign(content))
74
self.assertEqual(new_content, self.my_gpg.sign(content))
74
my_gpg._command_line = lambda:['cat', '-']
75
self.assertEqual(content, my_gpg.sign(content))
76
self.my_gpg._command_line = lambda:['cat', '-']
77
self.assertEqual(content, self.my_gpg.sign(content))
77
79
def test_returns_output(self):
78
80
content = "some content\nwith newlines\n"