404

[ Avaa Bypassed ]




Upload:

Command:

botdev@18.191.174.179: ~ $
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

from twisted.trial import unittest
from twisted.words.im import basesupport
from twisted.internet import error, defer

class DummyAccount(basesupport.AbstractAccount):
    """
    An account object that will do nothing when asked to start to log on.
    """

    loginHasFailed = False
    loginCallbackCalled = False

    def _startLogOn(self, *args):
        """
        Set self.loginDeferred to the same as the deferred returned, allowing a
        testcase to .callback or .errback.
        
        @return: A deferred.
        """
        self.loginDeferred = defer.Deferred()
        return self.loginDeferred

    def _loginFailed(self, result):
        self.loginHasFailed = True
        return basesupport.AbstractAccount._loginFailed(self, result)

    def _cb_logOn(self, result):
        self.loginCallbackCalled = True
        return basesupport.AbstractAccount._cb_logOn(self, result)

class DummyUI(object):
    """
    Provide just the interface required to be passed to AbstractAccount.logOn.
    """
    clientRegistered = False

    def registerAccountClient(self, result): 
        self.clientRegistered = True

class ClientMsgTests(unittest.TestCase):
    def makeUI(self):
        return DummyUI()

    def makeAccount(self):
        return DummyAccount('la', False, 'la', None, 'localhost', 6667)

    def test_connect(self):
        """
        Test that account.logOn works, and it calls the right callback when a
        connection is established.
        """
        account = self.makeAccount()
        ui = self.makeUI()
        d = account.logOn(ui)
        account.loginDeferred.callback(None)

        def check(result):
            self.assertFalse(account.loginHasFailed,
                    "Login shouldn't have failed")
            self.assertTrue(account.loginCallbackCalled,
                    "We should be logged in")
        d.addCallback(check)
        return d

    def test_failedConnect(self):
        """
        Test that account.logOn works, and it calls the right callback when a
        connection is established.
        """
        account = self.makeAccount()
        ui = self.makeUI()
        d = account.logOn(ui)
        account.loginDeferred.errback(Exception())

        def err(reason):
            self.assertTrue(account.loginHasFailed, "Login should have failed")
            self.assertFalse(account.loginCallbackCalled,
                    "We shouldn't be logged in")
            self.assertTrue(not ui.clientRegistered,
                    "Client shouldn't be registered in the UI")
        cb = lambda r: self.assertTrue(False, "Shouldn't get called back")
        d.addCallbacks(cb, err)
        return d

    def test_alreadyConnecting(self):
        """
        Test that it can fail sensibly when someone tried to connect before
        we did. 
        """
        account = self.makeAccount()
        ui = self.makeUI()
        account.logOn(ui)
        self.assertRaises(error.ConnectError, account.logOn, ui)


Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
__init__.py File 14 B 0644
test_basechat.py File 2.45 KB 0644
test_basesupport.py File 2.99 KB 0644
test_domish.py File 19.7 KB 0644
test_irc.py File 100.97 KB 0644
test_irc_service.py File 9.41 KB 0644
test_ircsupport.py File 10.45 KB 0644
test_jabberclient.py File 16.47 KB 0644
test_jabbercomponent.py File 13.87 KB 0644
test_jabbererror.py File 11.25 KB 0644
test_jabberjid.py File 7.04 KB 0644
test_jabberjstrports.py File 996 B 0644
test_jabbersasl.py File 9.21 KB 0644
test_jabbersaslmechanisms.py File 5.62 KB 0644
test_jabberxmlstream.py File 44.65 KB 0644
test_jabberxmppstringprep.py File 5.42 KB 0644
test_service.py File 27.79 KB 0644
test_tap.py File 2.13 KB 0644
test_xishutil.py File 9.18 KB 0644
test_xmlstream.py File 6.13 KB 0644
test_xmpproutertap.py File 2.34 KB 0644
test_xpath.py File 10.74 KB 0644