Add python tests

This commit is contained in:
Stef Walter 2012-03-17 13:27:42 +01:00
parent 605e0b1f9b
commit ad9936e3f5
6 changed files with 205 additions and 15 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@
.cproject
.libs
.project
.pydevproject
aclocal.m4
autom4te.cache
compile

View File

@ -65,7 +65,12 @@ JS_ENV = \
LD_LIBRARY_PATH=$(builddir)/.libs \
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)
@gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
@ -73,6 +78,11 @@ test-c: $(TEST_PROGS)
test-js:
@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

View File

@ -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();

View 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()

View 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()

View 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()