def test_wormhole_close_emit_closed_signal_with_wormhole_error_pass(qtbot): wormhole = Wormhole() wormhole._wormhole = MagicMock() wormhole._wormhole.close = MagicMock(side_effect=WormholeError()) with qtbot.wait_signal(wormhole.closed) as blocker: yield wormhole.close() assert blocker.args == []
def test_wormhole_connect_emit_got_welcome_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {"current_cli_version": "0"} monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.got_welcome) as blocker: yield wormhole.connect() assert blocker.args == [{"current_cli_version": "0"}]
def test_wormhole_send_raise_upgrade_required_no_abilities(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = b'{"blah": "blah"}' monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with pytest.raises(UpgradeRequiredError): yield wormhole.send("Testing", "123-test-test")
def test_wormhole_receive_emit_got_introduction_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = \ b'{"abilities": {"server-v1": {}}}' monkeypatch.setattr('gridsync.wormhole_.wormhole.create', lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.got_introduction): yield wormhole.receive('123-test-test')
def test_wormhole_send_emit_got_introduction_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"abilities": {"client-v1": {}}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.got_introduction): yield wormhole.send("Testing", "123-test-test")
def test_wormhole_receive_via_xfer_util(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"offer": {"message": "{\\"nickname\\": \\"Test Grid\\"}"}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() output = yield wormhole.receive("123-test-test") assert output == {"nickname": "Test Grid"}
def test_wormhole_send_raise_upgrade_required_bad_version(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"abilities": {"server-v9999": {}}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with pytest.raises(UpgradeRequiredError): yield wormhole.send("Testing", "123-test-test")
def test_wormhole_receive_succeed_return_msg_dict(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"abilities": {"server-v1": {}}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() output = yield wormhole.receive("123-test-test") assert output == {"abilities": {"server-v1": {}}}
def go(self): self.wormhole = Wormhole(self.use_tor) self.wormhole.got_code.connect(self.on_got_code) self.wormhole.got_introduction.connect(self.on_got_introduction) self.wormhole.send_completed.connect(self.on_send_completed) self.settings = self.gateway.get_settings() if self.folder_names: folders_data = yield self.get_folder_invites() self.settings['magic-folders'] = folders_data self.subtext_label.setText("Opening wormhole...\n\n") self.wormhole.send(self.settings).addErrback(self.handle_failure)
def test_wormhole_receive_via_xfer_util_raise_unknown_offer( qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"offer": {"NOT_message": "{\\"nickname\\": \\"Test Grid\\"}"}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with pytest.raises(Exception): yield wormhole.receive("123-test-test")
def test_wormhole_send_succeed_emit_send_completed_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"abilities": {"client-v1": {}}}') fake_wormhole.get_code.return_value = "9999-test-code" monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.send_completed): yield wormhole.send("Testing")
def test_wormhole_receive_succeed_emit_got_message_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"offer": {"message": "{\\"nickname\\": \\"Test Grid\\"}"}}') monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.got_message) as blocker: yield wormhole.receive("123-test-test") assert blocker.args == [{"nickname": "Test Grid"}]
def test_wormhole_send_allocate_code_emit_got_code_signal(qtbot, monkeypatch): fake_wormhole = MagicMock() fake_wormhole.get_welcome.return_value = {} fake_wormhole.get_message.return_value = ( b'{"abilities": {"client-v1": {}}}') fake_wormhole.get_code.return_value = "9999-test-code" monkeypatch.setattr("gridsync.wormhole_.wormhole.create", lambda x, y, z: fake_wormhole) wormhole = Wormhole() with qtbot.wait_signal(wormhole.got_code) as blocker: yield wormhole.send("Testing") assert blocker.args == ["9999-test-code"]
def __init__(self, use_tor=False): super(InviteSender, self).__init__() self.use_tor = use_tor self.wormhole = Wormhole(use_tor) self.wormhole.got_welcome.connect(self.got_welcome.emit) self.wormhole.got_code.connect(self.got_code.emit) self.wormhole.got_introduction.connect(self.got_introduction.emit) self.wormhole.send_completed.connect(self.send_completed.emit) self.wormhole.closed.connect(self.closed.emit) self._pending_invites = [] self._gateway = None
def __init__(self, known_gateways=None, use_tor=False): super(InviteReceiver, self).__init__() self.known_gateways = known_gateways self.use_tor = use_tor self.setup_runner = SetupRunner(known_gateways, use_tor) self.setup_runner.grid_already_joined.connect( self.grid_already_joined.emit) self.setup_runner.update_progress.connect(self.update_progress.emit) self.setup_runner.got_icon.connect(self.got_icon.emit) self.setup_runner.client_started.connect(self.client_started.emit) self.setup_runner.joined_folders.connect(self.joined_folders.emit) self.setup_runner.done.connect(self.done.emit) self.wormhole = Wormhole(use_tor) self.wormhole.got_welcome.connect(self.got_welcome.emit) self.wormhole.got_introduction.connect(self.got_introduction.emit) self.wormhole.got_message.connect(self.got_message.emit) self.wormhole.closed.connect(self.closed.emit)
def go(self, code): self.reset() self.label.setText(' ') self.lineedit.hide() self.tor_checkbox.hide() self.progressbar.show() if self.use_tor: self.tor_label.show() self.update_progress("Verifying invitation...") # 1 if code.split('-')[0] == "0": settings = get_settings_from_cheatcode(code[2:]) if settings: self.got_message(settings) return self.wormhole = Wormhole(self.use_tor) self.wormhole.got_welcome.connect(self.got_welcome) self.wormhole.got_message.connect(self.got_message) d = self.wormhole.receive(code) d.addErrback(self.handle_failure) reactor.callLater(30, d.cancel)
def test_wormhole_close_return_early_no_wormhole_no_emit_closed(qtbot): wormhole = Wormhole() with qtbot.assert_not_emitted(wormhole.closed): yield wormhole.close()
def test_wormhole_init__wormhole_object_is_none(): wormhole = Wormhole() assert wormhole._wormhole is None
def wormhole(): w = Wormhole() w._wormhole = MagicMock() return w