Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dsd_pythonanywhere/platform_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
25 changes: 25 additions & 0 deletions tests/unit_tests/test_platform_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down