mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-24 05:38:54 +00:00
8417d8c98b
* Handled entirely on the client side. * Schema names are stored in an xdg:schema attribute * Add option to turn of matching on schema names. So that we can lookup items stored by libgnome-keyring and others * Change schema 'identifier' to 'name' * Fix up tests
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
|
|
from gi.repository import MockService as Mock
|
|
from gi.repository import Secret, GLib
|
|
|
|
Mock.start("mock-service-normal.py")
|
|
|
|
STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
|
|
Secret.SchemaFlags.NONE,
|
|
{
|
|
"number": Secret.SchemaAttributeType.INTEGER,
|
|
"string": Secret.SchemaAttributeType.STRING,
|
|
"even": Secret.SchemaAttributeType.BOOLEAN,
|
|
}
|
|
)
|
|
|
|
class TestLookup(unittest.TestCase):
|
|
def setUp(self):
|
|
Mock.start("mock-service-normal.py")
|
|
|
|
def tearDown(self):
|
|
Mock.stop()
|
|
|
|
def testSynchronous(self):
|
|
password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "1", "even": "false" }, None)
|
|
self.assertEqual("111", password)
|
|
|
|
def testSyncNotFound(self):
|
|
password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "5", "even": "true" }, None)
|
|
self.assertEqual(None, password)
|
|
|
|
def testAsynchronous(self):
|
|
loop = GLib.MainLoop(None, False)
|
|
|
|
def on_result_ready(source, result, unused):
|
|
loop.quit()
|
|
password = Secret.password_lookup_finish(result)
|
|
self.assertEquals("222", password)
|
|
|
|
Secret.password_lookup (STORE_SCHEMA, { "number": "2", "string": "two" },
|
|
None, on_result_ready, None)
|
|
|
|
loop.run()
|
|
|
|
def testAsyncNotFound(self):
|
|
loop = GLib.MainLoop(None, False)
|
|
|
|
def on_result_ready(source, result, unused):
|
|
loop.quit()
|
|
password = Secret.password_lookup_finish(result)
|
|
self.assertEquals(None, password)
|
|
|
|
Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
|
|
None, on_result_ready, None)
|
|
|
|
loop.run()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|