Jason R. Coombs avatar Jason R. Coombs committed 327f1bf

Core tests no longer depend on any particular backend to run. They now simply test the interface is properly passing the calls through to _some_ backend. The backend tests themselves should exercise the expected behavior of a backend.

Comments (0)

Files changed (1)

keyring/tests/test_core.py

 
 from keyring.tests.py30compat import unittest
 
+import mock
+
 import keyring.backend
 import keyring.core
 import keyring.util.platform
 
 
 class CoreTestCase(unittest.TestCase):
-    skip_arbitrary_keyring = unittest.skip("the default keyring might be a "
-        "keyring "
-        "which requires input (such as file.EncryptedKeyring), "
-        "in which case the test blocks forever. TODO: patch rawinput "
-        "to supply a password.")
+    mock_global_backend = mock.patch('keyring.core._keyring_backend')
 
-    @skip_arbitrary_keyring
-    def test_set_get_password(self):
+    @mock_global_backend
+    def test_set_password(self, backend):
         """
-        set/get_password on the default keyring.
+        set_password on the default keyring is called.
         """
         keyring.core.set_password("test", "user", "passtest")
-        self.assertEqual(keyring.core.get_password("test", "user"), "passtest")
+        backend.set_password.assert_called_once_with('test', 'user',
+            'passtest')
 
-    @skip_arbitrary_keyring
-    def test_delete_password_present(self):
-        keyring.core.set_password("test", "user", "passtest")
+    @mock_global_backend
+    def test_get_password(self, backend):
+        """
+        set_password on the default keyring is called.
+        """
+        keyring.core.get_password("test", "user")
+        backend.get_password.assert_called_once_with('test', 'user')
+
+    @mock_global_backend
+    def test_delete_password(self, backend):
         keyring.core.delete_password("test", "user")
-        self.assertTrue(keyring.core.get_password("test", "user") is None)
-
-    @skip_arbitrary_keyring
-    def test_delete_password_not_present(self):
-        self.assertRaises(errors.PasswordDeleteError,
-            keyring.core.delete_password, "test", "user")
+        backend.delete_password.assert_called_once_with('test', 'user')
 
     def test_set_keyring_in_runtime(self):
         """Test the function of set keyring in runtime.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.