def test_run(self): """Test if run method of JCLComponent is executed""" self.has_run_func = False def run_func(component_self): self.has_run_func = True return (False, 0) self.runner.pid_file = "/tmp/jcl.pid" db_path = tempfile.mktemp("db", "jcltest", DB_DIR) db_url = "sqlite://" + db_path self.runner.db_url = db_url self.runner.config = None old_run_func = JCLComponent.run JCLComponent.run = run_func try: self.runner.run() finally: JCLComponent.run = old_run_func self.assertTrue(self.has_run_func) Account.dropTable() PresenceAccount.dropTable() User.dropTable() LegacyJID.dropTable() model.db_disconnect() os.unlink(db_path) self.assertFalse(os.access("/tmp/jcl.pid", os.F_OK))
def test__run(self): self.runner.pid_file = "/tmp/jcl.pid" db_path = tempfile.mktemp("db", "jcltest", DB_DIR) db_url = "sqlite://" + db_path self.runner.db_url = db_url def do_nothing(): return (False, 0) self.runner._run(do_nothing) model.db_connect() # dropTable should succeed because tables should exist Account.dropTable() PresenceAccount.dropTable() User.dropTable() LegacyJID.dropTable() model.db_disconnect() os.unlink(db_path) self.assertFalse(os.access("/tmp/jcl.pid", os.F_OK))
def test_get_root_presence_already_received_motd(self): user1 = User(jid="*****@*****.**") user1.has_received_motd = True account11 = Account(user=user1, name="account11", jid="*****@*****.**") account12 = Account(user=user1, name="account12", jid="*****@*****.**") presence = Presence(stanza_type="available", from_jid="*****@*****.**", to_jid="jcl.test.com") self.assertTrue(user1.has_received_motd) result = self.handler.get_root_presence(presence, Lang.en, 2) self.assertTrue(user1.has_received_motd) self.assertEquals(len(result), 1) self.assertTrue(isinstance(result[0], Presence)) self.assertEquals(result[0].get_to(), "*****@*****.**") self.assertEquals(result[0].get_from(), "jcl.test.com")
def test__run(self): self.runner.pid_file = "/tmp/jmc.pid" self.runner.db_url = self.db_url def do_nothing(): return (False, 0) self.runner._run(do_nothing) model.db_connection_str = self.runner.db_url model.db_connect() # dropTable should succeed because tables should exist Account.dropTable() PresenceAccount.dropTable() User.dropTable() LegacyJID.dropTable() MailAccount.dropTable() IMAPAccount.dropTable() POP3Account.dropTable() SMTPAccount.dropTable() model.db_disconnect() self.assertFalse(os.access("/tmp/jmc.pid", os.F_OK))
def test__run_restart(self): self.runner.pid_file = "/tmp/jcl.pid" db_path = tempfile.mktemp("db", "jcltest", DB_DIR) db_url = "sqlite://" + db_path self.runner.db_url = db_url self.i = 0 def restart(self): self.i += 1 yield (True, 0) self.i += 1 yield (False, 0) self.i += 1 restart_generator = restart(self) self.runner._run(lambda : restart_generator.next()) model.db_connect() # dropTable should succeed because tables should exist Account.dropTable() PresenceAccount.dropTable() User.dropTable() LegacyJID.dropTable() model.db_disconnect() os.unlink(db_path) self.assertFalse(os.access("/tmp/jcl.pid", os.F_OK)) self.assertEquals(self.i, 2)
def setup_db(self): User.createTable(ifNotExists=True) Account.createTable(ifNotExists=True) PresenceAccount.createTable(ifNotExists=True) LegacyJID.createTable(ifNotExists=True)