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.
17 from gi.repository import MockService as Mock
18 from gi.repository import Secret, GLib
20 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
21 Secret.SchemaFlags.NONE,
23 "number": Secret.SchemaAttributeType.INTEGER,
24 "string": Secret.SchemaAttributeType.STRING,
25 "even": Secret.SchemaAttributeType.BOOLEAN,
29 class TestRemove(unittest.TestCase):
31 Mock.start("mock-service-normal.py")
34 Secret.Service.disconnect()
37 def testSynchronous(self):
38 attributes = { "number": "1", "string": "one", "even": "false" }
40 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
41 self.assertEqual("111", password)
43 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
44 self.assertEqual(True, deleted)
46 def testSyncNotFound(self):
47 attributes = { "number": "11", "string": "one", "even": "true" }
49 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
50 self.assertEqual(None, password)
52 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
53 self.assertEqual(False, deleted)
55 def testAsynchronous(self):
56 loop = GLib.MainLoop(None)
58 def on_result_ready(source, result, unused):
60 deleted = Secret.password_clear_finish(result)
61 self.assertEquals(True, deleted)
63 Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
64 None, on_result_ready, None)
68 def testAsyncNotFound(self):
69 loop = GLib.MainLoop(None)
71 def on_result_ready(source, result, unused):
73 deleted = Secret.password_clear_finish(result)
74 self.assertEquals(False, deleted)
76 Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
77 None, on_result_ready, None)
81 if __name__ == '__main__':