mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2025-01-03 02:28:53 +00:00
Add python tests
This commit is contained in:
parent
605e0b1f9b
commit
ad9936e3f5
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,6 +15,7 @@
|
|||||||
.cproject
|
.cproject
|
||||||
.libs
|
.libs
|
||||||
.project
|
.project
|
||||||
|
.pydevproject
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
autom4te.cache
|
autom4te.cache
|
||||||
compile
|
compile
|
||||||
|
@ -65,7 +65,12 @@ JS_ENV = \
|
|||||||
LD_LIBRARY_PATH=$(builddir)/.libs \
|
LD_LIBRARY_PATH=$(builddir)/.libs \
|
||||||
GI_TYPELIB_PATH=$(builddir)/..:$(builddir)
|
GI_TYPELIB_PATH=$(builddir)/..:$(builddir)
|
||||||
|
|
||||||
test: test-c test-js
|
PY_TESTS = \
|
||||||
|
test-lookup-password.py \
|
||||||
|
test-remove-password.py \
|
||||||
|
test-store-password.py
|
||||||
|
|
||||||
|
PY_ENV = $(JS_ENV)
|
||||||
|
|
||||||
test-c: $(TEST_PROGS)
|
test-c: $(TEST_PROGS)
|
||||||
@gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
|
@gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
|
||||||
@ -73,6 +78,11 @@ test-c: $(TEST_PROGS)
|
|||||||
test-js:
|
test-js:
|
||||||
@for js in $(JS_TESTS); do echo "TEST: $$js"; $(JS_ENV) gjs $$js; done
|
@for js in $(JS_TESTS); do echo "TEST: $$js"; $(JS_ENV) gjs $$js; done
|
||||||
|
|
||||||
|
test-py:
|
||||||
|
@for py in $(PY_TESTS); do echo "TEST: $$py"; $(PY_ENV) python $$py; done
|
||||||
|
|
||||||
|
test: test-c test-py test-js
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# INTROSPECTION
|
# INTROSPECTION
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
const Mock = imports.gi.MockService;
|
|
||||||
const Secret = imports.gi.Secret;
|
|
||||||
|
|
||||||
Mock.start("mock-service-normal.py");
|
|
||||||
|
|
||||||
var schema = new Secret.Schema.new("org.test",
|
|
||||||
Secret.SchemaFlags.NONE,
|
|
||||||
{ "blah": Secret.SchemaAttributeType.STRING });
|
|
||||||
log(schema.identifier);
|
|
||||||
log(schema.flags);
|
|
||||||
/* log(schema.attributes); */
|
|
||||||
|
|
||||||
Mock.stop();
|
|
61
library/tests/test-lookup-password.py
Normal file
61
library/tests/test-lookup-password.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from gi.repository import MockService as Mock
|
||||||
|
from gi.repository import Secret, GLib
|
||||||
|
|
||||||
|
Mock.start("mock-service-normal.py")
|
||||||
|
|
||||||
|
STORE_SCHEMA = Secret.Schema.new("org.mock.type.Store",
|
||||||
|
Secret.SchemaFlags.NONE,
|
||||||
|
{
|
||||||
|
"number": Secret.SchemaAttributeType.INTEGER,
|
||||||
|
"string": Secret.SchemaAttributeType.STRING,
|
||||||
|
"even": Secret.SchemaAttributeType.BOOLEAN,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
class TestLookup(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
Mock.start("mock-service-normal.py")
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
Mock.stop()
|
||||||
|
|
||||||
|
def testSynchronous(self):
|
||||||
|
password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "1", "even": "false" }, None)
|
||||||
|
self.assertEqual("111", password)
|
||||||
|
|
||||||
|
def testSyncNotFound(self):
|
||||||
|
password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "5", "even": "true" }, None)
|
||||||
|
self.assertEqual(None, password)
|
||||||
|
|
||||||
|
def testAsynchronous(self):
|
||||||
|
loop = GLib.MainLoop(None, False)
|
||||||
|
|
||||||
|
def on_result_ready(source, result, unused):
|
||||||
|
loop.quit()
|
||||||
|
password = Secret.password_lookup_finish(result)
|
||||||
|
self.assertEquals("222", password)
|
||||||
|
|
||||||
|
Secret.password_lookup (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()
|
||||||
|
password = Secret.password_lookup_finish(result)
|
||||||
|
self.assertEquals(None, password)
|
||||||
|
|
||||||
|
Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
|
||||||
|
None, on_result_ready, None)
|
||||||
|
|
||||||
|
loop.run()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
71
library/tests/test-remove-password.py
Normal file
71
library/tests/test-remove-password.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from gi.repository import MockService as Mock
|
||||||
|
from gi.repository import Secret, GLib
|
||||||
|
|
||||||
|
Mock.start("mock-service-normal.py")
|
||||||
|
|
||||||
|
STORE_SCHEMA = Secret.Schema.new("org.mock.type.Store",
|
||||||
|
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()
|
61
library/tests/test-store-password.py
Normal file
61
library/tests/test-store-password.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from gi.repository import MockService as Mock
|
||||||
|
from gi.repository import Secret, GLib
|
||||||
|
|
||||||
|
Mock.start("mock-service-normal.py")
|
||||||
|
|
||||||
|
STORE_SCHEMA = Secret.Schema.new("org.mock.type.Store",
|
||||||
|
Secret.SchemaFlags.NONE,
|
||||||
|
{
|
||||||
|
"number": Secret.SchemaAttributeType.INTEGER,
|
||||||
|
"string": Secret.SchemaAttributeType.STRING,
|
||||||
|
"even": Secret.SchemaAttributeType.BOOLEAN,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
class TestStore(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
Mock.start("mock-service-normal.py")
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
Mock.stop()
|
||||||
|
|
||||||
|
def testSynchronous(self):
|
||||||
|
attributes = { "number": "9", "string": "nine", "even": "false" }
|
||||||
|
|
||||||
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
||||||
|
self.assertEqual(None, password)
|
||||||
|
|
||||||
|
stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
|
||||||
|
"The number nine", "999", None)
|
||||||
|
self.assertEqual(True, stored);
|
||||||
|
|
||||||
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
||||||
|
self.assertEqual("999", password)
|
||||||
|
|
||||||
|
def testAsynchronous(self):
|
||||||
|
attributes = { "number": "888", "string": "eight", "even": "true" }
|
||||||
|
|
||||||
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
||||||
|
self.assertEqual(None, password);
|
||||||
|
|
||||||
|
loop = GLib.MainLoop(None, False)
|
||||||
|
|
||||||
|
def on_result_ready(source, result, unused):
|
||||||
|
loop.quit()
|
||||||
|
stored = Secret.password_store_finish(result)
|
||||||
|
self.assertEquals(True, stored)
|
||||||
|
|
||||||
|
Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888",
|
||||||
|
None, on_result_ready, None)
|
||||||
|
|
||||||
|
loop.run()
|
||||||
|
|
||||||
|
password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
|
||||||
|
self.assertEqual("888", password)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user