def create_stub_template(): template = { "A": EnvVariable("A", "existing-value-a"), "B": EnvVariable("B", "existing-value-b"), "C": EnvVariable("C", "existing-value-c"), } return template
def mock_template(): template = { "A": EnvVariableTemplate("A", "{part1}-{part2}", [EnvVariable("part1", "A1"), EnvVariable("part2", "A2")]) } for letter in "BC": template[letter] = EnvVariable(letter, f"template-value-{letter.lower()}") return template
def create_stub_template_with_auto_variables(): template = { "A": EnvVariable("A", "existing-value-a"), "B": EnvVariable("B", "existing-value-b"), "C": EnvVariable("C", "existing-value-c"), "D": GitCommitVariable("D", 7), } return template
def test_merge_with_prompts_matching_with_skip(patched_get, mock_template): """Should merge two ordered dictionaries with matching keys and not prompt for any keys""" existing = {"A": "existing-value-a", "B": "existing-value-b"} merged = utils.merge_with_prompts(existing, mock_template, skip_existing=True) patched_get.assert_called_once_with(EnvVariable("C", "template-value-c")) assert merged["A"] == "existing-value-a" assert merged["B"] == "existing-value-b" assert merged["C"] == "new-value"
def test_prompt_user_for_value(self, patched_click): """Should request user response for key, and suggest default if provided""" patched_click.prompt.return_value = "user-response" result = utils.prompt_user_for_value( EnvVariable("test-key", "test-default")) assert result == "user-response" patched_click.prompt.assert_called_once_with("test-key", default="test-default", type=str)
def test_merge_with_prompts_matching_with_skip(self, patched_get, auto_var_template, patched_subprocess_output): """Should merge two ordered dictionaries with matching keys and not prompt for any keys""" existing = {"A": "existing-value-a", "B": "existing-value-b"} merged = utils.merge_with_prompts(existing, auto_var_template, skip_existing=True) patched_get.assert_called_once_with( EnvVariable("C", "existing-value-c")) assert merged["A"] == "existing-value-a" assert merged["B"] == "existing-value-b" assert merged["C"] == "new-value" expected_length = auto_var_template["D"].length mock_commit_hash = patched_subprocess_output.return_value assert merged["D"] == mock_commit_hash[expected_length]
def test_prompt_user_for_value_with_subvariables(patched_click): """Should request user response for each found variable and replace in template""" patched_click.prompt.side_effect = ["b", "d"] templated_var = EnvVariableTemplate("test", "{a}{c}", [EnvVariable("a", "b"), EnvVariable("c", "d")]) result = utils.prompt_user_for_value(templated_var) assert result == "bd"