Use upstream tag
[platform/upstream/libsecret.git] / libsecret / test-py-clear.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 sys
15 import unittest
16
17 from gi.repository import MockService as Mock
18 from gi.repository import Secret, GLib
19
20 STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
21         Secret.SchemaFlags.NONE,
22         {
23                 "number": Secret.SchemaAttributeType.INTEGER,
24                 "string": Secret.SchemaAttributeType.STRING,
25                 "even": Secret.SchemaAttributeType.BOOLEAN,
26         }
27 )
28
29 class TestRemove(unittest.TestCase):
30         def setUp(self):
31                 Mock.start("mock-service-normal.py")
32
33         def tearDown(self):
34                 Secret.Service.disconnect()
35                 Mock.stop()
36
37         def testSynchronous(self):
38                 attributes = { "number": "1", "string": "one", "even": "false" }
39
40                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
41                 self.assertEqual("111", password)
42
43                 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
44                 self.assertEqual(True, deleted)
45
46         def testSyncNotFound(self):
47                 attributes = { "number": "11", "string": "one", "even": "true" }
48
49                 password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
50                 self.assertEqual(None, password)
51
52                 deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
53                 self.assertEqual(False, deleted)
54
55         def testAsynchronous(self):
56                 loop = GLib.MainLoop(None)
57
58                 def on_result_ready(source, result, unused):
59                         loop.quit()
60                         deleted = Secret.password_clear_finish(result)
61                         self.assertEquals(True, deleted)
62
63                 Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
64                                       None, on_result_ready, None)
65
66                 loop.run()
67
68         def testAsyncNotFound(self):
69                 loop = GLib.MainLoop(None)
70
71                 def on_result_ready(source, result, unused):
72                         loop.quit()
73                         deleted = Secret.password_clear_finish(result)
74                         self.assertEquals(False, deleted)
75
76                 Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
77                                       None, on_result_ready, None)
78
79                 loop.run()
80
81 if __name__ == '__main__':
82                 unittest.main()