collection: Have gobject-introspection and glib-mkenums recognize flags
[platform/upstream/libsecret.git] / libsecret / tests / test-unstable.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 SecretUnstable, Secret, GLib
18
19 EXAMPLE_SCHEMA = Secret.Schema.new('org.mock.type.Store',
20         Secret.SchemaFlags.NONE,
21         {
22                 'number': Secret.SchemaAttributeType.INTEGER,
23                 'string': Secret.SchemaAttributeType.STRING,
24                 'even': Secret.SchemaAttributeType.BOOLEAN,
25         }
26 )
27
28 attributes = {
29         'number': '8',
30         'string': 'eight',
31         'even': 'true'
32 }
33
34 class TestStore(unittest.TestCase):
35         def setUp(self):
36                 Mock.start("mock-service-normal.py")
37
38         def tearDown(self):
39                 SecretUnstable.Service.disconnect()
40                 Mock.stop()
41
42         def testSynchronous(self):
43                 service = SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.NONE, None);
44                 path = service.read_alias_dbus_path_sync("default", None);
45
46                 # Just running this without error is good enough for us to test the unstable gir
47                 self.assertNotEqual(path, None);
48
49         def testValueGet(self):
50                 Secret.password_store_sync(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
51                                            'the label', 'the password', None)
52
53                 service = SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.NONE, None)
54                 items = service.search_sync(EXAMPLE_SCHEMA, { 'even': 'true' },
55                                                    SecretUnstable.SearchFlags.ALL | SecretUnstable.SearchFlags.LOAD_SECRETS,
56                                                    None)
57
58                 item = items[0]
59                 item_secret = item.get_secret()
60                 self.assertEqual(item_secret.get(), "the password")
61
62 if __name__ == '__main__':
63                 unittest.main()