Changeset 100
- Timestamp:
- 07/08/07 20:42:31 (2 years ago)
- Files:
-
- src/jmc/jabber/__init__.py (modified) (1 diff)
- src/jmc/jabber/component.py (modified) (3 diffs)
- src/jmc/jabber/disco.py (added)
- src/jmc/jabber/message.py (modified) (2 diffs)
- src/jmc/jabber/presence.py (modified) (3 diffs)
- src/jmc/jabber/tests/__init__.py (modified) (1 diff)
- src/jmc/jabber/tests/component.py (modified) (50 diffs)
- src/jmc/jabber/tests/disco.py (added)
- src/jmc/model/tests/account.py (modified) (23 diffs)
- src/jmc/runner.py (modified) (2 diffs)
- src/jmc/tests/runner.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/jmc/jabber/__init__.py
r99 r100 12 12 """Define filter for email address in JID""" 13 13 14 def __init__(self ):15 Handler.__init__(self )14 def __init__(self, component): 15 Handler.__init__(self, component) 16 16 self.dest_jid_regexp = re.compile(".*%.*") 17 17 src/jmc/jabber/component.py
r99 r100 31 31 from pyxmpp.jid import JID 32 32 33 import jcl.jabber as jabber 33 34 from jcl.model.account import Account, PresenceAccount, LegacyJID 35 from jcl.jabber.disco import RootDiscoGetInfoHandler 34 36 from jcl.jabber.component import Handler, AccountManager 35 37 from jcl.jabber.feeder import FeederComponent, Feeder, MessageSender, \ 36 38 HeadlineSender, FeederHandler 37 39 40 from jmc.jabber.disco import MailRootDiscoGetInfoHandler 38 41 from jmc.jabber.message import SendMailMessageHandler, \ 39 42 RootSendMailMessageHandler … … 52 55 server, 53 56 port, 54 db_connection_str,55 57 lang=Lang()): 56 58 """Use FeederComponent behavior and setup feeder and sender … … 62 64 server, 63 65 port, 64 db_connection_str,65 66 lang=lang) 66 67 self.handler = MailFeederHandler(MailFeeder(self), MailSender(self)) 67 self.account_manager = MailAccountManager(self)68 68 self.account_manager.account_classes = (IMAPAccount, 69 69 POP3Account, 70 70 SMTPAccount) 71 self.msg_handlers += [SendMailMessageHandler(), 72 RootSendMailMessageHandler()] 73 self.subscribe_handlers += [MailSubscribeHandler()] 74 self.unsubscribe_handlers += [MailUnsubscribeHandler()] 75 self.available_handlers += [MailPresenceHandler()] 76 self.unavailable_handlers += [MailPresenceHandler()] 77 78 class MailAccountManager(AccountManager): 79 """JMC specific account behavior""" 80 81 def root_disco_get_info(self, node, name, category, type): 82 """Add jabber:iq:gateway support""" 83 disco_info = AccountManager.root_disco_get_info(self, node, name, 84 category, type) 85 disco_info.add_feature("jabber:iq:gateway") 86 disco_info.add_identity(name, "headline", "newmail") 87 return disco_info 71 self.msg_handlers += [[SendMailMessageHandler(self), 72 RootSendMailMessageHandler(self)]] 73 self.presence_subscribe_handlers += [[MailSubscribeHandler(self)]] 74 self.presence_unsubscribe_handlers += [[MailUnsubscribeHandler(self)]] 75 self.presence_available_handlers += [[MailPresenceHandler(self)]] 76 self.presence_unavailable_handlers += [[MailPresenceHandler(self)]] 77 jabber.replace_handlers(self.disco_get_info_handlers, 78 RootDiscoGetInfoHandler, 79 MailRootDiscoGetInfoHandler(self)) 88 80 89 81 class MailFeeder(Feeder): src/jmc/jabber/message.py
r99 r100 32 32 33 33 class SendMailMessageHandler(MailHandler): 34 def __init__(self ):35 MailHandler.__init__(self )34 def __init__(self, component): 35 MailHandler.__init__(self, component) 36 36 self.__logger = logging.getLogger(\ 37 37 "jmc.jabber.component.SendMailMessageHandler") … … 58 58 """Handle message sent to root JID""" 59 59 60 def __init__(self ):61 SendMailMessageHandler.__init__(self )60 def __init__(self, component): 61 SendMailMessageHandler.__init__(self, component) 62 62 self.to_regexp = re.compile("^\s*(to|TO|To)\s*:\s*(?P<to_email>.*)") 63 63 self.__logger = logging.getLogger(\ src/jmc/jabber/presence.py
r99 r100 32 32 class MailPresenceHandler(DefaultPresenceHandler): 33 33 """Define filter for legacy JIDs presence handling""" 34 def __init__(self): 35 Handler.__init__(self) 34 35 def __init__(self, component): 36 Handler.__init__(self, component) 36 37 self.dest_jid_regexp = re.compile(".*%.*") 37 38 … … 45 46 46 47 class MailSubscribeHandler(DefaultSubscribeHandler, MailHandler): 47 """Use DefaultSubscribeHandler handle method and MailHandler filter. 48 """ 49 Use DefaultSubscribeHandler handle method and MailHandler filter. 48 50 Filter email address in JID. Accept and add to LegacyJID table. 49 51 """ 50 52 51 def __init__(self ):52 DefaultSubscribeHandler.__init__(self )53 MailHandler.__init__(self )53 def __init__(self, component): 54 DefaultSubscribeHandler.__init__(self, component) 55 MailHandler.__init__(self, component) 54 56 55 57 def filter(self, stanza, lang_class): … … 66 68 67 69 class MailUnsubscribeHandler(DefaultUnsubscribeHandler, MailHandler): 68 """Use DefaultUnsubscribeHandler handle method and MailHandler filter. 70 """ 71 Use DefaultUnsubscribeHandler handle method and MailHandler filter. 69 72 """ 70 73 71 def __init__(self ):72 DefaultUnsubscribeHandler.__init__(self )73 MailHandler.__init__(self )74 def __init__(self, component): 75 DefaultUnsubscribeHandler.__init__(self, component) 76 MailHandler.__init__(self, component) 74 77 75 78 def filter(self, stanza, lang_class): src/jmc/jabber/tests/__init__.py
r68 r100 4 4 import unittest 5 5 6 from jmc.jabber.tests import component 6 from jmc.jabber.tests import component, disco 7 7 8 8 def suite(): 9 9 suite = unittest.TestSuite() 10 10 suite.addTest(component.suite()) 11 suite.addTest(disco.suite()) 11 12 return suite 12 13 src/jmc/jabber/tests/component.py
r99 r100 32 32 from pyxmpp.message import Message 33 33 34 import jcl.model as model 34 35 from jcl.model import account 35 36 from jcl.model.account import Account, PresenceAccount, LegacyJID 36 from jcl.jabber.tests. componentimport DefaultSubscribeHandler_TestCase, \37 from jcl.jabber.tests.presence import DefaultSubscribeHandler_TestCase, \ 37 38 DefaultUnsubscribeHandler_TestCase 38 39 from jcl.jabber.tests.feeder import FeederMock, SenderMock … … 46 47 MailUnsubscribeHandler, MailPresenceHandler 47 48 from jmc.jabber.component import MailComponent, MailFeederHandler, \ 48 Mail AccountManager, MailSender49 MailSender 49 50 from jmc.lang import Lang 50 51 … … 56 57 57 58 class MockStream(object): 58 def __init__(self, \59 jid ="",60 secret ="",61 server ="",62 port ="",63 keepalive =True):59 def __init__(self, 60 jid="", 61 secret="", 62 server="", 63 port="", 64 keepalive=True): 64 65 self.sent = [] 65 66 self.connection_started = False … … 74 75 if not iq_type in ["query"]: 75 76 raise Exception("IQ type unknown: " + iq_type) 76 if not ns in ["jabber:iq:version", \77 "jabber:iq:register", \78 "http://jabber.org/protocol/disco#items", \77 if not ns in ["jabber:iq:version", 78 "jabber:iq:register", 79 "http://jabber.org/protocol/disco#items", 79 80 "http://jabber.org/protocol/disco#info"]: 80 81 raise Exception("Unknown namespace: " + ns) … … 85 86 86 87 def set_presence_handler(self, status, handler): 87 if not status in ["available", \88 "unavailable", \89 "probe", \90 "subscribe", \91 "subscribed", \92 "unsubscribe", \88 if not status in ["available", 89 "unavailable", 90 "probe", 91 "subscribe", 92 "subscribed", 93 "unsubscribe", 93 94 "unsubscribed"]: 94 95 raise Exception("Status unknown: " + status) … … 163 164 "password", 164 165 "localhost", 165 "5347", 166 'sqlite://' + DB_URL) 166 "5347") 167 167 self.comp.stream = MockStream() 168 168 self.comp.stream_class = MockStream 169 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 170 Account.createTable(ifNotExists = True) 171 PresenceAccount.createTable(ifNotExists = True) 172 MailAccount.createTable(ifNotExists = True) 173 IMAPAccount.createTable(ifNotExists = True) 174 POP3Account.createTable(ifNotExists = True) 175 SMTPAccount.createTable(ifNotExists = True) 176 MockIMAPAccount.createTable(ifNotExists = True) 177 MockPOP3Account.createTable(ifNotExists = True) 178 del account.hub.threadConnection 169 model.db_connection_str = 'sqlite://' + DB_URL 170 model.db_connect() 171 Account.createTable(ifNotExists=True) 172 PresenceAccount.createTable(ifNotExists=True) 173 MailAccount.createTable(ifNotExists=True) 174 IMAPAccount.createTable(ifNotExists=True) 175 POP3Account.createTable(ifNotExists=True) 176 SMTPAccount.createTable(ifNotExists=True) 177 MockIMAPAccount.createTable(ifNotExists=True) 178 MockPOP3Account.createTable(ifNotExists=True) 179 model.db_disconnect() 179 180 180 181 def tearDown(self): 181 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)182 MockPOP3Account.dropTable(ifExists =True)183 MockIMAPAccount.dropTable(ifExists =True)184 SMTPAccount.dropTable(ifExists =True)185 POP3Account.dropTable(ifExists =True)186 IMAPAccount.dropTable(ifExists =True)187 MailAccount.dropTable(ifExists =True)188 PresenceAccount.dropTable(ifExists =True)189 Account.dropTable(ifExists =True)182 model.db_connect() 183 MockPOP3Account.dropTable(ifExists=True) 184 MockIMAPAccount.dropTable(ifExists=True) 185 SMTPAccount.dropTable(ifExists=True) 186 POP3Account.dropTable(ifExists=True) 187 IMAPAccount.dropTable(ifExists=True) 188 MailAccount.dropTable(ifExists=True) 189 PresenceAccount.dropTable(ifExists=True) 190 Account.dropTable(ifExists=True) 190 191 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 191 account.hub.threadConnection.close()192 del account.hub.threadConnection192 model.hub.threadConnection.close() 193 model.db_disconnect() 193 194 if os.path.exists(DB_PATH): 194 195 os.unlink(DB_PATH) … … 198 199 ########################################################################### 199 200 def test_feed_live_email_init_no_password(self): 200 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)201 account11 = MockIMAPAccount(user_jid = "test1@test.com", \202 name = "account11", \203 jid ="account11@jmc.test.com")201 model.db_connect() 202 account11 = MockIMAPAccount(user_jid="test1@test.com", 203 name="account11", 204 jid="account11@jmc.test.com") 204 205 account11.status = account.ONLINE 205 206 self.assertTrue(account11.first_check) … … 220 221 self.assertFalse(account11.has_connected) 221 222 self.assertFalse(account11.marked_all_as_read) 222 del account.hub.threadConnection223 model.db_disconnect() 223 224 224 225 def test_feed_live_email_init_no_password2(self): 225 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)226 model.db_connect() 226 227 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 227 228 name = "account11", \ … … 242 243 self.assertFalse(account11.marked_all_as_read) 243 244 self.assertEquals(len(self.comp.stream.sent), 0) 244 del account.hub.threadConnection245 model.db_disconnect() 245 246 246 247 def test_feed_interval_no_check(self): 247 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)248 model.db_connect() 248 249 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 249 250 name = "account11", \ … … 256 257 self.assertEquals(result, []) 257 258 self.assertEquals(account11.lastcheck, 1) 258 del account.hub.threadConnection259 model.db_disconnect() 259 260 260 261 def test_feed_interval_check(self): 261 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)262 model.db_connect() 262 263 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 263 264 name = "account11", \ … … 270 271 self.assertEquals(result, []) 271 272 self.assertEquals(account11.lastcheck, 0) 272 del account.hub.threadConnection273 model.db_disconnect() 273 274 274 275 def test_feed_no_password(self): 275 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)276 model.db_connect() 276 277 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 277 278 name = "account11", \ … … 294 295 self.assertFalse(account11.connected) 295 296 self.assertFalse(account11.has_connected) 296 del account.hub.threadConnection297 model.db_disconnect() 297 298 298 299 def test_feed_unknown_action(self): 299 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)300 model.db_connect() 300 301 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 301 302 name = "account11", \ … … 318 319 self.assertFalse(account11.connected) 319 320 self.assertTrue(account11.has_connected) 320 del account.hub.threadConnection321 model.db_disconnect() 321 322 322 323 def test_feed_retrieve_no_mail(self): 323 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)324 model.db_connect() 324 325 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 325 326 name = "account11", \ … … 339 340 self.assertTrue(account11.has_connected) 340 341 self.assertEquals(len(self.comp.stream.sent), 0) 341 del account.hub.threadConnection342 model.db_disconnect() 342 343 343 344 def test_feed_retrieve_mail(self): … … 345 346 return [("body1", "from1@test.com"), 346 347 ("body2", "from2@test.com")][index] 347 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)348 model.db_connect() 348 349 account11 = MockIMAPAccount(user_jid="test1@test.com", 349 350 name="account11", … … 376 377 % ("from2@test.com")) 377 378 self.assertEquals(result[1][2], "body2") 378 del account.hub.threadConnection379 model.db_disconnect() 379 380 380 381 def test_feed_digest_no_mail(self): 381 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)382 model.db_connect() 382 383 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 383 384 name = "account11", \ … … 397 398 self.assertTrue(account11.has_connected) 398 399 self.assertEquals(len(self.comp.stream.sent), 0) 399 del account.hub.threadConnection400 model.db_disconnect() 400 401 401 402 def test_feed_digest_mail(self): … … 403 404 return [("body1", "from1@test.com"), \ 404 405 ("body2", "from2@test.com")][index] 405 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)406 model.db_connect() 406 407 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 407 408 name = "account11", \ … … 427 428 self.assertEquals(result[0][2], \ 428 429 "body1\n----------------------------------\nbody2\n----------------------------------\n") 429 del account.hub.threadConnection430 model.db_disconnect() 430 431 431 432 ########################################################################### … … 433 434 ########################################################################### 434 435 def test_initialize_live_email(self): 435 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)436 model.db_connect() 436 437 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 437 438 name = "account11", \ … … 450 451 self.assertTrue(account11.has_connected) 451 452 self.assertTrue(account11.marked_all_as_read) 452 del account.hub.threadConnection453 model.db_disconnect() 453 454 454 455 def test_initialize_live_email_connection_error(self): 455 456 def raiser(): 456 457 raise Exception 457 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)458 model.db_connect() 458 459 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 459 460 name = "account11", \ … … 477 478 self.assertFalse(account11.has_connected) 478 479 self.assertFalse(account11.marked_all_as_read) 479 del account.hub.threadConnection480 model.db_disconnect() 480 481 481 482 def test_initialize_live_email_mark_as_read_error(self): 482 483 def raiser(): 483 484 raise Exception 484 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)485 model.db_connect() 485 486 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 486 487 name = "account11", \ … … 504 505 self.assertTrue(account11.has_connected) 505 506 self.assertFalse(account11.marked_all_as_read) 506 del account.hub.threadConnection507 model.db_disconnect() 507 508 508 509 def test_initialize_live_email_disconnection_error(self): 509 510 def raiser(): 510 511 raise Exception 511 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)512 model.db_connect() 512 513 account11 = MockIMAPAccount(user_jid = "test1@test.com", \ 513 514 name = "account11", \ … … 532 533 self.assertTrue(account11.has_connected) 533 534 self.assertTrue(account11.marked_all_as_read) 534 del account.hub.threadConnection535 model.db_disconnect() 535 536 536 537 class SendMailMessageHandler_TestCase(unittest.TestCase): 537 538 def setUp(self): 538 self.handler = SendMailMessageHandler( )539 self.handler = SendMailMessageHandler(None) 539 540 540 541 def test_handle(self): … … 557 558 Lang.en.send_mail_ok_body % ("user@test.com")) 558 559 559 class MailAccountManager_TestCase(unittest.TestCase):560 def test_root_disco_get_info(self):561 mam = MailAccountManager(None)562 disco_info = mam.root_disco_get_info(None, "JMC", "gateway", "smtp")563 self.assertTrue(disco_info.has_feature("jabber:iq:gateway"))564 self.assertEquals(len(disco_info.get_identities()), 2)565 self.assertTrue(disco_info.identity_is("gateway", "smtp"))566 self.assertTrue(disco_info.identity_is("headline", "newmail"))567 568 560 class RootSendMailMessageHandler_TestCase(unittest.TestCase): 569 561 def setUp(self): 570 self.handler = RootSendMailMessageHandler( )562 self.handler = RootSendMailMessageHandler(None) 571 563 if os.path.exists(DB_PATH): 572 564 os.unlink(DB_PATH) 573 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 574 Account.createTable(ifNotExists = True) 575 SMTPAccount.createTable(ifNotExists = True) 576 del account.hub.threadConnection 565 model.db_connection_str = 'sqlite://' + DB_URL 566 model.db_connect() 567 Account.createTable(ifNotExists=True) 568 SMTPAccount.createTable(ifNotExists=True) 569 model.db_disconnect() 577 570 578 571 def tearDown(self): 579 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)580 SMTPAccount.dropTable(ifExists =True)581 Account.dropTable(ifExists =True)572 model.db_connect() 573 SMTPAccount.dropTable(ifExists=True) 574 Account.dropTable(ifExists=True) 582 575 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 583 account.hub.threadConnection.close()584 del account.hub.threadConnection576 model.hub.threadConnection.close() 577 model.db_disconnect() 585 578 if os.path.exists(DB_PATH): 586 579 os.unlink(DB_PATH) 587 580 588 581 def test_filter(self): 589 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)582 model.db_connect() 590 583 account11 = SMTPAccount(user_jid="user1@test.com", 591 584 name="account11", … … 600 593 accounts = self.handler.filter(message, None) 601 594 self.assertEquals(accounts.count(), 1) 602 del account.hub.threadConnection595 model.db_disconnect() 603 596 604 597 def test_filter_no_default_account(self): 605 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)598 model.db_connect() 606 599 account11 = SMTPAccount(user_jid="user1@test.com", 607 600 name="account11", … … 616 609 self.assertEquals(accounts.count(), 2) 617 610 self.assertEquals(accounts[0].name, "account11") 618 del account.hub.threadConnection611 model.db_disconnect() 619 612 620 613 def test_filter_wrong_dest(self): 621 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)614 model.db_connect() 622 615 account11 = SMTPAccount(user_jid="user1@test.com", 623 616 name="account11", … … 631 624 accounts = self.handler.filter(message, None) 632 625 self.assertEquals(accounts.count(), 2) 633 del account.hub.threadConnection626 model.db_disconnect() 634 627 635 628 def test_filter_wrong_user(self): 636 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)629 model.db_connect() 637 630 account11 = SMTPAccount(user_jid="user1@test.com", 638 631 name="account11", … … 646 639 accounts = self.handler.filter(message, None) 647 640 self.assertEquals(accounts.count(), 0) 648 del account.hub.threadConnection641 model.db_disconnect() 649 642 650 643 def test_handle_email_found_in_header(self): … … 689 682 if os.path.exists(DB_PATH): 690 683 os.unlink(DB_PATH) 691 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 684 model.db_connection_str = 'sqlite://' + DB_URL 685 model.db_connect() 692 686 Account.createTable(ifNotExists=True) 693 687 PresenceAccount.createTable(ifNotExists=True) … … 695 689 IMAPAccount.createTable(ifNotExists=True) 696 690 POP3Account.createTable(ifNotExists=True) 697 del account.hub.threadConnection691 model.db_disconnect() 698 692 699 693 def tearDown(self): 700 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)694 model.db_connect() 701 695 POP3Account.dropTable(ifExists=True) 702 696 IMAPAccount.dropTable(ifExists=True) … … 705 699 Account.dropTable(ifExists=True) 706 700 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 707 account.hub.threadConnection.close()708 del account.hub.threadConnection701 model.hub.threadConnection.close() 702 model.db_disconnect() 709 703 if os.path.exists(DB_PATH): 710 704 os.unlink(DB_PATH) … … 712 706 def test_create_message(self): 713 707 mail_sender = MailSender() 714 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)708 model.db_connect() 715 709 account11 = IMAPAccount(user_jid="test1@test.com", 716 710 name="account11", … … 722 716 "message body")) 723 717 self.assertEquals(message.get_to(), account11.user_jid) 724 del account.hub.threadConnection718 model.db_disconnect() 725 719 self.assertEquals(message.get_subject(), "subject") 726 720 self.assertEquals(message.get_body(), "message body") … … 735 729 def test_create_message_digest(self): 736 730 mail_sender = MailSender() 737 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)731 model.db_connect() 738 732 account11 = IMAPAccount(user_jid="test1@test.com", 739 733 name="account11", … … 745 739 "message body")) 746 740 self.assertEquals(message.get_to(), account11.user_jid) 747 del account.hub.threadConnection741 model.db_disconnect() 748 742 self.assertEquals(message.get_subject(), "subject") 749 743 self.assertEquals(message.get_body(), "message body") … … 752 746 class MailHandler_TestCase(unittest.TestCase): 753 747 def setUp(self): 754 self.handler = MailHandler( )748 self.handler = MailHandler(None) 755 749 if os.path.exists(DB_PATH): 756 750 os.unlink(DB_PATH) 757 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 758 Account.createTable(ifNotExists = True) 759 SMTPAccount.createTable(ifNotExists = True) 760 del account.hub.threadConnection 751 model.db_connection_str = 'sqlite://' + DB_URL 752 model.db_connect() 753 Account.createTable(ifNotExists=True) 754 SMTPAccount.createTable(ifNotExists=True) 755 model.db_disconnect() 761 756 762 757 def tearDown(self): 763 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)764 SMTPAccount.dropTable(ifExists =True)765 Account.dropTable(ifExists =True)758 model.db_connect() 759 SMTPAccount.dropTable(ifExists=True) 760 Account.dropTable(ifExists=True) 766 761 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 767 account.hub.threadConnection.close()768 del account.hub.threadConnection762 model.hub.threadConnection.close() 763 model.db_disconnect() 769 764 if os.path.exists(DB_PATH): 770 765 os.unlink(DB_PATH) 771 766 772 767 def test_filter(self): 773 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)768 model.db_connect() 774 769 account11 = SMTPAccount(user_jid="user1@test.com", 775 770 name="account11", … … 786 781 self.assertEquals(accounts.count(), 1) 787 782 self.assertEquals(accounts[0].name, "account11") 788 del account.hub.threadConnection783 model.db_disconnect() 789 784 790 785 def test_filter_root(self): 791 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)786 model.db_connect() 792 787 account11 = SMTPAccount(user_jid="user1@test.com", 793 788 name="account11", … … 802 797 accounts = self.handler.filter(message, None) 803 798 self.assertEquals(accounts, None) 804 del account.hub.threadConnection799 model.db_disconnect() 805 800 806 801 def test_filter_no_default(self): 807 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)802 model.db_connect() 808 803 account11 = SMTPAccount(user_jid = "user1@test.com", \ 809 804 name = "account11", \ … … 819 814 self.assertEquals(accounts.count(), 2) 820 815 self.assertEquals(accounts[0].name, "account11") 821 del account.hub.threadConnection816 model.db_disconnect() 822 817 823 818 def test_filter_wrong_dest(self): 824 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)819 model.db_connect() 825 820 account11 = SMTPAccount(user_jid = "user1@test.com", \ 826 821 name = "account11", \ … … 834 829 accounts = self.handler.filter(message, None) 835 830 self.assertEquals(accounts, None) 836 del account.hub.threadConnection831 model.db_disconnect() 837 832 838 833 def test_filter_wrong_account(self): 839 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)834 model.db_connect() 840 835 account11 = SMTPAccount(user_jid="user1@test.com", 841 836 name="account11", … … 853 848 return 854 849 finally: 855 del account.hub.threadConnection850 model.db_disconnect() 856 851 self.fail("No exception 'NoAccountError' catched") 857 852 858 853 class MailPresenceHandler_TestCase(unittest.TestCase): 859 854 def setUp(self): 860 self.handler = MailPresenceHandler( )855 self.handler = MailPresenceHandler(None) 861 856 862 857 def test_filter(self): … … 884 879 def setUp(self): 885 880 MailHandler_TestCase.setUp(self) 886 self.handler = MailSubscribeHandler( )887 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)881 self.handler = MailSubscribeHandler(None) 882 model.db_connect() 888 883 LegacyJID.createTable(ifNotExists=True) 889 del account.hub.threadConnection884 model.db_disconnect() 890 885 891 886 def test_handle(self): 892 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)887 model.db_connect() 893 888 account11 = SMTPAccount(user_jid="user1@test.com", 894 889 name="account11", … … 900 895 legacy_jids = LegacyJID.select() 901 896 self.assertEquals(legacy_jids.count(), 1) 902 del account.hub.threadConnection897 model.db_disconnect() 903 898 904 899 class MailUnsubscribeHandler_TestCase(DefaultUnsubscribeHandler_TestCase, MailHandler_TestCase): 905 900 def setUp(self): 906 901 MailHandler_TestCase.setUp(self) 907 self.handler = MailUnsubscribeHandler( )908 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)902 self.handler = MailUnsubscribeHandler(None) 903 model.db_connect() 909 904 LegacyJID.createTable(ifNotExists=True) 910 del account.hub.threadConnection905 model.db_disconnect() 911 906 912 907 def test_handle(self): 913 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)908 model.db_connect() 914 909 account11 = SMTPAccount(user_jid="user1@test.com", 915 910 name="account11", … … 945 940 LegacyJID.q.jid == "u111%test.com@jcl.test.com") 946 941 self.assertEquals(removed_legacy_jid.count(), 0) 947 del account.hub.threadConnection942 model.db_disconnect() 948 943 949 944 class MailFeederHandler_TestCase(unittest.TestCase): … … 952 947 if os.path.exists(DB_PATH): 953 948 os.unlink(DB_PATH) 954 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL) 949 model.db_connection_str = 'sqlite://' + DB_URL 950 model.db_connect() 955 951 Account.createTable(ifNotExists=True) 956 952 PresenceAccount.createTable(ifNotExists=True) … … 959 955 POP3Account.createTable(ifNotExists=True) 960 956 SMTPAccount.createTable(ifNotExists=True) 961 del account.hub.threadConnection957 model.db_disconnect() 962 958 963 959 def tearDown(self): 964 960 self.handler = None 965 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)961 model.db_connect() 966 962 SMTPAccount.dropTable(ifExists=True) 967 963 IMAPAccount.dropTable(ifExists=True) … … 971 967 Account.dropTable(ifExists=True) 972 968 del TheURIOpener.cachedURIs['sqlite://' + DB_URL] 973 account.hub.threadConnection.close()974 del account.hub.threadConnection969 model.hub.threadConnection.close() 970 model.db_disconnect() 975 971 if os.path.exists(DB_PATH): 976 972 os.unlink(DB_PATH) 977 973 978 974 def test_filter(self): 979 account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)975 model.db_connect() 980 976 account11 = SMTPAccount(user_jid="user1@test.com", 981 977 name="account11", … … 992 988 self.assertEquals(accounts[0].name, "account12") 993 989 self.assertEquals(accounts[1].name, "account13") 994 del account.hub.threadConnection990 model.db_disconnect() 995 991 996 992 def suite(): … … 998 994 suite.addTest(unittest.makeSuite(MailComponent_TestCase, 'test')) 999 995 suite.addTest(unittest.makeSuite(SendMailMessageHandler_TestCase, 'test')) 1000 suite.addTest(unittest.makeSuite(MailAccountManager_TestCase, 'test'))1001 996 suite.addTest(unittest.makeSuite(RootSendMailMessageHandler_TestCase, 'test')) 1002 997 suite.addTest(unittest.makeSuite(MailSender_TestCase, 'test')) src/jmc/model/tests/account.py
r93 r100 30 30 from sqlobject.dbconnection import TheURIOpener 31 31 32 import jcl.model as model 32 33 from jcl.model import account 33 34 from jcl.model.account import Account, PresenceAccount … … 50 51 os.unlink(DB_PATH) 51 52 self.db_url = DB_URL 52 account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url) 53 Account.createTable(ifNotExists = True) 54 PresenceAccount.createTable(ifNotExists = True) 55 MailAccount.createTable(ifNotExists = True) 56 self.account = MailAccount(user_jid = "user1@test.com", \ 57 name = "account1", \ 58 jid = "account1@jmc.test.com") 59 del account.hub.threadConnection 53 model.db_connection_str = 'sqlite://' + self.db_url 54 model.db_connect() 55 Account.createTable(ifNotExists=True) 56 PresenceAccount.createTable(ifNotExists=True) 57 MailAccount.createTable(ifNotExists=True) 58 self.account = MailAccount(user_jid="user1@test.com", 59 name="account1", 60 jid="account1@jmc.test.com") 61 model.db_disconnect() 60 62 self.account_class = MailAccount 61 63 62 64 def tearDown(self): 63 account.hub.threadConnection = connectionForURI('sqlite://' + self.db_url)64 MailAccount.dropTable(ifExists =True)65 PresenceAccount.dropTable(ifExists =True)65 model.db_connect() 66 MailAccount.dropTable(ifExists=True) 67 PresenceAccount.dropTable(ifExists=True) 66 68 Account.dropTable(ifExists = True) 67 69 del TheURIOpener.cachedURIs['sqlite://' + self.db_url] 68 account.hub.threadConnection.close()69 del account.hub.threadConnection70 model.hub.threadConnection.close() 71 model.db_disconnect() 70 72 if os.path.exists(DB_PATH): 71 73 os.unlink(DB_PATH) … … 74 76 def inner(self): 75 77 encoded, multipart, header = email_type 76 email = email_generator.generate(encoded, \77 multipart, \78 email = email_generator.generate(encoded, 79 multipart, 78 80
