Ejemplo n.º 1
0
def test_configuration_loading_https_repo_url(clear_hammurabi_env,
                                              temporary_file_generator,
                                              temporary_dir):
    """
    Load only the necessary configs and check for default settings
    """

    toml_file = temporary_file_generator()
    config_file = temporary_file_generator(".py")

    temporary_dir_repo = Repo.init(temporary_dir)
    temporary_dir_repo.create_remote(
        "origin", "https://github.com/gabor-boros/hammurabi.git")

    os.chdir(temporary_dir)

    pillar_configuration = """from unittest.mock import Mock
pillar = Mock()
"""

    toml_configuration = {
        "tool": {
            "hammurabi": {
                "pillar_config": config_file.name
            }
        }
    }

    with config_file as f:
        f.write(pillar_configuration.encode("ascii"))

    with toml_file as f:
        f.write(toml.dumps(toml_configuration).encode("ascii"))

    os.environ["HAMMURABI_SETTINGS_PATH"] = toml_file.name
    config = Config()
    config.load()

    # Make sure to remove the file before going forward. In case
    # of an assert failure the fill will be deleted for sure
    os.unlink(config_file.name)
    os.unlink(toml_file.name)

    assert config.github is None
    assert (config.repo.working_dir.replace(
        "/private", "") == temporary_dir_repo.working_dir)
    assert config.settings.dict() == {
        "dry_run": False,
        "git_base_name": "master",
        "git_branch_name": "hammurabi",
        "pillar": config.settings.pillar,
        "repository": "gabor-boros/hammurabi",
        "rule_can_abort": False,
        "report_name": Path("hammurabi_report.json"),
    }
Ejemplo n.º 2
0
def test_destination_overwrite(temporary_file_generator):
    template_path = Path(temporary_file_generator().name)
    template_path.write_text("Hello {{ magic_word }}!")

    destination_path = Path(temporary_file_generator().name)
    destination_path.write_text("Here comes the greeting")

    rule = TemplateRendered(
        name="Template rendered",
        template=template_path,
        destination=destination_path,
        context={"magic_word": "World"},
    )

    rule.task()

    assert destination_path.read_text() == "Hello World!"
    destination_path.unlink()
Ejemplo n.º 3
0
def test_not_a_git_repository_path(clear_hammurabi_env, temporary_dir,
                                   temporary_file_generator, caplog):
    os.chdir(temporary_dir)

    toml_file = temporary_file_generator()
    os.environ["HAMMURABI_SETTINGS_PATH"] = toml_file.name

    with pytest.raises(RuntimeError):
        Config().load()

    record = caplog.records[0]
    assert len(caplog.records)
    assert record.levelname == "ERROR"
    assert record.message == f'"{os.getcwd()}" is not a git repository'