Ejemplo n.º 1
0
def test_validate_happy_path_succeeds():
    # Arrange
    config = get_sample_config()

    # Act
    validate_configuration_data(config)

    # Assert
    pass  # exception was not raised
Ejemplo n.º 2
0
def test_validate_command_id(id, expect_pass):
    # Arrange
    config = {"commands": {id: {"cmd": "test command"}}}

    # Act
    if expect_pass:
        validate_configuration_data(config)
    else:
        with pytest.raises(ValidationError) as error_info:
            validate_configuration_data(config)
Ejemplo n.º 3
0
def test_validate_command_string_succeeds():
    # Arrange
    config = get_sample_config()
    config["commands"]["test"] = "poetry install"

    # Act
    validate_configuration_data(config)

    # Assert
    pass  # exception was not raised
Ejemplo n.º 4
0
def test_validate_command_without_cmd_fails():
    # Arrange
    config = get_sample_config()
    config["commands"]["test"].pop("cmd")

    # Act
    with pytest.raises(ValidationError) as error_info:
        validate_configuration_data(config)

    # Assert
    assert error_info.value.message == "'cmd' is a required property"
Ejemplo n.º 5
0
def test_validate_command_simple_array_succeeds():
    # Arrange
    config = get_sample_config()
    config["commands"]["test"] = [
        "poetry install", "poetry run pre-commit install"
    ]

    # Act
    validate_configuration_data(config)

    # Assert
    pass  # exception was not raised
Ejemplo n.º 6
0
def test_legacy_config_raises_DeprecatedSchemaException():
    # Arrange
    legacy_config = [
        {
            "id": "test",
            "cmd": "poetry run python -m pytest",
        },
        {
            "id": "setup",
            "cmd": "poetry install",
        },
    ]

    # Act
    # Assert
    with pytest.raises(DeprecatedSchemaException):
        validate_configuration_data(legacy_config)
Ejemplo n.º 7
0
def test_validate_env(key, value, expect_pass, config_type):
    # Arrange
    config = get_sample_config()
    if config_type == "global_env":
        config["global_env"] = {key: value}
    elif config_type == "env":
        config["commands"]["test"]["env"] = {key: value}
    elif config_type == "shortcut":
        config["shortcuts"] = {key: value}
    else:
        raise Exception("did not recognize config type {}".format(config_type))

    # Act
    if expect_pass:
        validate_configuration_data(config)
    else:
        with pytest.raises(ValidationError) as error_info:
            validate_configuration_data(config)
Ejemplo n.º 8
0
def test_legacy_config_prints_informational_message(capfd):
    # Arrange
    legacy_config = [
        {
            "id": "test",
            "cmd": "poetry run python -m pytest",
        },
        {
            "id": "setup",
            "cmd": "poetry install",
        },
    ]

    # Act
    try:
        validate_configuration_data(legacy_config)
    except Exception:
        pass
    out, err = capfd.readouterr()

    # Assert
    assert DEPRECATED_SCHEMA_MESSAGE in out
Ejemplo n.º 9
0
def test_load_config_converts_legacy_config_to_valid_config(mock_open):
    # Arrange
    mock_open.return_value = StringIO(
        textwrap.dedent("""
            - id: run
              cmd: echo "./manage.py runserver"
            - id: test
              cmd:
              - "poetry run python -m pytest"
            """))

    # Act
    result = load_config("filename")

    # Assert
    assert type(result) == dict
    # Confirm validate_configuration_data does not throw an exception
    assert validate_configuration_data(result) == None