5 from cam import openssl_wrap
8 class PopenStub(object):
10 def __init__(self, stdout='', returncode=0):
12 self.returncode = returncode
14 def communicate(self):
15 return self.stdout, 'unused'
18 class OpensslWrapTest(unittest.TestCase):
28 self.mox.StubOutWithMock(subprocess, 'Popen', use_mock_anything=True)
29 pipe_stub = PopenStub(stdout='output')
30 subprocess.Popen(['openssl', 'test'], stdout=subprocess.PIPE
31 ).AndReturn(pipe_stub)
33 result = openssl_wrap.run('test')
34 self.assertEquals('output', result)
36 def test_run_fails(self):
37 self.mox.StubOutWithMock(subprocess, 'Popen', use_mock_anything=True)
38 pipe_stub = PopenStub(returncode=1)
39 subprocess.Popen(['openssl', 'test'], stdout=subprocess.PIPE
40 ).AndReturn(pipe_stub)
43 result = openssl_wrap.run('test')
44 self.assertRaises(openssl_wrap.CommandError, r)
46 def test_run_with_config(self):
47 self.mox.StubOutWithMock(subprocess, 'Popen', use_mock_anything=True)
48 pipe_stub = PopenStub(stdout='output')
49 subprocess.Popen(['openssl', 'test', '-config', 'conf', '-batch', 'arg'],
50 stdout=subprocess.PIPE).AndReturn(pipe_stub)
52 result = openssl_wrap.run_with_config('conf', 'test', 'arg')
55 if __name__ == '__main__':