Rename the library subdirectory to libsecret
[platform/upstream/libsecret.git] / libsecret / tests / test-remove-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 TestRemove(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": "1", "string": "one", "even": "false" }
26
27                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
28                 self.assertEqual("111", password)
29
30                 deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
31                 self.assertEqual(True, deleted)
32
33         def testSyncNotFound(self):
34                 attributes = { "number": "11", "string": "one", "even": "true" }
35
36                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
37                 self.assertEqual(None, password)
38
39                 deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
40                 self.assertEqual(False, deleted)
41
42         def testAsynchronous(self):
43                 loop = GLib.MainLoop(None, False)
44
45                 def on_result_ready(source, result, unused):
46                         loop.quit()
47                         deleted = Secret.password_remove_finish(result)
48                         self.assertEquals(True, deleted)
49
50                 Secret.password_remove(STORE_SCHEMA, { "number": "2", "string": "two" },
51                                        None, on_result_ready, None)
52
53                 loop.run()
54
55         def testAsyncNotFound(self):
56                 loop = GLib.MainLoop(None, False)
57
58                 def on_result_ready(source, result, unused):
59                         loop.quit()
60                         deleted = Secret.password_remove_finish(result)
61                         self.assertEquals(False, deleted)
62
63                 Secret.password_remove(STORE_SCHEMA, { "number": "7", "string": "five" },
64                                        None, on_result_ready, None)
65
66                 loop.run()
67
68 if __name__ == '__main__':
69                 unittest.main()