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, 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 TestStore(unittest.TestCase):
30 Mock.start("mock-service-normal.py")
33 SecretUnstable.Service.disconnect()
36 def testSynchronous(self):
37 attributes = { "number": "9", "string": "nine", "even": "false" }
39 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
40 self.assertEqual(None, password)
42 stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
43 "The number nine", "999", None)
44 self.assertEqual(True, stored);
46 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
47 self.assertEqual("999", password)
49 def testAsynchronous(self):
50 attributes = { "number": "888", "string": "eight", "even": "true" }
52 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
53 self.assertEqual(None, password);
55 loop = GLib.MainLoop(None, False)
57 def on_result_ready(source, result, unused):
59 stored = Secret.password_store_finish(result)
60 self.assertEquals(True, stored)
62 Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888",
63 None, on_result_ready, None)
67 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
68 self.assertEqual("888", password)
70 if __name__ == '__main__':