4 # Copyright 2012 Red Hat Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published
8 # by the Free Software Foundation; either version 2.1 of the licence or (at
9 # your option) any later version.
11 # See the included COPYING file for more information.
16 from gi.repository import MockService as Mock
17 from gi.repository import Secret, GLib
19 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
20 Secret.SchemaFlags.NONE,
22 "number": Secret.SchemaAttributeType.INTEGER,
23 "string": Secret.SchemaAttributeType.STRING,
24 "even": Secret.SchemaAttributeType.BOOLEAN,
28 class TestLookup(unittest.TestCase):
30 Mock.start("mock-service-normal.py")
33 Secret.Service.disconnect()
36 def testSynchronous(self):
37 password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "1", "even": "false" }, None)
38 self.assertEqual("111", password)
40 def testSyncNotFound(self):
41 password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "5", "even": "true" }, None)
42 self.assertEqual(None, password)
44 def testAsynchronous(self):
45 loop = GLib.MainLoop(None)
47 def on_result_ready(source, result, unused):
49 password = Secret.password_lookup_finish(result)
50 self.assertEquals("222", password)
52 Secret.password_lookup (STORE_SCHEMA, { "number": "2", "string": "two" },
53 None, on_result_ready, None)
57 def testAsyncNotFound(self):
58 loop = GLib.MainLoop(None)
60 def on_result_ready(source, result, unused):
62 password = Secret.password_lookup_finish(result)
63 self.assertEquals(None, password)
65 Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
66 None, on_result_ready, None)
70 if __name__ == '__main__':