Esempio n. 1
0
File: account.py Progetto: dax/jmc
 def test_send_email_esmtp_no_auth(self):
     model.db_connect()
     smtp_account = SMTPAccount(user=User(jid="*****@*****.**"), name="account11", jid="*****@*****.**")
     smtp_account.host = "localhost"
     smtp_account.port = 1025
     model.db_disconnect()
     email = smtp_account.create_email("*****@*****.**", "*****@*****.**", "subject", "body")
     test_func = self.make_test(
         [
             "220 localhost ESMTP\r\n",
             "250-localhost Hello 127.0.0.1\r\n" + "250-SIZE 52428800\r\n" + "250-PIPELINING\r\n" + "250 HELP\r\n",
             "250 OK\r\n",
             "250 Accepted\r\n",
             "354 Enter message\r\n",
             None,
             None,
             None,
             None,
             None,
             None,
             None,
             None,
             "250 OK\r\n",
         ],
         [
             "ehlo .*\r\n",
             "mail FROM:<" + str(email["From"]) + ">.*",
             "rcpt TO:<" + str(email["To"]) + ">\r\n",
             "data\r\n",
         ]
         + email.as_string().split("\n")
         + [".\r\n"],
         lambda self: smtp_account.send_email(email),
     )
     test_func()
Esempio n. 2
0
File: runner.py Progetto: dax/jcl
    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))
Esempio n. 3
0
File: account.py Progetto: dax/jmc
 def inner():
     self.server = server.DummyServer("localhost", 1143)
     thread.start_new_thread(self.server.serve, ())
     self.server.responses = [
         "* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + "AUTH=PLAIN]\r\n",
         lambda data: "* CAPABILITY IMAP4 "
         + "LOGIN-REFERRALS AUTH=PLAIN\r\n"
         + data.split()[0]
         + " OK CAPABILITY completed\r\n",
         lambda data: data.split()[0] + " OK LOGIN completed\r\n",
     ]
     if responses:
         self.server.responses += responses
     self.server.queries = ["^[^ ]* CAPABILITY", '^[^ ]* LOGIN login "pass"']
     if queries:
         self.server.queries += queries
     self.server.queries += ["^[^ ]* LOGOUT"]
     if not self.imap_account.connected:
         self.imap_account.connect()
     self.failUnless(self.imap_account.connection, "Cannot establish connection")
     if core:
         model.db_connect()
         core(self)
         model.db_disconnect()
     if self.imap_account.connected:
         self.imap_account.disconnect()
     self.failUnless(self.server.verify_queries())
Esempio n. 4
0
File: account.py Progetto: dax/jcl
def get_account_filter(filter, account_class=Account):
    result = None
    model.db_connect()
    accounts = account_class.select(filter)
    if accounts.count() > 0:
        result = accounts[0]
    model.db_disconnect()
    return result
Esempio n. 5
0
File: __init__.py Progetto: dax/jcl
 def tearDown(self):
     model.db_connect()
     MyMockSQLObject.dropTable(ifExists=True)
     del TheURIOpener.cachedURIs[self.db_url]
     model.hub.threadConnection.close()
     model.db_disconnect()
     if os.path.exists(self.db_path):
         os.unlink(self.db_path)
Esempio n. 6
0
File: account.py Progetto: dax/jcl
 def test_set_status(self):
     model.db_connect()
     account11 = Account(user=User(jid="*****@*****.**"),
                         name="account11",
                         jid="*****@*****.**")
     account11.status = account.OFFLINE
     self.assertEquals(account11.status, account.OFFLINE)
     model.db_disconnect()
Esempio n. 7
0
File: __init__.py Progetto: dax/jcl
 def setUp(self):
     self.db_path = tempfile.mktemp("db", "jcltest", DB_DIR)
     if os.path.exists(self.db_path):
         os.unlink(self.db_path)
     self.db_url = "sqlite://" + self.db_path
     model.db_connection_str = self.db_url
     model.db_connect()
     MyMockSQLObject.createTable(ifNotExists=True)
     model.db_disconnect()
Esempio n. 8
0
File: __init__.py Progetto: dax/jcl
 def create_account_thread():
     for i in xrange(100):
         string_attr = "obj2" + str(i)
         model.db_connect()
         obj = MyMockSQLObject(string_attr=string_attr)
         model.db_disconnect()
         model.db_connect()
         obj2 = MyMockSQLObject.select(MyMockSQLObject.q.string_attr == string_attr)
         model.db_disconnect()
         self.assertEquals(obj, obj2[0])
Esempio n. 9
0
File: account.py Progetto: dax/jcl
 def setUp(self, tables=[]):
     JCLTestCase.setUp(self, tables=[User, Account, PresenceAccount,
                                     PresenceAccountExample] + tables)
     model.db_connect()
     self.account = PresenceAccountExample(\
         user=User(jid="*****@*****.**"),
         name="account11",
         jid="*****@*****.**")
     model.db_disconnect()
     self.account_class = PresenceAccount
Esempio n. 10
0
File: account.py Progetto: dax/jmc
 def setUp(self):
     JCLTestCase.setUp(self, tables=[Account, PresenceAccount, User, MailAccount, POP3Account])
     self.pop3_account = POP3Account(
         user=User(jid="*****@*****.**"), name="account1", jid="*****@*****.**", login="******"
     )
     self.pop3_account.password = "******"
     self.pop3_account.host = "localhost"
     self.pop3_account.port = 1110
     self.pop3_account.ssl = False
     model.db_disconnect()
     self.account_class = POP3Account
Esempio n. 11
0
File: account.py Progetto: dax/jmc
 def test_send_email_esmtp_auth_method2(self):
     model.db_connect()
     smtp_account = SMTPAccount(user=User(jid="*****@*****.**"), name="account11", jid="*****@*****.**")
     smtp_account.host = "localhost"
     smtp_account.port = 1025
     smtp_account.login = "******"
     smtp_account.password = "******"
     model.db_disconnect()
     email = smtp_account.create_email("*****@*****.**", "*****@*****.**", "subject", "body")
     test_func = self.make_test(
         [
             "220 localhost ESMTP\r\n",
             "250-localhost Hello 127.0.0.1\r\n"
             + "250-SIZE 52428800\r\n"
             + "250-AUTH PLAIN LOGIN CRAM-MD5\r\n"
             + "250-PIPELINING\r\n"
             + "250 HELP\r\n",
             "334 ZGF4IDNmNDM2NzY0YzBhNjgyMTQ1MzhhZGNiMjE2YTYxZjRm\r\n",
             "535 Incorrect Authentication data\r\n",
             "334 asd235r4\r\n",
             "235 Authentication succeeded\r\n",
             "250 OK\r\n",
             "250 Accepted\r\n",
             "354 Enter message\r\n",
             None,
             None,
             None,
             None,
             None,
             None,
             None,
             None,
             "250 OK\r\n",
         ],
         [
             "ehlo .*\r\n",
             "AUTH CRAM-MD5\r\n",
             ".*\r\n",
             "AUTH LOGIN .*\r\n",
             ".*\r\n",
             "mail FROM:<" + str(email["From"]) + ">.*",
             "rcpt TO:<" + str(email["To"]) + ">\r\n",
             "data\r\n",
         ]
         + email.as_string().split("\n")
         + [".\r\n"],
         lambda self: smtp_account.send_email(email),
     )
     test_func()
Esempio n. 12
0
File: message.py Progetto: dax/jcl
 def test_filter_not_password_account(self):
     model.db_connect()
     user1 = User(jid="*****@*****.**")
     account11 = Account(user=user1,
                         name="account11",
                         jid="*****@*****.**")
     account12 = Account(user=user1,
                         name="account12",
                         jid="*****@*****.**")
     message = Message(from_jid="*****@*****.**",
                       to_jid="*****@*****.**",
                       subject="[PASSWORD]",
                       body="secret")
     _account = self.handler.filter(message, None)
     self.assertEquals(_account, None)
     model.db_disconnect()
Esempio n. 13
0
File: account.py Progetto: dax/jmc
 def inner():
     self.server = server.DummyServer("localhost", 1025)
     thread.start_new_thread(self.server.serve, ())
     self.server.responses = []
     if responses:
         self.server.responses += responses
     self.server.responses += ["221 localhost closing connection\r\n"]
     self.server.queries = []
     if queries:
         self.server.queries += queries
     self.server.queries += ["quit\r\n"]
     if core:
         model.db_connect()
         core(self)
         model.db_disconnect()
     self.failUnless(self.server.verify_queries())
Esempio n. 14
0
File: account.py Progetto: dax/jcl
 def test_set_status_live_password(self):
     model.db_connect()
     account11 = ExampleAccount(user=User(jid="*****@*****.**"),
                                name="account11",
                                jid="*****@*****.**",
                                login="******",
                                password="******",
                                store_password=False,
                                test_enum="choice3",
                                test_int=21)
     account11.waiting_password_reply = True
     account11.status = account.OFFLINE
     self.assertEquals(account11.status, account.OFFLINE)
     self.assertEquals(account11.waiting_password_reply, False)
     self.assertEquals(account11.password, None)
     model.db_disconnect()
Esempio n. 15
0
File: feeder.py Progetto: dax/jcl
 def test_send(self):
     self.comp.stream = MockStream()
     self.comp.stream_class = MockStream
     model.db_connect()
     account11 = Account(user=User(jid="*****@*****.**"),
                         name="account11",
                         jid="*****@*****.**")
     self.sender.send(account11, ("subject", "Body message"))
     self.assertEquals(len(self.comp.stream.sent), 1)
     message = self.comp.stream.sent[0]
     self.assertEquals(message.get_from(), account11.jid)
     self.assertEquals(message.get_to(), account11.user.jid)
     self.assertEquals(message.get_subject(), "subject")
     self.assertEquals(message.get_body(), "Body message")
     self.assertEquals(message.get_type(), self.message_type)
     model.db_disconnect()
Esempio n. 16
0
File: message.py Progetto: dax/jcl
 def test_filter_waiting_password(self):
     model.db_connect()
     user1 = User(jid="*****@*****.**")
     account11 = ExampleAccount(user=user1,
                                name="account11",
                                jid="*****@*****.**")
     account11.waiting_password_reply = True
     account12 = ExampleAccount(user=user1,
                                name="account12",
                                jid="*****@*****.**")
     message = Message(from_jid="[email protected]/resource",
                       to_jid="*****@*****.**",
                       subject="[PASSWORD]",
                       body="secret")
     _account = self.handler.filter(message, None)
     self.assertEquals(_account.name, "account11")
     model.db_disconnect()
Esempio n. 17
0
File: message.py Progetto: dax/jcl
 def test_handle(self):
     model.db_connect()
     user1 = User(jid="*****@*****.**")
     account11 = ExampleAccount(user=user1,
                                name="account11",
                                jid="*****@*****.**")
     account12 = ExampleAccount(user=user1,
                                name="account12",
                                jid="*****@*****.**")
     message = Message(from_jid="[email protected]/resource",
                       to_jid="*****@*****.**",
                       subject="[PASSWORD]",
                       body="secret")
     messages = self.handler.handle(message, Lang.en, account11)
     self.assertEquals(len(messages), 1)
     self.assertEquals(account11.password, "secret")
     model.db_disconnect()
Esempio n. 18
0
File: message.py Progetto: dax/jcl
 def test_filter_not_good_message(self):
     model.db_connect()
     user1 = User(jid="*****@*****.**")
     account11 = ExampleAccount(user=user1,
                                name="account11",
                                jid="*****@*****.**")
     account11.waiting_password_reply = True
     account12 = ExampleAccount(user=user1,
                                name="account12",
                                jid="*****@*****.**")
     message = Message(from_jid="*****@*****.**",
                       to_jid="*****@*****.**",
                       subject="[WRONG MESSAGE]",
                       body="secret")
     _account = self.handler.filter(message, None)
     self.assertEquals(_account, None)
     model.db_disconnect()
Esempio n. 19
0
File: runner.py Progetto: dax/jcl
 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))
Esempio n. 20
0
File: account.py Progetto: dax/jmc
 def inner(self):
     self.server = server.DummyServer("localhost", 1110)
     thread.start_new_thread(self.server.serve, ())
     self.server.responses = ["+OK connected\r\n", "+OK name is a valid mailbox\r\n", "+OK pass\r\n"]
     if responses:
         self.server.responses += responses
     self.server.queries = ["USER login\r\n", "PASS pass\r\n"]
     if queries:
         self.server.queries += queries
     self.server.queries += ["QUIT\r\n"]
     self.pop3_account.connect()
     self.failUnless(self.pop3_account.connection, "Cannot establish connection")
     if core:
         model.db_connect()
         core(self)
         model.db_disconnect()
     self.pop3_account.disconnect()
     self.failUnless(self.server.verify_queries(), "Sended queries does not match expected queries.")
Esempio n. 21
0
File: runner.py Progetto: dax/jmc
 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))
Esempio n. 22
0
File: runner.py Progetto: dax/jcl
 def _run(self, run_func):
     if self.console:
         self.run_console()
     else:
         try:
             self.setup_pidfile()
             model.db_connection_str = self.db_url
             model.db_connect()
             self.setup_db()
             model.db_disconnect()
             self.logger.debug(self.component_name + " v" +
                               self.component_version + " is starting ...")
             restart = True
             while restart:
                 (restart, time_to_wait) = run_func()
                 self.wait_event.wait(time_to_wait)
             self.logger.debug(self.component_name + " is exiting")
         finally:
             if os.path.exists(self.pid_file):
                 os.remove(self.pid_file)
Esempio n. 23
0
File: __init__.py Progetto: dax/jcl
 def test_multiple_db_connection(self):
     def create_account_thread():
         for i in xrange(100):
             string_attr = "obj2" + str(i)
             model.db_connect()
             obj = MyMockSQLObject(string_attr=string_attr)
             model.db_disconnect()
             model.db_connect()
             obj2 = MyMockSQLObject.select(MyMockSQLObject.q.string_attr == string_attr)
             model.db_disconnect()
             self.assertEquals(obj, obj2[0])
     timer_thread = threading.Thread(target=create_account_thread,
                                     name="CreateAccountThread")
     timer_thread.start()
     for i in xrange(100):
         string_attr = "obj1" + str(i)
         model.db_connect()
         obj = MyMockSQLObject(string_attr=string_attr)
         model.db_disconnect()
         model.db_connect()
         obj2 = MyMockSQLObject.select(MyMockSQLObject.q.string_attr == string_attr)
         model.db_disconnect()
         self.assertEquals(obj, obj2[0])
     timer_thread.join(2)
     threads = threading.enumerate()
     self.assertEquals(len(threads), 1)
     model.db_connect()
     objs = MyMockSQLObject.select()
     self.assertEquals(objs.count(), 200)
     model.db_disconnect()
Esempio n. 24
0
File: runner.py Progetto: dax/jcl
 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)