Esempio n. 1
0
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 == []
Esempio n. 2
0
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"}]
Esempio n. 3
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")
Esempio n. 4
0
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')
Esempio n. 5
0
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")
Esempio n. 6
0
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"}
Esempio n. 7
0
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")
Esempio n. 8
0
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": {}}}
Esempio n. 9
0
 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)
Esempio n. 10
0
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")
Esempio n. 11
0
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")
Esempio n. 12
0
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"}]
Esempio n. 13
0
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"]
Esempio n. 14
0
    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
Esempio n. 15
0
    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)
Esempio n. 16
0
 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)
Esempio n. 17
0
def test_wormhole_close_return_early_no_wormhole_no_emit_closed(qtbot):
    wormhole = Wormhole()
    with qtbot.assert_not_emitted(wormhole.closed):
        yield wormhole.close()
Esempio n. 18
0
def test_wormhole_init__wormhole_object_is_none():
    wormhole = Wormhole()
    assert wormhole._wormhole is None
Esempio n. 19
0
def wormhole():
    w = Wormhole()
    w._wormhole = MagicMock()
    return w