## ## test_mailconnection_factory.py ## Login : David Rousselie ## Started on Fri May 20 10:46:58 2005 ## $Id: test_component.py,v 1.2 2005/09/18 20:24:07 dax Exp $ ## ## Copyright (C) 2005 ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import thread import unittest import dummy_server import time import traceback from pyxmpp import xmlextra from jmc.jabber.component import * from jmc.utils.config import Config class TestStreamHandler(xmlextra.StreamHandler): def __init__(self, expected_balises = []): xmlextra.StreamHandler.__init__(self) self.expected_balises = expected_balises def stream_start(self, doc): pass def stream_end(self, doc): pass def stanza(self, notused, node): pass class MailComponent_TestCase_NoConnection(unittest.TestCase): def setUp(self): self.mail_component = MailComponent(Config("tests/jmc-test.xml")) def tearDown(self): self.mail_component = None def test_get_reg_form(self): reg_form = self.mail_component.get_reg_form() reg_form2 = self.mail_component.get_reg_form() self.assertTrue(reg_form is reg_form2) #TODO class MailComponent_TestCase_Basic(unittest.TestCase): def setUp(self): self.handler = TestStreamHandler() self.mail_component = MailComponent(Config("tests/jmc-test.xml")) self.server = dummy_server.XMLDummyServer("localhost", 55555, None, self.handler) thread.start_new_thread(self.server.serve, ()) def tearDown(self): self.server = None self.mail_component = None os.remove("./registered.db") def test_run(self): self.server.responses = ["", \ ""] self.server.queries = ["", \ "[0-9abcdef]*", ""] self.mail_component.run(1) self.failUnless(self.server.verify_queries()) # TODO : more assertion class MailComponent_TestCase_NoReg(unittest.TestCase): def setUp(self): self.handler = TestStreamHandler() self.mail_component = MailComponent(Config("tests/jmc-test.xml")) self.server = dummy_server.XMLDummyServer("localhost", 55555, None, self.handler) thread.start_new_thread(self.server.serve, ()) def tearDown(self): self.server = None self.mail_component = None ## TODO : be storage independant os.remove("./registered.db") def test_disco_get_items(self): self.server.responses = ["", "", ""] self.server.queries = ["" + \ "", \ "[0-9abcdef]*", "", ""] self.mail_component.run(1) self.failUnless(self.server.verify_queries()) def test_get_register(self): self.server.responses = ["", "", ""] self.server.queries = ["" + \ "", \ "[0-9abcdef]*", "" + \ "" + \ "" + \ "Jabber Mail connection registration" + \ "Enter anything below" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "INBOX" + \ "" + \ "" + \ "2" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "2" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "0" + \ "" + \ "" + \ "" + \ "" + \ "" + \ "5" + \ "" + \ "" + \ "" + \ "", ""] self.mail_component.run(1) self.failUnless(self.server.verify_queries()) def test_disco_get_info(self): self.server.responses = ["", "", ""] self.server.queries = ["" + \ "", "[0-9abcdef]*", "" + \ "" + \ "" + \ "" + \ "" + \ "", ""] self.mail_component.run(1) self.failUnless(self.server.verify_queries()) def test_set_register(self): self.server.responses = ["", \ "" + \ "" + \ "" + \ "" + \ "" + \ "test" + \ "" + \ "" + \ "logintest" + \ "" + \ "" + \ "passtest" + \ "" + \ "" + \ "hosttest" + \ "" + \ "" + \ "993" + \ "" + \ "" + \ "imaps" + \ "" + \ "" + \ "INBOX" + \ "" + \ "" + \ "2" + \ "" + \ "" + \ "2" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "1" + \ "" + \ "" + \ "0" + \ "" + \ "" + \ "5" + \ "" + \ "" + \ "", lambda x: None, ""] self.server.queries = ["" + \ "", \ "[0-9abcdef]*", \ "", "", "New imaps connection \\'test\\': Registered with username \\'logintest\\' and password \\'passtest\\' on \\'hosttest:993\\'", "", ""] self.mail_component.run(1) self.failUnless(self.server.verify_queries()) class MailComponent_TestCase_Reg(unittest.TestCase): def setUp(self): self.mail_component = MailComponent(Config("tests/jmc-test.xml")) self.mail_component.set_register(iq = None) def test_get_reg_form_init(self): pass def test_get_reg_form_init_2pass(self): pass def test_disco_get_items(self): pass def test_get_register(self): pass def test_set_register_update(self): pass def test_set_register_remove(self): pass def test_presence_available_transport(self): pass def test_presence_available_mailbox(self): pass def test_presence_unavailable_transport(self): pass def test_presence_unavailable_mailbox(self): pass def test_presence_subscribe(self): pass def test_presence_subscribed_transport(self): pass def test_presence_subscribed_mailbox(self): pass def test_presence_unsubscribe(self): pass def test_presence_unsubscribed(self): pass def test_check_mail(self): pass