collection: Have gobject-introspection and glib-mkenums recognize flags
[platform/upstream/libsecret.git] / libsecret / tests / test-clear-password.py
1 #
2 # Copyright 2012 Red Hat Inc.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published
6 # by the Free Software Foundation; either version 2.1 of the licence or (at
7 # your option) any later version.
8 #
9 # See the included COPYING file for more information.
10 #
11
12 #!/usr/bin/env python
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 TestRemove(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": "1", "string": "one", "even": "false" }
38
39                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
40                 self.assertEqual("111", password)
41
42                 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
43                 self.assertEqual(True, deleted)
44
45         def testSyncNotFound(self):
46                 attributes = { "number": "11", "string": "one", "even": "true" }
47
48                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
49                 self.assertEqual(None, password)
50
51                 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
52                 self.assertEqual(False, deleted)
53
54         def testAsynchronous(self):
55                 loop = GLib.MainLoop(None, False)
56
57                 def on_result_ready(source, result, unused):
58                         loop.quit()
59                         deleted = Secret.password_clear_finish(result)
60                         self.assertEquals(True, deleted)
61
62                 Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
63                                       None, on_result_ready, None)
64
65                 loop.run()
66
67         def testAsyncNotFound(self):
68                 loop = GLib.MainLoop(None, False)
69
70                 def on_result_ready(source, result, unused):
71                         loop.quit()
72                         deleted = Secret.password_clear_finish(result)
73                         self.assertEquals(False, deleted)
74
75                 Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
76                                       None, on_result_ready, None)
77
78                 loop.run()
79
80 if __name__ == '__main__':
81                 unittest.main()