From 0af901aadbc7d9d065ef515de6a203dc8419536f Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Sat, 22 Aug 2026 10:33:36 -0500 Subject: [PATCH] Stop prompting to overwrite wsgi.py on redeploy wsgi.py always exists already, so use modify_file() rather than add_file(), which would prompt for overwrite confirmation on every redeploy and block --automate-all. --- dsd_pythonanywhere/platform_deployer.py | 2 +- tests/unit_tests/test_platform_deployer.py | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dsd_pythonanywhere/platform_deployer.py b/dsd_pythonanywhere/platform_deployer.py index f694e8b..78529c4 100644 --- a/dsd_pythonanywhere/platform_deployer.py +++ b/dsd_pythonanywhere/platform_deployer.py @@ -193,7 +193,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 bf9c175..0eee02b 100644 --- a/tests/unit_tests/test_platform_deployer.py +++ b/tests/unit_tests/test_platform_deployer.py @@ -53,6 +53,31 @@ def test_modify_settings(tmp_path: Path, monkeypatch): assert 'if os.getenv("ON_PYTHONANYWHERE"):' 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"