diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 9c3d946c1..5655b61f9 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -293,6 +293,7 @@ def set_flags_in_settings_files(): def remove_envs_and_associated_files(): shutil.rmtree(".envs") os.remove("merge_production_dotenvs_in_dotenv.py") + shutil.rmtree("tests") def remove_celery_compose_dirs(): diff --git a/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py b/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py index e47705fbc..c3cee35a3 100644 --- a/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py +++ b/{{cookiecutter.project_slug}}/merge_production_dotenvs_in_dotenv.py @@ -2,8 +2,6 @@ import os from collections.abc import Sequence from pathlib import Path -import pytest - BASE_DIR = Path(__file__).parent.resolve() PRODUCTION_DOTENVS_DIR = BASE_DIR / ".envs" / ".production" PRODUCTION_DOTENV_FILES = [ @@ -30,55 +28,5 @@ def main(): merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES) -@pytest.mark.parametrize( - ("input_contents", "append_linesep", "expected_output"), - [ - # No line separator - ([], False, ""), - ([""], False, ""), - (["\n"], False, "\n"), - (["TEST=1"], False, "TEST=1"), - (["THIS=2", "THAT='example'"], False, "THIS=2THAT='example'"), - (["ONE=1\n", "TWO=2"], False, "ONE=1\nTWO=2"), - (["A=0", "B=1", "C=2"], False, "A=0B=1C=2"), - # With line separator - ( - [], - True, - "", - ), - ( - [""], - True, - "\n", - ), - ( - ["JANE=doe"], - True, - "JANE=doe\n", - ), - (["SEP=true", "AR=ator"], True, "SEP=true\nAR=ator\n"), - (["X=x\n", "Y=y", "Z=z\n"], True, "X=x\n\nY=y\nZ=z\n\n"), - ], -) -def test_merge( - tmp_path: Path, - input_contents: list[str], - append_linesep: bool, - expected_output: str, -): - output_file = tmp_path / ".env" - - files_to_merge = [] - for num, input_content in enumerate(input_contents, start=1): - merge_file = tmp_path / f".service{num}" - merge_file.write_text(input_content) - files_to_merge.append(merge_file) - - merge(output_file, files_to_merge, append_linesep) - - assert output_file.read_text() == expected_output - - if __name__ == "__main__": main() diff --git a/{{cookiecutter.project_slug}}/tests/test_merge_production_dotenvs_in_dotenv.py b/{{cookiecutter.project_slug}}/tests/test_merge_production_dotenvs_in_dotenv.py new file mode 100644 index 000000000..faf7357f6 --- /dev/null +++ b/{{cookiecutter.project_slug}}/tests/test_merge_production_dotenvs_in_dotenv.py @@ -0,0 +1,43 @@ +from pathlib import Path + +import pytest + +from merge_production_dotenvs_in_dotenv import merge + + +@pytest.mark.parametrize( + ("input_contents", "append_linesep", "expected_output"), + [ + # No line separator + ([], False, ""), + ([""], False, ""), + (["\n"], False, "\n"), + (["TEST=1"], False, "TEST=1"), + (["THIS=2", "THAT='example'"], False, "THIS=2THAT='example'"), + (["ONE=1\n", "TWO=2"], False, "ONE=1\nTWO=2"), + (["A=0", "B=1", "C=2"], False, "A=0B=1C=2"), + # With line separator + ([], True, ""), + ([""], True, "\n"), + (["JANE=doe"], True, "JANE=doe\n"), + (["SEP=true", "AR=ator"], True, "SEP=true\nAR=ator\n"), + (["X=x\n", "Y=y", "Z=z\n"], True, "X=x\n\nY=y\nZ=z\n\n"), + ], +) +def test_merge( + tmp_path: Path, + input_contents: list[str], + append_linesep: bool, + expected_output: str, +): + output_file = tmp_path / ".env" + + files_to_merge = [] + for num, input_content in enumerate(input_contents, start=1): + merge_file = tmp_path / f".service{num}" + merge_file.write_text(input_content) + files_to_merge.append(merge_file) + + merge(output_file, files_to_merge, append_linesep) + + assert output_file.read_text() == expected_output