2 # Copyright 2012 Red Hat Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published
6 # by the Free Software Foundation; either version 2.1 of the licence or (at
7 # your option) any later version.
9 # See the included COPYING file for more information.
16 from gi.repository import MockService as Mock
17 from gi.repository import Secret, SecretUnstable, 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 TestRemove(unittest.TestCase):
30 Mock.start("mock-service-normal.py")
33 SecretUnstable.Service.disconnect()
36 def testSynchronous(self):
37 attributes = { "number": "1", "string": "one", "even": "false" }
39 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
40 self.assertEqual("111", password)
42 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
43 self.assertEqual(True, deleted)
45 def testSyncNotFound(self):
46 attributes = { "number": "11", "string": "one", "even": "true" }
48 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
49 self.assertEqual(None, password)
51 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
52 self.assertEqual(False, deleted)
54 def testAsynchronous(self):
55 loop = GLib.MainLoop(None, False)
57 def on_result_ready(source, result, unused):
59 deleted = Secret.password_clear_finish(result)
60 self.assertEquals(True, deleted)
62 Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
63 None, on_result_ready, None)
67 def testAsyncNotFound(self):
68 loop = GLib.MainLoop(None, False)
70 def on_result_ready(source, result, unused):
72 deleted = Secret.password_clear_finish(result)
73 self.assertEquals(False, deleted)
75 Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
76 None, on_result_ready, None)
80 if __name__ == '__main__':