Bump version number
[platform/upstream/libsecret.git] / libsecret / tests / test-store-password.py
1 #!/usr/bin/env python
2
3 import unittest
4
5 from gi.repository import MockService as Mock
6 from gi.repository import Secret, GLib
7
8 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
9         Secret.SchemaFlags.NONE,
10         {
11                 "number": Secret.SchemaAttributeType.INTEGER,
12                 "string": Secret.SchemaAttributeType.STRING,
13                 "even": Secret.SchemaAttributeType.BOOLEAN,
14         }
15 )
16
17 class TestStore(unittest.TestCase):
18         def setUp(self):
19                 Mock.start("mock-service-normal.py")
20
21         def tearDown(self):
22                 Mock.stop()
23
24         def testSynchronous(self):
25                 attributes = { "number": "9", "string": "nine", "even": "false" }
26
27                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
28                 self.assertEqual(None, password)
29
30                 stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
31                                                     "The number nine", "999", None)
32                 self.assertEqual(True, stored);
33
34                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
35                 self.assertEqual("999", password)
36
37         def testAsynchronous(self):
38                 attributes = { "number": "888", "string": "eight", "even": "true" }
39
40                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
41                 self.assertEqual(None, password);
42
43                 loop = GLib.MainLoop(None, False)
44
45                 def on_result_ready(source, result, unused):
46                         loop.quit()
47                         stored = Secret.password_store_finish(result)
48                         self.assertEquals(True, stored)
49
50                 Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888",
51                                       None, on_result_ready, None)
52
53                 loop.run()
54
55                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
56                 self.assertEqual("888", password)
57
58 if __name__ == '__main__':
59                 unittest.main()