Ejemplo n.º 1
0
def test_wizard_offers_better_node_name(tmpdir, monkeypatch, wizard_answers):
    """
    When the node name does not conform, a better alternative is offered
    * Removes special chars
    * Replaces spaces with hyphens
    * Replaces underscores with hyphens
    * Converts all uppercase letters to lowercase
    """

    # Given
    wizard_answers[0] = "Küche_Unten #2"
    expected_name = "kuche-unten-2"
    monkeypatch.setattr(wz, "default_input",
                        MagicMock(side_effect=lambda _, default: default))

    config_file = tmpdir.join("test.yaml")
    input_mock = MagicMock(side_effect=wizard_answers)
    monkeypatch.setattr("builtins.input", input_mock)
    monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
    monkeypatch.setattr(wz, "sleep", lambda _: 0)
    monkeypatch.setattr(wz, "wizard_write", MagicMock())

    # When
    retval = wz.wizard(str(config_file))

    # Then
    assert retval == 0
    assert wz.default_input.call_args.args[1] == expected_name
Ejemplo n.º 2
0
def test_wizard_rejects_path_with_invalid_extension():
    """
    The wizard should reject config files that are not yaml
    """

    # Given
    config_file = "test.json"

    # When
    retval = wz.wizard(config_file)

    # Then
    assert retval == 1
Ejemplo n.º 3
0
def test_wizard_rejects_existing_files(tmpdir):
    """
    The wizard should reject any configuration file that already exists
    """

    # Given
    config_file = tmpdir.join("test.yaml")
    config_file.write("")

    # When
    retval = wz.wizard(str(config_file))

    # Then
    assert retval == 2
Ejemplo n.º 4
0
def test_wizard_accepts_default_answers_esp8266(tmpdir, monkeypatch, wizard_answers):
    """
    The wizard should accept the given default answers for esp8266
    """

    # Given
    config_file = tmpdir.join("test.yaml")
    input_mock = MagicMock(side_effect=wizard_answers)
    monkeypatch.setattr("builtins.input", input_mock)
    monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
    monkeypatch.setattr(wz, "sleep", lambda _: 0)
    monkeypatch.setattr(wz, "wizard_write", MagicMock())

    # When
    retval = wz.wizard(str(config_file))

    # Then
    assert retval == 0
Ejemplo n.º 5
0
def test_wizard_requires_valid_ssid(tmpdir, monkeypatch, wizard_answers):
    """
    When the board is not a valid esp8266 board, the wizard should reject it
    """

    # Given
    wizard_answers.insert(3, "")  # add an invalid entry for ssid

    config_file = tmpdir.join("test.yaml")
    input_mock = MagicMock(side_effect=wizard_answers)
    monkeypatch.setattr("builtins.input", input_mock)
    monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
    monkeypatch.setattr(wz, "sleep", lambda _: 0)
    monkeypatch.setattr(wz, "wizard_write", MagicMock())

    # When
    retval = wz.wizard(str(config_file))

    # Then
    assert retval == 0
Ejemplo n.º 6
0
def test_wizard_requires_correct_platform(tmpdir, monkeypatch, wizard_answers):
    """
    When the platform is not either esp32 or esp8266, the wizard should reject it
    """

    # Given
    wizard_answers.insert(1, "foobar")  # add invalid entry for platform

    config_file = tmpdir.join("test.yaml")
    input_mock = MagicMock(side_effect=wizard_answers)
    monkeypatch.setattr("builtins.input", input_mock)
    monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
    monkeypatch.setattr(wz, "sleep", lambda _: 0)
    monkeypatch.setattr(wz, "wizard_write", MagicMock())

    # When
    retval = wz.wizard(str(config_file))

    # Then
    assert retval == 0
Ejemplo n.º 7
0
def command_wizard(args):
    from esphome import wizard

    return wizard.wizard(args.configuration)
Ejemplo n.º 8
0
def command_wizard(args):
    return wizard.wizard(args.configuration)