5 from gi.repository import MockService as Mock
6 from gi.repository import Secret, GLib
8 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
9 Secret.SchemaFlags.NONE,
11 "number": Secret.SchemaAttributeType.INTEGER,
12 "string": Secret.SchemaAttributeType.STRING,
13 "even": Secret.SchemaAttributeType.BOOLEAN,
17 class TestStore(unittest.TestCase):
19 Mock.start("mock-service-normal.py")
24 def testSynchronous(self):
25 attributes = { "number": "9", "string": "nine", "even": "false" }
27 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
28 self.assertEqual(None, password)
30 stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
31 "The number nine", "999", None)
32 self.assertEqual(True, stored);
34 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
35 self.assertEqual("999", password)
37 def testAsynchronous(self):
38 attributes = { "number": "888", "string": "eight", "even": "true" }
40 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
41 self.assertEqual(None, password);
43 loop = GLib.MainLoop(None, False)
45 def on_result_ready(source, result, unused):
47 stored = Secret.password_store_finish(result)
48 self.assertEquals(True, stored)
50 Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888",
51 None, on_result_ready, None)
55 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
56 self.assertEqual("888", password)
58 if __name__ == '__main__':