-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_distribute.py
58 lines (51 loc) · 1.89 KB
/
test_distribute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""This module tests the distribute module"""
import builtins
import unittest
import mock
from libpkpass.commands.cli import Cli
from libpkpass.errors import CliArgumentError, DecryptionError
from .basetest.basetest import patch_args, ERROR_MSGS
class DistributeTests(unittest.TestCase):
"""This class tests the distribute class"""
def test_recipient_not_in_database(self):
"""Test what happens with a recipient is not within the appropriate directory"""
with self.assertRaises(CliArgumentError) as context:
with patch_args(
subparser_name="distribute",
identity="bleh",
nopassphrase="true",
pwname="test",
):
"".join(Cli().run())
self.assertEqual(context.exception.msg, ERROR_MSGS["rep"])
def test_distribute_cli_error(self):
"""Test what happens with pwname is not supplied"""
with self.assertRaises(CliArgumentError) as context:
with patch_args(
subparser_name="distribute",
identity="r1",
nopassphrase="true",
pwname=None,
):
"".join(Cli().run())
self.assertEqual(context.exception.msg, ERROR_MSGS["pwname"])
def test_distribute_success(self):
"""Test a successful distribute"""
ret = True
try:
with patch_args(
subparser_name="distribute",
identity="r1",
nopassphrase="true",
pwname="test",
escrow_users="r2,r3,r4",
min_escrow=2,
):
with mock.patch.object(builtins, "input", lambda _: "y"):
"".join(Cli().run())
except DecryptionError:
ret = False
self.assertTrue(ret)
if __name__ == "__main__":
unittest.main()