2013-12-11 09:12:23 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2012-08-06 09:22:30 +00:00
|
|
|
#
|
|
|
|
# Copyright 2012 Red Hat Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation; either version 2.1 of the licence or (at
|
|
|
|
# your option) any later version.
|
|
|
|
#
|
|
|
|
# See the included COPYING file for more information.
|
|
|
|
#
|
|
|
|
|
2013-12-11 09:12:23 +00:00
|
|
|
import sys
|
2012-03-17 12:27:42 +00:00
|
|
|
import unittest
|
|
|
|
|
2016-04-06 08:40:20 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('MockService', '0')
|
|
|
|
gi.require_version('Secret', '1')
|
|
|
|
|
2012-03-17 12:27:42 +00:00
|
|
|
from gi.repository import MockService as Mock
|
2013-12-11 09:32:25 +00:00
|
|
|
from gi.repository import Secret, GLib
|
2012-03-17 12:27:42 +00:00
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
STORE_SCHEMA = Secret.Schema.new("org.mock.Schema",
|
2012-03-17 12:27:42 +00:00
|
|
|
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):
|
2013-12-11 09:32:25 +00:00
|
|
|
Secret.Service.disconnect()
|
2012-03-17 12:27:42 +00:00
|
|
|
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)
|
|
|
|
|
2012-07-14 06:59:36 +00:00
|
|
|
deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
|
2012-03-17 12:27:42 +00:00
|
|
|
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)
|
|
|
|
|
2012-07-14 06:59:36 +00:00
|
|
|
deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
|
2012-03-17 12:27:42 +00:00
|
|
|
self.assertEqual(False, deleted)
|
|
|
|
|
|
|
|
def testAsynchronous(self):
|
2013-12-11 09:12:23 +00:00
|
|
|
loop = GLib.MainLoop(None)
|
2012-03-17 12:27:42 +00:00
|
|
|
|
|
|
|
def on_result_ready(source, result, unused):
|
|
|
|
loop.quit()
|
2012-07-14 06:59:36 +00:00
|
|
|
deleted = Secret.password_clear_finish(result)
|
2012-03-17 12:27:42 +00:00
|
|
|
self.assertEquals(True, deleted)
|
|
|
|
|
2012-07-14 06:59:36 +00:00
|
|
|
Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
|
|
|
|
None, on_result_ready, None)
|
2012-03-17 12:27:42 +00:00
|
|
|
|
|
|
|
loop.run()
|
|
|
|
|
|
|
|
def testAsyncNotFound(self):
|
2013-12-11 09:12:23 +00:00
|
|
|
loop = GLib.MainLoop(None)
|
2012-03-17 12:27:42 +00:00
|
|
|
|
|
|
|
def on_result_ready(source, result, unused):
|
|
|
|
loop.quit()
|
2012-07-14 06:59:36 +00:00
|
|
|
deleted = Secret.password_clear_finish(result)
|
2012-03-17 12:27:42 +00:00
|
|
|
self.assertEquals(False, deleted)
|
|
|
|
|
2012-07-14 06:59:36 +00:00
|
|
|
Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
|
|
|
|
None, on_result_ready, None)
|
2012-03-17 12:27:42 +00:00
|
|
|
|
|
|
|
loop.run()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|