Make InheritableAccount_TestCase really inheritable
darcs-hash:20070612054931-86b55-8fcd5afc9a0802177f20f59a022dc0c92515d844.gz
This commit is contained in:
@@ -668,9 +668,12 @@ class AccountManager(object):
|
|||||||
account_class.q.user_jid == unicode(from_jid.bare())))
|
account_class.q.user_jid == unicode(from_jid.bare())))
|
||||||
if accounts is not None:
|
if accounts is not None:
|
||||||
query = info_query.new_query("jabber:iq:register")
|
query = info_query.new_query("jabber:iq:register")
|
||||||
|
_account = accounts[0]
|
||||||
|
self.db_disconnect()
|
||||||
self.get_reg_form_init(lang_class,
|
self.get_reg_form_init(lang_class,
|
||||||
accounts[0]).as_xml(query)
|
_account).as_xml(query)
|
||||||
self.db_disconnect()
|
else:
|
||||||
|
self.db_disconnect()
|
||||||
return [info_query]
|
return [info_query]
|
||||||
|
|
||||||
def _account_type_get_register(self, info_query, account_class, lang_class):
|
def _account_type_get_register(self, info_query, account_class, lang_class):
|
||||||
@@ -1054,6 +1057,7 @@ class AccountManager(object):
|
|||||||
name="name",
|
name="name",
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
|
self.db_connect()
|
||||||
for (field_name,
|
for (field_name,
|
||||||
field_type,
|
field_type,
|
||||||
field_options,
|
field_options,
|
||||||
@@ -1088,6 +1092,7 @@ class AccountManager(object):
|
|||||||
except:
|
except:
|
||||||
self.__logger.debug("Setting field " + field_name + " required")
|
self.__logger.debug("Setting field " + field_name + " required")
|
||||||
field.required = True
|
field.required = True
|
||||||
|
self.db_disconnect()
|
||||||
return reg_form
|
return reg_form
|
||||||
|
|
||||||
def get_reg_form_init(self, lang_class, _account):
|
def get_reg_form_init(self, lang_class, _account):
|
||||||
|
|||||||
@@ -804,44 +804,44 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
account11 = Account(user_jid = "user1@test.com", \
|
account11 = Account(user_jid="user1@test.com",
|
||||||
name = "account11", \
|
name="account11",
|
||||||
jid = "account11@jcl.test.com")
|
jid="account11@jcl.test.com")
|
||||||
account12 = Account(user_jid = "user1@test.com", \
|
account12 = Account(user_jid="user1@test.com",
|
||||||
name = "account12", \
|
name="account12",
|
||||||
jid = "account12@jcl.test.com")
|
jid="account12@jcl.test.com")
|
||||||
account21 = Account(user_jid = "user1@test.com", \
|
account21 = Account(user_jid="user1@test.com",
|
||||||
name = "account21", \
|
name="account21",
|
||||||
jid = "account21@jcl.test.com")
|
jid="account21@jcl.test.com")
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
self.comp.handle_get_register(Iq(stanza_type="get",
|
||||||
from_jid = "user1@test.com", \
|
from_jid="user1@test.com",
|
||||||
to_jid = "account11@jcl.test.com"))
|
to_jid="account11@jcl.test.com"))
|
||||||
self.assertEquals(len(self.comp.stream.sent), 1)
|
self.assertEquals(len(self.comp.stream.sent), 1)
|
||||||
iq_sent = self.comp.stream.sent[0]
|
iq_sent = self.comp.stream.sent[0]
|
||||||
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
self.assertEquals(iq_sent.get_to(), "user1@test.com")
|
||||||
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title", \
|
titles = iq_sent.xpath_eval("jir:query/jxd:x/jxd:title",
|
||||||
{"jir" : "jabber:iq:register", \
|
{"jir" : "jabber:iq:register",
|
||||||
"jxd" : "jabber:x:data"})
|
"jxd" : "jabber:x:data"})
|
||||||
self.assertEquals(len(titles), 1)
|
self.assertEquals(len(titles), 1)
|
||||||
self.assertEquals(titles[0].content, \
|
self.assertEquals(titles[0].content,
|
||||||
Lang.en.register_title)
|
Lang.en.register_title)
|
||||||
instructions = iq_sent.xpath_eval("jir:query/jxd:x/jxd:instructions", \
|
instructions = iq_sent.xpath_eval("jir:query/jxd:x/jxd:instructions",
|
||||||
{"jir" : "jabber:iq:register", \
|
{"jir" : "jabber:iq:register",
|
||||||
"jxd" : "jabber:x:data"})
|
"jxd" : "jabber:x:data"})
|
||||||
self.assertEquals(len(instructions), 1)
|
self.assertEquals(len(instructions), 1)
|
||||||
self.assertEquals(instructions[0].content, \
|
self.assertEquals(instructions[0].content,
|
||||||
Lang.en.register_instructions)
|
Lang.en.register_instructions)
|
||||||
fields = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field", \
|
fields = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field",
|
||||||
{"jir" : "jabber:iq:register", \
|
{"jir" : "jabber:iq:register",
|
||||||
"jxd" : "jabber:x:data"})
|
"jxd" : "jabber:x:data"})
|
||||||
self.assertEquals(len(fields), 1)
|
self.assertEquals(len(fields), 1)
|
||||||
self.assertEquals(fields[0].prop("type"), "hidden")
|
self.assertEquals(fields[0].prop("type"), "hidden")
|
||||||
self.assertEquals(fields[0].prop("var"), "name")
|
self.assertEquals(fields[0].prop("var"), "name")
|
||||||
self.assertEquals(fields[0].prop("label"), Lang.en.account_name)
|
self.assertEquals(fields[0].prop("label"), Lang.en.account_name)
|
||||||
self.assertEquals(fields[0].children.next.name, "required")
|
self.assertEquals(fields[0].children.next.name, "required")
|
||||||
value = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field/jxd:value", \
|
value = iq_sent.xpath_eval("jir:query/jxd:x/jxd:field/jxd:value",
|
||||||
{"jir" : "jabber:iq:register", \
|
{"jir" : "jabber:iq:register",
|
||||||
"jxd" : "jabber:x:data"})
|
"jxd" : "jabber:x:data"})
|
||||||
self.assertEquals(len(value), 1)
|
self.assertEquals(len(value), 1)
|
||||||
self.assertEquals(value[0].content, "account11")
|
self.assertEquals(value[0].content, "account11")
|
||||||
|
|||||||
@@ -163,11 +163,15 @@ class AccountModule_TestCase(unittest.TestCase):
|
|||||||
"value")
|
"value")
|
||||||
|
|
||||||
class InheritableAccount_TestCase(unittest.TestCase):
|
class InheritableAccount_TestCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.db_url = DB_URL
|
||||||
|
|
||||||
def test_get_register_fields(self):
|
def test_get_register_fields(self):
|
||||||
"""Check if post functions and default functions execute correctly.
|
"""Check if post functions and default functions execute correctly.
|
||||||
To be validated this test only need to be executed without any
|
To be validated this test only need to be executed without any
|
||||||
exception.
|
exception.
|
||||||
"""
|
"""
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url)
|
||||||
for (field_name,
|
for (field_name,
|
||||||
field_type,
|
field_type,
|
||||||
field_options,
|
field_options,
|
||||||
@@ -180,29 +184,31 @@ class InheritableAccount_TestCase(unittest.TestCase):
|
|||||||
except FieldError, error:
|
except FieldError, error:
|
||||||
# this type of error is OK
|
# this type of error is OK
|
||||||
pass
|
pass
|
||||||
|
del account.hub.threadConnection
|
||||||
|
|
||||||
class Account_TestCase(InheritableAccount_TestCase):
|
class Account_TestCase(InheritableAccount_TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if os.path.exists(DB_PATH):
|
if os.path.exists(DB_PATH):
|
||||||
os.unlink(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)
|
Account.createTable(ifNotExists = True)
|
||||||
ExampleAccount.createTable(ifNotExists = True)
|
ExampleAccount.createTable(ifNotExists = True)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
self.account_class = Account
|
self.account_class = Account
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url)
|
||||||
ExampleAccount.dropTable(ifExists = True)
|
ExampleAccount.dropTable(ifExists = True)
|
||||||
Account.dropTable(ifExists = True)
|
Account.dropTable(ifExists = True)
|
||||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||||
account.hub.threadConnection.close()
|
account.hub.threadConnection.close()
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
if os.path.exists(DB_PATH):
|
if os.path.exists(DB_PATH):
|
||||||
os.unlink(DB_PATH)
|
os.unlink(DB_PATH)
|
||||||
|
|
||||||
def test_set_status(self):
|
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",
|
account11 = Account(user_jid="test1@test.com",
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jcl.test.com")
|
jid="account11@jcl.test.com")
|
||||||
@@ -212,7 +218,7 @@ class Account_TestCase(InheritableAccount_TestCase):
|
|||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
def test_set_status_live_password(self):
|
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",
|
account11 = ExampleAccount(user_jid="test1@test.com",
|
||||||
name="account11",
|
name="account11",
|
||||||
jid="account11@jcl.test.com",
|
jid="account11@jcl.test.com",
|
||||||
@@ -232,7 +238,8 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
if os.path.exists(DB_PATH):
|
if os.path.exists(DB_PATH):
|
||||||
os.unlink(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)
|
Account.createTable(ifNotExists = True)
|
||||||
PresenceAccount.createTable(ifNotExists = True)
|
PresenceAccount.createTable(ifNotExists = True)
|
||||||
PresenceAccountExample.createTable(ifNotExists = True)
|
PresenceAccountExample.createTable(ifNotExists = True)
|
||||||
@@ -244,11 +251,11 @@ class PresenceAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
self.account_class = PresenceAccount
|
self.account_class = PresenceAccount
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url)
|
||||||
PresenceAccountExample.dropTable(ifExists = True)
|
PresenceAccountExample.dropTable(ifExists = True)
|
||||||
PresenceAccount.dropTable(ifExists = True)
|
PresenceAccount.dropTable(ifExists = True)
|
||||||
Account.dropTable(ifExists = True)
|
Account.dropTable(ifExists = True)
|
||||||
del TheURIOpener.cachedURIs['sqlite://' + DB_URL]
|
del TheURIOpener.cachedURIs['sqlite://' + self.db_url]
|
||||||
account.hub.threadConnection.close()
|
account.hub.threadConnection.close()
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
if os.path.exists(DB_PATH):
|
if os.path.exists(DB_PATH):
|
||||||
|
|||||||
Reference in New Issue
Block a user