Browse Source

add tests for db.changepassword

oz123 11 năm trước cách đây
mục cha
commit
75299c2ee8
2 tập tin đã thay đổi với 18 bổ sung2 xóa
  1. 8 2
      pwman/tests/db_tests.py
  2. 10 0
      pwman/ui/tools.py

+ 8 - 2
pwman/tests/db_tests.py

@@ -1,7 +1,8 @@
 import os
 import os.path
 import sys
-from pwman.ui.tools import DummyCallback
+from pwman.ui.tools import DummyCallback, DummyCallback2
+
 
 if 'darwin' in sys.platform:  # pragma: no cover
     from pwman.ui.mac import PwmanCliMac as PwmanCliOld
@@ -20,7 +21,7 @@ import pwman.util.config as config
 import pwman.data.factory
 from pwman.data.nodes import NewNode
 from pwman.data.tags import Tag, TagNew
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto import CryptoEngine, CryptoBadKeyException
 from pwman import which, default_config
 import unittest
 
@@ -105,6 +106,11 @@ class DBTests(unittest.TestCase):
         got_tags = self.tester.cli._tags(enc)
         self.assertEqual(2, len(got_tags))
 
+    def test_change_pass(self):
+        self.tester.cli.callback = DummyCallback2
+        self.assertRaises(CryptoBadKeyException,
+                          self.tester.cli._db.changepassword)
+
 
 class CLITests(unittest.TestCase):
     """

+ 10 - 0
pwman/ui/tools.py

@@ -390,6 +390,7 @@ class CLICallback(Callback):
     def getsecret(self, question):
         return getpass.getpass(question + ":")
 
+
 class DummyCallback(Callback):
 
     def getinput(self, question):
@@ -397,3 +398,12 @@ class DummyCallback(Callback):
 
     def getsecret(self, question):
         return '12345'
+
+
+class DummyCallback2(Callback):
+
+    def getinput(self, question):
+        return 'newsecret'
+
+    def getsecret(self, question):
+        return 'newsecret'