mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 20:58:52 +00:00
268f2dfd62
* Were erroneously starting the mock service when loading the python test modules, although already started in setUp()
70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
|
|
from gi.repository import MockService as Mock
|
|
from gi.repository import Secret, GLib
|
|
|
|
STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
|
|
Secret.SchemaFlags.NONE,
|
|
{
|
|
"number": Secret.SchemaAttributeType.INTEGER,
|
|
"string": Secret.SchemaAttributeType.STRING,
|
|
"even": Secret.SchemaAttributeType.BOOLEAN,
|
|
}
|
|
)
|
|
|
|
class TestRemove(unittest.TestCase):
|
|
def setUp(self):
|
|
Mock.start("mock-service-normal.py")
|
|
|
|
def tearDown(self):
|
|
Mock.stop()
|
|
|
|
def testSynchronous(self):
|
|
attributes = { "number": "1", "string": "one", "even": "false" }
|
|
|
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
|
self.assertEqual("111", password)
|
|
|
|
deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
|
|
self.assertEqual(True, deleted)
|
|
|
|
def testSyncNotFound(self):
|
|
attributes = { "number": "11", "string": "one", "even": "true" }
|
|
|
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
|
self.assertEqual(None, password)
|
|
|
|
deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
|
|
self.assertEqual(False, deleted)
|
|
|
|
def testAsynchronous(self):
|
|
loop = GLib.MainLoop(None, False)
|
|
|
|
def on_result_ready(source, result, unused):
|
|
loop.quit()
|
|
deleted = Secret.password_remove_finish(result)
|
|
self.assertEquals(True, deleted)
|
|
|
|
Secret.password_remove(STORE_SCHEMA, { "number": "2", "string": "two" },
|
|
None, on_result_ready, None)
|
|
|
|
loop.run()
|
|
|
|
def testAsyncNotFound(self):
|
|
loop = GLib.MainLoop(None, False)
|
|
|
|
def on_result_ready(source, result, unused):
|
|
loop.quit()
|
|
deleted = Secret.password_remove_finish(result)
|
|
self.assertEquals(False, deleted)
|
|
|
|
Secret.password_remove(STORE_SCHEMA, { "number": "7", "string": "five" },
|
|
None, on_result_ready, None)
|
|
|
|
loop.run()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|