Fix tests

This commit is contained in:
David Rousselie
2010-06-09 13:46:38 +02:00
parent 3d0d70c976
commit 348f5ce37e
2 changed files with 137 additions and 2 deletions

View File

@@ -42,6 +42,138 @@ Last-Update: <YYYY-MM-DD>
clean:
$(PYTHON) setup.py clean
--- /dev/null
+++ jcl-0.1b3/src/jcl/model/tests/__init___flymake.py
@@ -0,0 +1,84 @@
+"""JCL test module"""
+__revision__ = ""
+
+import unittest
+import threading
+import os
+import tempfile
+import sys
+
+from sqlobject import SQLObject
+from sqlobject.col import StringCol
+from sqlobject.dbconnection import TheURIOpener
+
+import jcl.model as model
+
+if sys.platform == "win32":
+ DB_DIR = "/c|/temp/"
+else:
+ DB_DIR = "/tmp/"
+
+class MyMockSQLObject(SQLObject):
+ _connection = model.hub
+ string_attr = StringCol()
+
+class ModelModule_TestCase(unittest.TestCase):
+ def setUp(self):
+ self.db_path = tempfile.mktemp("db", "jcltest", DB_DIR)
+ if os.path.exists(self.db_path):
+ os.unlink(self.db_path)
+ self.db_url = "sqlite://" + self.db_path
+ model.db_connection_str = self.db_url
+ model.db_connect()
+ MyMockSQLObject.createTable(ifNotExists=True)
+ model.db_disconnect()
+
+ def tearDown(self):
+ model.db_connect()
+ MyMockSQLObject.dropTable(ifExists=True)
+ del TheURIOpener.cachedURIs[self.db_url]
+ model.hub.threadConnection.close()
+ model.db_disconnect()
+ if os.path.exists(self.db_path):
+ os.unlink(self.db_path)
+
+ def test_multiple_db_connection(self):
+ def create_account_thread():
+ for i in xrange(100):
+ string_attr = "obj2" + str(i)
+ model.db_connect()
+ obj = MyMockSQLObject(string_attr=string_attr)
+ model.db_disconnect()
+ model.db_connect()
+ obj2 = MyMockSQLObject.select(MyMockSQLObject.q.string_attr == string_attr)
+ model.db_disconnect()
+ self.assertEquals(obj, obj2[0])
+ timer_thread = threading.Thread(target=create_account_thread,
+ name="CreateAccountThread")
+ timer_thread.start()
+ for i in xrange(100):
+ string_attr = "obj1" + str(i)
+ model.db_connect()
+ obj = MyMockSQLObject(string_attr=string_attr)
+ model.db_disconnect()
+ model.db_connect()
+ obj2 = MyMockSQLObject.select(MyMockSQLObject.q.string_attr == string_attr)
+ model.db_disconnect()
+ self.assertEquals(obj, obj2[0])
+ timer_thread.join(2)
+ threads = threading.enumerate()
+ self.assertEquals(len(threads), 1)
+ model.db_connect()
+ objs = MyMockSQLObject.select()
+ self.assertEquals(objs.count(), 200)
+ model.db_disconnect()
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(ModelModule_TestCase, 'test'))
+ from jcl.model.tests import account
+ suite.addTest(account.suite())
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
--- jcl-0.1b3.orig/src/jcl/model/tests/account.py
+++ jcl-0.1b3/src/jcl/model/tests/account.py
@@ -137,6 +137,42 @@ class AccountModule_TestCase(JCLTestCase
"user1@jcl.test.com")
self.assertEquals(result, "test")
+ def test_boolean_post_func_with_1_str(self):
+ result = account.boolean_post_func("1", None, "user1@jcl.test.com")
+ self.assertEquals(result, True)
+
+ def test_boolean_post_func_with_True_str(self):
+ result = account.boolean_post_func("True", None, "user1@jcl.test.com")
+ self.assertEquals(result, True)
+
+ def test_boolean_post_func_with_False_str(self):
+ result = account.boolean_post_func("False", None, "user1@jcl.test.com")
+ self.assertEquals(result, False)
+
+ def test_boolean_post_func_with_1_unicode(self):
+ result = account.boolean_post_func(u"1", None, "user1@jcl.test.com")
+ self.assertEquals(result, True)
+
+ def test_boolean_post_func_with_True_unicode(self):
+ result = account.boolean_post_func(u"true", None, "user1@jcl.test.com")
+ self.assertEquals(result, True)
+
+ def test_boolean_post_func_with_False_unicode(self):
+ result = account.boolean_post_func(u"False", None, "user1@jcl.test.com")
+ self.assertEquals(result, False)
+
+ def test_boolean_post_func_with_1(self):
+ result = account.boolean_post_func(1, None, "user1@jcl.test.com")
+ self.assertEquals(result, False)
+
+ def test_boolean_post_func_with_True(self):
+ result = account.boolean_post_func(True, None, "user1@jcl.test.com")
+ self.assertEquals(result, True)
+
+ def test_boolean_post_func_with_False(self):
+ result = account.boolean_post_func(False, None, "user1@jcl.test.com")
+ self.assertEquals(result, False)
+
def test_int_post_func(self):
result = account.int_post_func("42", None, "user1@jcl.test.com")
self.assertEquals(result, 42)
--- jcl-0.1b3.orig/src/jcl/jabber/tests/register.py
+++ jcl-0.1b3/src/jcl/jabber/tests/register.py
@@ -56,7 +56,7 @@ class SetRegisterHandler_TestCase(JCLTes

View File

@@ -161,8 +161,8 @@ class AccountModule_TestCase(JCLTestCase):
result = account.boolean_post_func(u"False", None, "user1@jcl.test.com")
self.assertEquals(result, False)
def test_boolean_post_func_with_1(self):
result = account.boolean_post_func(1, None, "user1@jcl.test.com")
def test_boolean_post_func_with_0_str(self):
result = account.boolean_post_func("0", None, "user1@jcl.test.com")
self.assertEquals(result, False)
def test_boolean_post_func_with_True(self):
@@ -254,6 +254,9 @@ class AccountModule_TestCase(JCLTestCase):
self.assertEquals(_account.name, "account11")
class InheritableAccount_TestCase(JCLTestCase):
def setUp(self):
JCLTestCase.setUp(self, tables=[Account])
self.account_class = Account
def test_get_register_fields(self):
"""