collection: Have gobject-introspection and glib-mkenums recognize flags
[platform/upstream/libsecret.git] / libsecret / tests / test-store-password.py
1 #!/usr/bin/env python
2
3 #
4 # Copyright 2012 Red Hat Inc.
5 #
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.
10 #
11 # See the included COPYING file for more information.
12 #
13
14 import unittest
15
16 from gi.repository import MockService as Mock
17 from gi.repository import Secret, SecretUnstable, GLib
18
19 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
20         Secret.SchemaFlags.NONE,
21         {
22                 "number": Secret.SchemaAttributeType.INTEGER,
23                 "string": Secret.SchemaAttributeType.STRING,
24                 "even": Secret.SchemaAttributeType.BOOLEAN,
25         }
26 )
27
28 class TestStore(unittest.TestCase):
29         def setUp(self):
30                 Mock.start("mock-service-normal.py")
31
32         def tearDown(self):
33                 SecretUnstable.Service.disconnect()
34                 Mock.stop()
35
36         def testSynchronous(self):
37                 attributes = { "number": "9", "string": "nine", "even": "false" }
38
39                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
40                 self.assertEqual(None, password)
41
42                 stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
43                                                     "The number nine", "999", None)
44                 self.assertEqual(True, stored);
45
46                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
47                 self.assertEqual("999", password)
48
49         def testAsynchronous(self):
50                 attributes = { "number": "888", "string": "eight", "even": "true" }
51
52                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
53                 self.assertEqual(None, password);
54
55                 loop = GLib.MainLoop(None, False)
56
57                 def on_result_ready(source, result, unused):
58                         loop.quit()
59                         stored = Secret.password_store_finish(result)
60                         self.assertEquals(True, stored)
61
62                 Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888",
63                                       None, on_result_ready, None)
64
65                 loop.run()
66
67                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
68                 self.assertEqual("888", password)
69
70 if __name__ == '__main__':
71                 unittest.main()