summaryrefslogtreecommitdiffstats
path: root/tests/QtSql
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-06-07 14:43:45 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-06-07 16:57:11 -0300
commitab918abc1e103e0ca86939f7d057e8a44ac8a4ef (patch)
tree53c6f57d089dcf5e145d766b1ceef704714046d8 /tests/QtSql
parent471486732b03cbb42b884158604a59d5a18e8a35 (diff)
downloadpyside-ab918abc1e103e0ca86939f7d057e8a44ac8a4ef.tar.gz
pyside-ab918abc1e103e0ca86939f7d057e8a44ac8a4ef.tar.xz
pyside-ab918abc1e103e0ca86939f7d057e8a44ac8a4ef.zip
Created new unittest model.
Separete unittest for module. Only run unittest for compiled modules. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>, Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/QtSql')
-rw-r--r--tests/QtSql/CMakeLists.txt1
-rwxr-xr-xtests/QtSql/qsqldatabaseandqueries_test.py56
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/QtSql/CMakeLists.txt b/tests/QtSql/CMakeLists.txt
new file mode 100644
index 0000000..a944691
--- /dev/null
+++ b/tests/QtSql/CMakeLists.txt
@@ -0,0 +1 @@
+PYSIDE_TEST(qsqldatabaseandqueries_test.py)
diff --git a/tests/QtSql/qsqldatabaseandqueries_test.py b/tests/QtSql/qsqldatabaseandqueries_test.py
new file mode 100755
index 0000000..49f2209
--- /dev/null
+++ b/tests/QtSql/qsqldatabaseandqueries_test.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+'''Test cases for QtSql database creation, destruction and queries'''
+
+import sys
+import unittest
+
+from PySide import QtSql
+from PySide.QtCore import QVariant, QString
+
+class SqlDatabaseCreationDestructionAndQueries(unittest.TestCase):
+ '''Test cases for QtSql database creation, destruction and queries'''
+
+ def setUp(self):
+ #Acquire resources
+ self.assertFalse(QtSql.QSqlDatabase.drivers().isEmpty(), "installed Qt has no DB drivers")
+ self.assertTrue("QSQLITE" in QtSql.QSqlDatabase.drivers(), "\"QSQLITE\" driver not available in this Qt version")
+ self.db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
+ self.db.setDatabaseName(":memory:")
+ self.assertTrue(self.db.open())
+
+ def tearDown(self):
+ #Release resources
+ self.db.close()
+ QtSql.QSqlDatabase.removeDatabase(":memory:")
+ del self.db
+
+ def testTableCreationAndDestruction(self):
+ #Test table creation and destruction
+ query = QtSql.QSqlQuery()
+ query.exec_("CREATE TABLE dummy(id int primary key, dummyfield varchar(20))")
+ query.exec_("DROP TABLE dummy")
+ query.clear()
+
+ def testTableInsertionAndRetrieval(self):
+ #Test table creation, insertion and retrieval
+ query = QtSql.QSqlQuery()
+ query.exec_("CREATE TABLE person(id int primary key, "
+ "firstname varchar(20), lastname varchar(20))")
+ query.exec_("INSERT INTO person VALUES(101, 'George', 'Harrison')")
+ query.prepare("INSERT INTO person (id, firstname, lastname) "
+ "VALUES (:id, :firstname, :lastname)")
+ query.bindValue(":id", QVariant(102))
+ query.bindValue(":firstname", QVariant("John"))
+ query.bindValue(":lastname", QVariant("Lennon"))
+ query.exec_()
+
+ lastname = ''
+ query.exec_("SELECT lastname FROM person where id=101")
+ self.assertTrue(query.isActive())
+ query.next()
+ lastname = query.value(0).toString()
+ self.assertEqual(lastname, 'Harrison')
+
+if __name__ == '__main__':
+ unittest.main()
+