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 _init(self, *args, **kw): """MailAccount init Initialize class attributes""" PresenceAccount._init(self, *args, **kw) self.__logger = logging.getLogger("jmc.model.account.MailAccount") self.connection = None self.connected = False self.default_lang_class = Lang.en
def _get_register_fields(cls, real_class=None): """ See Account._get_register_fields """ if real_class is None: real_class = cls return PresenceAccount.get_register_fields(real_class) + \ [("login", "text-single", None, validate_login, lambda bare_from_jid: ""), ("password", "text-private", None, validate_password, lambda bare_from_jid: ""), ("host", "text-single", None, validate_host, lambda bare_from_jid: ""), ("port", "text-single", None, account.int_post_func, lambda bare_from_jid: real_class.get_default_port()), ("ssl", "boolean", None, account.boolean_post_func, lambda bare_from_jid: False), ("store_password", "boolean", None, account.boolean_post_func, lambda bare_from_jid: True), ("live_email_only", "boolean", None, account.boolean_post_func, lambda bare_from_jid: False), ("interval", "text-single", None, account.int_post_func, lambda bare_from_jid: 5)]
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__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)
def _get_register_fields(cls, real_class=None): if real_class is None: real_class = cls return PresenceAccount.get_register_fields(real_class) + \ [("test_new_int", "text-single", None, account.int_post_func, lambda bare_from_jid: 43)]
def set_status(self, status): """Set current Jabber status""" if status != account.OFFLINE and self._status == account.OFFLINE: PresenceAccount.set_status(self, status) self.first_check = True self._status = status