Example #1
0
def test_UI_GIVEN_valid_command_WHEN_sending_command_THEN_command_producer_sends_command(
    qtbot, instrument, settings
):

    window = FileWriterCtrl(instrument, settings)
    qtbot.addWidget(window)
    window.command_producer = Mock()

    broker = "broker1:9092/topic1"
    service_id = "12345678"

    window.command_widget.broker_line_edit.setText(broker)
    window.command_widget.start_time_enabled.setChecked(False)
    window.command_widget.stop_time_enabled.setChecked(False)
    window.command_widget.service_id_lineedit.setText(service_id)

    window.send_command()

    window.command_producer.send_command.assert_called_once()

    sent_msg = window.command_producer.send_command.call_args_list[0][0][0]

    res = run_start_pl72.deserialise_pl72(sent_msg)

    assert res.nexus_structure
    assert "children" in res.nexus_structure
    assert res.broker == broker
    assert res.service_id == service_id
    assert not window.command_widget.ok_button.isEnabled()
def test_UI_GIVEN_valid_command_WHEN_sending_command_THEN_command_producer_sends_command(
        qtbot, instrument):

    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_producer = Mock()

    broker = "broker1:9092/topic1"
    service_id = "12345678"

    window.command_widget.broker_line_edit.setText(broker)
    window.command_widget.start_time_enabled.setChecked(False)
    window.command_widget.stop_time_enabled.setChecked(False)
    window.command_widget.service_id_lineedit.setText(service_id)

    window.send_command()

    window.command_producer.send_command.assert_called_once()

    sent_msg = window.command_producer.send_command.call_args_list[0][0][0]

    res = json.loads(sent_msg)

    assert res["cmd"] == "FileWriter_new"
    assert res["nexus_structure"]
    assert res["nexus_structure"]["children"]
    assert res["broker"] == broker
    assert res["service_id"] == service_id
    assert not window.command_widget.ok_button.isEnabled()
def test_UI_GIVEN_invalid_broker_WHEN_command_broker_timer_callback_is_called_THEN_nothing_happens(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_producer = None
    window.command_broker_edit.setText("invalid")

    window.command_broker_timer_changed(DummyInterface)
    assert window.command_producer is None
def test_UI_GIVEN_command_producer_WHEN_checking_connection_status_THEN_command_led_is_turned_on(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_producer = Mock()
    window.status_consumer = None
    window.command_producer.connected = True

    window._check_connection_status()
    assert window.command_broker_led.is_on()
def test_UI_GIVEN_no_status_consumer_and_no_command_producer_WHEN_checking_status_connection_THEN_both_leds_are_turned_off(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.status_consumer = None
    window.command_producer = None

    window._check_connection_status()

    assert window.status_broker_led.is_off()
    assert window.command_broker_led.is_off()
def test_UI_GIVEN_valid_broker_WHEN_command_broker_timer_callback_is_called_THEN_producer_is_created(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_broker_change_timer.stop()
    window.status_broker_change_timer.stop()

    window.command_producer = 1  # anything that's not None
    window.command_broker_edit.setText("valid:9092/topic1")

    window.command_broker_timer_changed(DummyInterface)
    assert isinstance(window.command_producer, DummyInterface)