当前位置: 首页>>代码示例>>Python>>正文


Python AMP.callRemote方法代码示例

本文整理汇总了Python中twisted.protocols.amp.AMP.callRemote方法的典型用法代码示例。如果您正苦于以下问题:Python AMP.callRemote方法的具体用法?Python AMP.callRemote怎么用?Python AMP.callRemote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.protocols.amp.AMP的用法示例。


在下文中一共展示了AMP.callRemote方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_periodic_noops

# 需要导入模块: from twisted.protocols.amp import AMP [as 别名]
# 或者: from twisted.protocols.amp.AMP import callRemote [as 别名]
 def test_periodic_noops(self):
     """
     When connected, the protocol sends ``NoOp`` commands at a fixed
     interval.
     """
     expected_pings = 3
     reactor = Clock()
     locator = _NoOpCounter()
     peer = AMP(locator=locator)
     protocol = self.build_protocol(reactor)
     pump = connectedServerAndClient(lambda: protocol, lambda: peer)[2]
     for i in range(expected_pings):
         reactor.advance(PING_INTERVAL.total_seconds())
         peer.callRemote(NoOp)  # Keep the other side alive past its timeout
         pump.flush()
     self.assertEqual(locator.noops, expected_pings)
开发者ID:wangbinxiang,项目名称:flocker,代码行数:18,代码来源:test_protocol.py

示例2: test_adds_user

# 需要导入模块: from twisted.protocols.amp import AMP [as 别名]
# 或者: from twisted.protocols.amp.AMP import callRemote [as 别名]
    def test_adds_user(self):
        """
        When L{UserAdder} is connected to L{IdentityAdmin}, the L{AddUser}
        command is called and L{IdentityAdmin} adds the user to its factory's
        store.
        """
        admin = IdentityAdmin()
        admin.factory = self.adminFactory

        serverTransport = makeFakeServer(admin)
        serverTransport.getQ2QHost = lambda: Q2QAddress('Q2Q Host')

        client = AMP()
        pump = connect(admin, serverTransport, client, makeFakeClient(client))

        d = client.callRemote(AddUser, name='q2q username',
                              password='q2q password')
        pump.flush()

        # The username and password are added, along with the domain=q2q
        # host, to the IdentityAdmin's factory's store
        self.assertEqual([call('Q2Q Host', 'q2q username', 'q2q password')],
                         self.addUser.calls)

        # The server responds with {}
        self.assertEqual({}, self.successResultOf(d))
开发者ID:chellygel,项目名称:vertex,代码行数:28,代码来源:test_standalone.py

示例3: run_amp_command

# 需要导入模块: from twisted.protocols.amp import AMP [as 别名]
# 或者: from twisted.protocols.amp.AMP import callRemote [as 别名]
def run_amp_command(description, command, args, reactor=None):
    if reactor is None:
        from twisted.internet import reactor
    endpoint = endpoints.clientFromString(reactor, description)
    amp = AMP()
    d = endpoints.connectProtocol(endpoint, amp)
    d.addCallback(lambda ign: amp.callRemote(command, **args))
    return d
开发者ID:habnabit,项目名称:passacre-urwid,代码行数:10,代码来源:purwid.py

示例4: CredReceiverTests

# 需要导入模块: from twisted.protocols.amp import AMP [as 别名]
# 或者: from twisted.protocols.amp.AMP import callRemote [as 别名]
class CredReceiverTests(TestCase):
    """
    Tests for L{CredReceiver}, an L{IBoxReceiver} which integrates with
    L{twisted.cred} to provide authentication and authorization of AMP
    connections.
    """
    def setUp(self):
        """
        Create a L{CredReceiver} hooked up to a fake L{IBoxSender} which
        records boxes sent through it.
        """
        self.username = '[email protected]'
        self.password = 'foo bar baz'
        self.checker = InMemoryUsernamePasswordDatabaseDontUse()
        self.checker.addUser(self.username, self.password)
        self.avatar = StubAvatar()
        self.realm = StubRealm(self.avatar)
        self.portal = Portal(self.realm, [self.checker])
        self.server = CredReceiver()
        self.server.portal = self.portal
        self.client = AMP()
        self.finished = loopbackAsync(self.server, self.client)


    def test_otpLogin(self):
        """
        L{CredReceiver.otpLogin} returns without error if the pad is valid.
        """
        PAD = 'test_otpLogin'
        self.portal.registerChecker(OneTimePadChecker({PAD: 'user'}))
        d = self.server.otpLogin(PAD)
        def cbLoggedIn(result):
            self.assertEqual(result, {})
        d.addCallback(cbLoggedIn)
        return d


    def test_otpLoginUnauthorized(self):
        """
        L{CredReceiver.otpLogin} should fail with L{UnauthorizedLogin} if an
        invalid pad is received.
        """
        self.portal.registerChecker(OneTimePadChecker({}))
        return self.assertFailure(
            self.server.otpLogin('test_otpLoginUnauthorized'),
            UnauthorizedLogin)


    def test_otpLoginNotImplemented(self):
        """
        L{CredReceiver.otpLogin} should fail with L{NotImplementedError} if
        the realm raises L{NotImplementedError} when asked for the avatar.
        """
        def noAvatar(avatarId, mind, *interfaces):
            raise NotImplementedError()
        self.realm.requestAvatar = noAvatar

        PAD = 'test_otpLoginNotImplemented'
        self.portal.registerChecker(OneTimePadChecker({PAD: 'user'}))
        return self.assertFailure(
            self.server.otpLogin(PAD), NotImplementedError)


    def test_otpLoginResponder(self):
        """
        L{CredReceiver} responds to the L{OTPLogin} command.
        """
        PAD = 'test_otpLoginResponder'
        self.portal.registerChecker(OneTimePadChecker({PAD: 'user'}))
        d = self.client.callRemote(OTPLogin, pad=PAD)
        def cbLoggedIn(result):
            self.assertEqual(result, {})
        d.addCallback(cbLoggedIn)
        return d


    def test_passwordLoginDifferentChallenges(self):
        """
        L{CredReceiver.passwordLogin} returns a new challenge each time it is
        called.
        """
        first = self.server.passwordLogin(self.username)
        second = self.server.passwordLogin(self.username)
        self.assertNotEqual(first['challenge'], second['challenge'])


    def test_passwordLoginResponder(self):
        """
        L{CredReceiver} responds to the L{PasswordLogin} L{Command} with a
        challenge.
        """
        d = self.client.callRemote(PasswordLogin, username=self.username)
        def cbLogin(result):
            self.assertIn('challenge', result)
        d.addCallback(cbLogin)
        return d


    def test_determineFromDifferentNonces(self):
        """
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:epsilon,代码行数:103,代码来源:test_ampauth.py

示例5: LocalWorkerAMPTests

# 需要导入模块: from twisted.protocols.amp import AMP [as 别名]
# 或者: from twisted.protocols.amp.AMP import callRemote [as 别名]
class LocalWorkerAMPTests(TestCase):
    """
    Test case for distributed trial's manager-side local worker AMP protocol
    """

    def setUp(self):
        self.managerTransport = StringTransport()
        self.managerAMP = LocalWorkerAMP()
        self.managerAMP.makeConnection(self.managerTransport)
        self.result = TestResult()
        self.workerTransport = StringTransport()
        self.worker = AMP()
        self.worker.makeConnection(self.workerTransport)

        config = trial.Options()
        self.testName = "twisted.doesnexist"
        config['tests'].append(self.testName)
        self.testCase = trial._getSuite(config)._tests.pop()

        self.managerAMP.run(self.testCase, self.result)
        self.managerTransport.clear()


    def pumpTransports(self):
        """
        Sends data from C{self.workerTransport} to C{self.managerAMP}, and then
        data from C{self.managerTransport} back to C{self.worker}.
        """
        self.managerAMP.dataReceived(self.workerTransport.value())
        self.workerTransport.clear()
        self.worker.dataReceived(self.managerTransport.value())


    def test_runSuccess(self):
        """
        Run a test, and succeed.
        """
        results = []

        d = self.worker.callRemote(managercommands.AddSuccess,
                                   testName=self.testName)
        d.addCallback(lambda result: results.append(result['success']))
        self.pumpTransports()

        self.assertTrue(results)


    def test_runExpectedFailure(self):
        """
        Run a test, and fail expectedly.
        """
        results = []

        d = self.worker.callRemote(managercommands.AddExpectedFailure,
                                   testName=self.testName, error='error',
                                   todo='todoReason')
        d.addCallback(lambda result: results.append(result['success']))
        self.pumpTransports()

        self.assertEqual(self.testCase, self.result.expectedFailures[0][0])
        self.assertTrue(results)


    def test_runError(self):
        """
        Run a test, and encounter an error.
        """
        results = []

        d = self.worker.callRemote(managercommands.AddError,
                                   testName=self.testName, error='error',
                                   errorClass='exceptions.ValueError',
                                   frames=[])
        d.addCallback(lambda result: results.append(result['success']))
        self.pumpTransports()

        self.assertEqual(self.testCase, self.result.errors[0][0])
        self.assertTrue(results)


    def test_runErrorWithFrames(self):
        """
        L{LocalWorkerAMP._buildFailure} recreates the C{Failure.frames} from
        the C{frames} argument passed to C{AddError}.
        """
        results = []

        d = self.worker.callRemote(managercommands.AddError,
                                   testName=self.testName, error='error',
                                   errorClass='exceptions.ValueError',
                                   frames=["file.py", "invalid code", "3"])
        d.addCallback(lambda result: results.append(result['success']))
        self.pumpTransports()

        self.assertEqual(self.testCase, self.result.errors[0][0])
        self.assertEqual(
            [('file.py', 'invalid code', 3, [], [])],
            self.result.errors[0][1].frames)
        self.assertTrue(results)

#.........这里部分代码省略.........
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:103,代码来源:test_worker.py


注:本文中的twisted.protocols.amp.AMP.callRemote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。