From 33fa6f6ede260372151fe8356a95135786f36556 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 23:52:32 -0700 Subject: [PATCH] tests for new establish_key wormhole hook defered should behave similarly to the `verify` hook --- src/wormhole/test/test_wormhole.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/wormhole/test/test_wormhole.py b/src/wormhole/test/test_wormhole.py index 67ad14f..7a701df 100644 --- a/src/wormhole/test/test_wormhole.py +++ b/src/wormhole/test/test_wormhole.py @@ -522,6 +522,32 @@ class Basic(unittest.TestCase): self.assertEqual(len(pieces), 3) # nameplate plus two words self.assert_(re.search(r'^\d+-\w+-\w+$', code), code) + def _test_establish_key_hook(self, established): + + timing = DebugTiming() + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) + + if established is True: + w._key = b"key" + elif established is False: + w._key = None + else: + w._key = b"key" + w._error = WelcomeError() + + d = w.establish_key() + + if w._key is not None and established is True: + self.successResultOf(d) + elif established is False: + self.assertNot(d.called) + else: + self.failureResultOf(d) + + def test_establish_key_hook(self): + for established in (True, False, "error"): + self._test_establish_key_hook(established) + # make sure verify() can be called both before and after the verifier is # computed