Commits

Jonathan Ballet committed 864ed34

Make all tests automated by mocking the getpass() function

Now, the tests don't ask for passwords anymore, they always use the same (this
can be changed eventually)

Comments (0)

Files changed (2)

keyring/backend.py

 Created by Kang Zhang on 2009-07-09
 """
 
+import getpass
 import os
 import sys
 import ConfigParser
             status = -1
         return status
 
+    def _getpass(self, *args, **kwargs):
+        return getpass.getpass(*args, **kwargs)
+
     def _init_file(self):
         """Init the password file, set the password for it.
         """
 
-        print("Please set a password for your new keyring")
         password = None
         while 1:
             if not password:
-                import getpass
-                password = getpass.getpass()
-                password2 = getpass.getpass('Password (again): ')
+                password = self._getpass("Please set a password for your new keyring")
+                password2 = self._getpass('Password (again): ')
                 if password != password2:
                     sys.stderr.write("Error: Your passwords didn't math\n")
                     password = None
         if not self._check_file():
             self._init_file()
 
-        print "Please input your password for the keyring"
-        import getpass
-        password = getpass.getpass()
+        password = self._getpass("Please input your password for the keyring")
 
         if not self._auth(password):
             sys.stderr.write("Wrong password for the keyring.\n")

keyring/tests/test_backend.py

     __test__ = True
 
     def init_keyring(self):
-        print >> sys.stderr, "Testing OSXKeychain, following password prompts are for this keyring"
         return keyring.backend.OSXKeychain()
 
 
                     DBUS_SESSION_BUS_ADDRESS='1')
 
     def init_keyring(self):
-        print >> sys.stderr, "Testing GnomeKeyring, following password prompts are for this keyring"
         return keyring.backend.GnomeKeyring()
 
     def test_supported(self):
     __test__ = True
 
     def init_keyring(self):
-        print >> sys.stderr, "Testing KDEKWallet, following password prompts are for this keyring"
         return keyring.backend.KDEKWallet()
 
 
     __test__ = True
 
     def init_keyring(self):
-        print >> sys.stderr, "Testing UnecryptedFile, following password prompts are for this keyring"
         return keyring.backend.UncryptedFileKeyring()
 
 
 class CryptedFileKeyringTestCase(FileKeyringTestCase):
     __test__ = True
 
+    def setUp(self):
+        super(self.__class__, self).setUp()
+        self.keyring._getpass = lambda *args, **kwargs: "abcdef"
+
     def init_keyring(self):
-        print >> sys.stderr, "Testing CryptedFile, following password prompts are for this keyring"
         return keyring.backend.CryptedFileKeyring()
 
 
     __test__ = True
 
     def init_keyring(self):
-        print >> sys.stderr, "Testing Win32, following password prompts are for this keyring"
         return keyring.backend.Win32CryptoKeyring()