From 62ceb22a185c6bffac45a2c3b8e994a99be3e3c0 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Tue, 12 Jun 2007 07:49:31 +0200 Subject: [PATCH] Make InheritableAccount_TestCase really inheritable darcs-hash:20070612054931-86b55-8fcd5afc9a0802177f20f59a022dc0c92515d844.gz --- src/jcl/jabber/component.py | 9 +++++-- src/jcl/jabber/tests/component.py | 44 +++++++++++++++---------------- src/jcl/model/tests/account.py | 23 ++++++++++------ 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index a573843..d1972d5 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -668,9 +668,12 @@ class AccountManager(object): account_class.q.user_jid == unicode(from_jid.bare()))) if accounts is not None: query = info_query.new_query("jabber:iq:register") + _account = accounts[0] + self.db_disconnect() self.get_reg_form_init(lang_class, - accounts[0]).as_xml(query) - self.db_disconnect() + _account).as_xml(query) + else: + self.db_disconnect() return [info_query] def _account_type_get_register(self, info_query, account_class, lang_class): @@ -1054,6 +1057,7 @@ class AccountManager(object): name="name", required=True) + self.db_connect() for (field_name, field_type, field_options, @@ -1088,6 +1092,7 @@ class AccountManager(object): except: self.__logger.debug("Setting field " + field_name + " required") field.required = True + self.db_disconnect() return reg_form def get_reg_form_init(self, lang_class, _account): diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index 26a5e07..4650d94 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -804,44 +804,44 @@ class JCLComponent_TestCase(unittest.TestCase): self.comp.stream = MockStream() self.comp.stream_class = MockStream account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) - account11 = Account(user_jid = "user1@test.com", \ - name = "account11", \ - jid = "account11@jcl.test.com") - account12 = Account(user_jid = "user1@test.com", \ - name = "account12", \ - jid = "account12@jcl.test.com") - account21 = Account(user_jid = "user1@test.com", \ - name = "account21", \ - jid = "account21@jcl.test.com") + account11 = Account(user_jid="user1@test.com", + name="account11", + jid="account11@jcl.test.com") + account12 = Account(user_jid="user1@test.com", + name="account12", + jid="account12@jcl.test.com") + account21 = Account(user_jid="user1@test.com", + name="account21", + jid="account21@jcl.test.com") del account.hub.threadConnection - self.comp.handle_get_register(Iq(stanza_type = "get", \ - from_jid = "user1@test.com", \ - to_jid = "account11@jcl.test.com")) + self.comp.handle_get_register(Iq(stanza_type="get", + from_jid="user1@test.com", + to_jid="account11@jcl.test.com")) self.assertEquals(len(self.comp.stream.sent), 1) iq_sent = self.comp.stream.sent[0] self.assertEquals(iq_sent.get_to(), "user1@test.com") - titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \ - {"jir" : "jabber:iq:register", \ + titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", + {"jir" : "jabber:iq:register", "jxd" : "jabber:x:data"}) self.assertEquals(len(titles), 1) - self.assertEquals(titles[0].content, \ + self.assertEquals(titles[0].content, Lang.en.register_title) - instructions = iq_sent.xpath_eval("jir:query/jxd:x/jxd:instructions", \ - {"jir" : "jabber:iq:register", \ + instructions = iq_sent.xpath_eval("jir:query/jxd:x/jxd:instructions", + {"jir" : "jabber:iq:register", "jxd" : "jabber:x:data"}) self.assertEquals(len(instructions), 1) - self.assertEquals(instructions[0].content, \ + self.assertEquals(instructions[0].content, Lang.en.register_instructions) - fields = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field", \ - {"jir" : "jabber:iq:register", \ + fields = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field", + {"jir" : "jabber:iq:register", "jxd" : "jabber:x:data"}) self.assertEquals(len(fields), 1) self.assertEquals(fields[0].prop("type"), "hidden") self.assertEquals(fields[0].prop("var"), "name") self.assertEquals(fields[0].prop("label"), Lang.en.account_name) self.assertEquals(fields[0].children.next.name, "required") - value = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field/jxd:value", \ - {"jir" : "jabber:iq:register", \ + value = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field/jxd:value", + {"jir" : "jabber:iq:register", "jxd" : "jabber:x:data"}) self.assertEquals(len(value), 1) self.assertEquals(value[0].content, "account11") diff --git a/src/jcl/model/tests/account.py b/src/jcl/model/tests/account.py index f6d7967..5493f11 100644 --- a/src/jcl/model/tests/account.py +++ b/src/jcl/model/tests/account.py @@ -163,11 +163,15 @@ class AccountModule_TestCase(unittest.TestCase): "value") class InheritableAccount_TestCase(unittest.TestCase): + def setUp(self): + self.db_url = DB_URL + def test_get_register_fields(self): """Check if post functions and default functions execute correctly. To be validated this test only need to be executed without any exception. """ + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) for (field_name, field_type, field_options, @@ -180,29 +184,31 @@ class InheritableAccount_TestCase(unittest.TestCase): except FieldError, error: # this type of error is OK pass + del account.hub.threadConnection class Account_TestCase(InheritableAccount_TestCase): def setUp(self): if os.path.exists(DB_PATH): os.unlink(DB_PATH) - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + self.db_url = DB_URL + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) Account.createTable(ifNotExists = True) ExampleAccount.createTable(ifNotExists = True) del account.hub.threadConnection self.account_class = Account def tearDown(self): - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) ExampleAccount.dropTable(ifExists = True) Account.dropTable(ifExists = True) - del TheURIOpener.cachedURIs['sqlite://' + DB_URL] + del TheURIOpener.cachedURIs['sqlite://' + self.db_url] account.hub.threadConnection.close() del account.hub.threadConnection if os.path.exists(DB_PATH): os.unlink(DB_PATH) def test_set_status(self): - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) account11 = Account(user_jid="test1@test.com", name="account11", jid="account11@jcl.test.com") @@ -212,7 +218,7 @@ class Account_TestCase(InheritableAccount_TestCase): del account.hub.threadConnection def test_set_status_live_password(self): - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) account11 = ExampleAccount(user_jid="test1@test.com", name="account11", jid="account11@jcl.test.com", @@ -232,7 +238,8 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase): def setUp(self): if os.path.exists(DB_PATH): os.unlink(DB_PATH) - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + self.db_url = DB_URL + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) Account.createTable(ifNotExists = True) PresenceAccount.createTable(ifNotExists = True) PresenceAccountExample.createTable(ifNotExists = True) @@ -244,11 +251,11 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase): self.account_class = PresenceAccount def tearDown(self): - account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) + account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) PresenceAccountExample.dropTable(ifExists = True) PresenceAccount.dropTable(ifExists = True) Account.dropTable(ifExists = True) - del TheURIOpener.cachedURIs['sqlite://' + DB_URL] + del TheURIOpener.cachedURIs['sqlite://' + self.db_url] account.hub.threadConnection.close() del account.hub.threadConnection if os.path.exists(DB_PATH):