def test_raise_yes_exposed(self): self.source_tub.setOption("expose-remote-exception-types", True) d = self.setupTarget(TargetWithoutInterfaces()) d.addCallback(lambda rr: self.shouldFail(ValueError, "one", None, rr. callRemote, "fail")) d.addCallback(self._examine_raise, False) return d
def test_remote_attribute_error_yes_exposed(self): self._set_expose(True) rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(AttributeError, "one", None, rr.callRemote, "bogus") d.addCallback(self._examine_remote_attribute_error, False) return d
def test_raise_not_exposed(self): self._set_expose(False) rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(RemoteException, "one", None, rr.callRemote, "fail") d.addCallback(self._examine_raise, True) return d
def testCall1a(self): # no interfaces, but use positional args rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("add", 1, 2) d.addCallback(lambda res: self.assertEqual(res, 3)) d.addCallback(lambda res: self.assertEqual(target.calls, [(1, 2)])) return d
def testCall1b(self): # no interfaces, use both positional and keyword args rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("add", 1, b=2) d.addCallback(lambda res: self.failUnlessEqual(res, 3)) d.addCallback(lambda res: self.failUnlessEqual(target.calls, [(1,2)])) return d
def testFail1(self): # this is done without interfaces rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("fail") self.failIf(target.calls) d.addBoth(self._testFail1_1) return d
def test_raise_default(self): # current default is to expose exceptions. This may change in the # future. rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(ValueError, "one", None, rr.callRemote, "fail") d.addCallback(self._examine_raise, False) return d
def setUp(self): s0, s1 = self.makeTubs(2) s0.brokerClass = PingCountingBroker s1.brokerClass = PingCountingBroker self.target = TargetWithoutInterfaces() public_url = s0.registerReference(self.target, "target") self.public_url = public_url
def testCall1(self): # this is done without interfaces rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("add", a=1, b=2) d.addCallback(lambda res: self.failUnlessEqual(res, 3)) d.addCallback(lambda res: self.failUnlessEqual(target.calls, [(1,2)])) d.addCallback(self._testCall1_1, rr) return d
def testFail3(self): # this is done without interfaces rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("bogus", a=1, b=2) # the target does not have .bogus method, so we get an AttributeError self.failIf(target.calls) d.addBoth(self._testFail3_1) return d
def testFail2(self): # this is done without interfaces rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("add", a=1, b=2, c=3) # add() does not take a 'c' argument, so we get a TypeError here self.failIf(target.calls) d.addBoth(self._testFail2_1) return d
def test_remote_attribute_error_not_exposed(self): self._set_expose(False) # the target doesn't specify an interface, so the sender can't know # that the method is missing rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(RemoteException, "one", None, rr.callRemote, "bogus") d.addCallback(self._examine_remote_attribute_error, True) return d
def testFailStringException(self): # make sure we handle string exceptions correctly if sys.version_info >= (2,5): log.msg("skipping test: string exceptions are deprecated in 2.5") return rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("failstring") self.failIf(target.calls) d.addBoth(self._testFailStringException_1) return d
def setUp(self): s0, s1 = self.services = [Tub(), Tub()] s0.brokerClass = PingCountingBroker s1.brokerClass = PingCountingBroker s0.startService() s1.startService() l = s0.listenOn("tcp:0:interface=127.0.0.1") s0.setLocation("127.0.0.1:%d" % l.getPortnum()) self.target = TargetWithoutInterfaces() public_url = s0.registerReference(self.target, "target") self.public_url = public_url
def testCallOnly(self): rr, target = self.setupTarget(TargetWithoutInterfaces()) ret = rr.callRemoteOnly("add", a=1, b=2) self.failUnlessIdentical(ret, None) # since we don't have a Deferred to wait upon, we just have to poll # for the call to take place. It should happen pretty quickly. def _check(): if target.calls: self.failUnlessEqual(target.calls, [(1,2)]) return True return False d = self.poll(_check) return d
def testCopiedFailure(self): # A calls B, who calls C. C fails. B gets a CopiedFailure and reports # it back to A. What does A get? rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("fail_remotely", target) def _check(f): # f should be a CopiedFailure self.failUnless(isinstance(f, Failure), "Hey, we didn't fail: %s" % f) self.failUnless(f.check(ValueError), "wrong exception type: %s" % f) self.failUnlessSubstring("you asked me to fail", f.value) d.addBoth(_check) return d
def testBadMethod2(self): t1 = TargetWithoutInterfaces() d = self.getRef(t1) d.addCallback(lambda ref: ref.callRemote('missing', a=2, b=3)) d.addCallbacks(self._testBadMethod_cb, self._testBadMethod2_eb) return d
def testCallWithF(self): rr, target = self.setupTarget(TargetWithoutInterfaces()) d = rr.callRemote("with_f", f=1) d.addCallback(lambda res: self.assertEqual(res, 1)) return d
def testConnect1(self): t1 = TargetWithoutInterfaces() d = self.getRef(t1) d.addCallback(lambda ref: ref.callRemote('add', a=2, b=3)) d.addCallback(self._testConnect1, t1) return d
def testInterface3(self): t = TargetWithoutInterfaces() iface = getRemoteInterface(t) self.failIf(iface)
def testInterface3(self): t = TargetWithoutInterfaces() iface = getRemoteInterface(t) self.assertFalse(iface)
def test_remote_attribute_error_default(self): rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(AttributeError, 'one', None, rr.callRemote, 'bogus') d.addCallback(self._examine_remote_attribute_error, False) return d
def test_raise_yes_exposed(self): self._set_expose(True) rr, target = self.setupTarget(TargetWithoutInterfaces()) d = self.shouldFail(ValueError, "one", None, rr.callRemote, "fail") d.addCallback(self._examine_raise, False) return d