diff --git a/dsd_pythonanywhere/platform_deployer.py b/dsd_pythonanywhere/platform_deployer.py index 8747d52..4aa8b5d 100644 --- a/dsd_pythonanywhere/platform_deployer.py +++ b/dsd_pythonanywhere/platform_deployer.py @@ -210,7 +210,7 @@ def _modify_wsgi(self): } contents = plugin_utils.get_template_string(template_path, context) path = dsd_config.project_root / dsd_config.local_project_name / "wsgi.py" - plugin_utils.add_file(path, contents) + plugin_utils.modify_file(path, contents) def _modify_gitignore(self) -> None: """Ensure .gitignore ignores deployment files.""" diff --git a/tests/unit_tests/test_platform_deployer.py b/tests/unit_tests/test_platform_deployer.py index e929a69..a5a36b2 100644 --- a/tests/unit_tests/test_platform_deployer.py +++ b/tests/unit_tests/test_platform_deployer.py @@ -57,6 +57,31 @@ def test_modify_settings(tmp_path: Path, monkeypatch): assert 'ALLOWED_HOSTS = ["testuser.pythonanywhere.com"]' in modified_content +def test_modify_wsgi_redeploy_does_not_prompt(tmp_path: Path, monkeypatch, mocker): + """_modify_wsgi overwrites an existing wsgi.py without a confirmation prompt.""" + project_name = "mysite" + project_dir = tmp_path / project_name + project_dir.mkdir() + wsgi_path = project_dir / "wsgi.py" + wsgi_path.write_text("# original wsgi.py") + + deployer = PlatformDeployer() + monkeypatch.setattr(dsd_config, "project_root", tmp_path) + monkeypatch.setattr(dsd_config, "local_project_name", project_name) + monkeypatch.setattr(dsd_config, "stdout", sys.stdout) + mocker.patch.object(deployer, "_get_repo_name", return_value="myrepo") + + # wsgi.py already exists here, as it would on a redeploy. If this used + # add_file(), it would block on an interactive confirmation prompt. + deployer._modify_wsgi() + modified_content = wsgi_path.read_text() + assert "myrepo" in modified_content + assert project_name in modified_content + + deployer._modify_wsgi() + assert wsgi_path.read_text() == modified_content + + def test_add_requirements(tmp_path: Path, monkeypatch): """_add_requirements adds required packages.""" requirements_path = tmp_path / "requirements.txt"