summaryrefslogtreecommitdiff
path: root/libsecret/test-py-clear.py
blob: a398381cd9f6ce52ef6eed6c6fd2d7b95d1c3dae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python

#
# 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.
#

import sys
import unittest

import gi
gi.require_version('MockService', '0')
gi.require_version('Secret', '1')

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):
		Secret.Service.disconnect()
		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_clear_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_clear_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(False, deleted)

	def testAsynchronous(self):
		loop = GLib.MainLoop(None)

		def on_result_ready(source, result, unused):
			loop.quit()
			deleted = Secret.password_clear_finish(result)
			self.assertEquals(True, deleted)

		Secret.password_clear(STORE_SCHEMA, { "number": "2", "string": "two" },
		                      None, on_result_ready, None)

		loop.run()

	def testAsyncNotFound(self):
		loop = GLib.MainLoop(None)

		def on_result_ready(source, result, unused):
			loop.quit()
			deleted = Secret.password_clear_finish(result)
			self.assertEquals(False, deleted)

		Secret.password_clear(STORE_SCHEMA, { "number": "7", "string": "five" },
		                      None, on_result_ready, None)

		loop.run()

if __name__ == '__main__':
		unittest.main()