Make InheritableAccount_TestCase really inheritable

darcs-hash:20070612054931-86b55-8fcd5afc9a0802177f20f59a022dc0c92515d844.gz
This commit is contained in:
David Rousselie
2007-06-12 07:49:31 +02:00
parent 2d3e5a06d5
commit 62ceb22a18
3 changed files with 44 additions and 32 deletions

View File

@@ -668,8 +668,11 @@ 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)
_account).as_xml(query)
else:
self.db_disconnect()
return [info_query]
@@ -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):

View File

@@ -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", \
account11 = Account(user_jid="user1@test.com",
name="account11",
jid="account11@jcl.test.com")
account12 = Account(user_jid = "user1@test.com", \
name = "account12", \
account12 = Account(user_jid="user1@test.com",
name="account12",
jid="account12@jcl.test.com")
account21 = Account(user_jid = "user1@test.com", \
name = "account21", \
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", \
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")

View File

@@ -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):