diff --git a/commodore/git.py b/commodore/git.py index 9d39da8d8..d24dd504f 100644 --- a/commodore/git.py +++ b/commodore/git.py @@ -161,10 +161,10 @@ def stage_all(repo): # and a_blob as after. before = c.b_blob.data_stream.read().decode('utf-8').split('\n') after = c.a_blob.data_stream.read().decode('utf-8').split('\n') - diff = difflib.unified_diff(before, after, lineterm='', - fromfile=c.b_path, tofile=c.a_path) - diff = [_colorize_diff(line) for line in diff] - difftext.append('\n'.join(diff).strip()) + diff_lines = difflib.unified_diff(before, after, lineterm='', + fromfile=c.b_path, tofile=c.a_path) + diff_lines = [_colorize_diff(line) for line in diff_lines] + difftext.append('\n'.join(diff_lines).strip()) return '\n'.join(difftext), changed diff --git a/tests/test_git.py b/tests/test_git.py new file mode 100644 index 000000000..abdd9acc2 --- /dev/null +++ b/tests/test_git.py @@ -0,0 +1,14 @@ +""" +Unit-tests for git +""" + +from commodore import git +from pathlib import Path + + +def test_reconstruct_api_response(tmp_path: Path): + repo_path = tmp_path / 'test-repo' + repo_path.mkdir() + repo = git.create_repository(repo_path) + output = git.stage_all(repo) + assert output != "" diff --git a/tests/test_target.py b/tests/test_target.py index 736cc5567..0a84730bb 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -4,7 +4,7 @@ import click import pytest -import commodore.cluster as cluster +from commodore import cluster cluster_obj = { @@ -22,16 +22,14 @@ def test_render_target(): target = cluster._full_target(cluster_obj, components, catalog) facts = cluster_obj['facts'] + all_classes = [f"defaults.{cn}" for cn in components] + [ + 'global.common', + f"global.{facts['distribution']}", + f"global.{facts['cloud']}", + f"{cluster_obj['tenant']}.{cluster_obj['id']}"] assert target != "" - all_classes = ([f"defaults.{cn}" for cn in components] + - ['global.common', - f"global.{facts['distribution']}", - f"global.{facts['cloud']}", - f"{cluster_obj['tenant']}.{cluster_obj['id']}", - ]) - assert len(target['classes']) == len( - all_classes), "rendered target includes different amount of classes" - # Test order of included classes + assert len(target['classes']) == len(all_classes), \ + "rendered target includes different amount of classes" for i in range(len(all_classes)): assert target['classes'][i] == all_classes[i] assert target['parameters']['target_name'] == 'cluster'