10000 fix wsgi file template · pythonanywhere/helper_scripts@43a2130 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43a2130

Browse files
committed
fix wsgi file template
1 parent d4db4df commit 43a2130

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

pythonanywhere/django_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def update_wsgi_file(self):
116116
print(snakesay(f'Updating wsgi file at {self.wsgi_file_path}'))
117117
template = open(Path(__file__).parent / 'wsgi_file_template.py').read()
118118
with open(self.wsgi_file_path, 'w') as f:
119-
f.write(template.format(project_path=self.project_path))
119+
f.write(template.format(project=self))
120120

121121

122122
def create_webapp(self, nuke):

pythonanywhere/wsgi_file_template.py

Lines changed: 3 additions & 3 deletions
10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import sys
55

66
# Add your project directory to the sys.path
7-
project_path = {project_path!r}
8-
sys.path.insert(0, project_path)
7+
settings_path = '{project.settings_path.parent.parent}'
8+
sys.path.insert(0, settings_path)
99

10
# Set environment variable to tell django where your settings.py is
11-
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
11+
os.environ['DJANGO_SETTINGS_MODULE'] = '{project.settings_path.parent.name}.settings'
1212

1313
# Set the 'application' variable to the Django wsgi app
1414
from django.core.wsgi import get_wsgi_application

tests/test_django_project.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def more_nested_submodule():
235235
class TestFindDjangoFiles:
236236

237237
def test_non_nested(self, fake_home, non_nested_submodule):
238+
238239
project = DjangoProject('mydomain.com')
239240
shutil.copytree(non_nested_submodule, project.project_path)
240241
expected_settings_path = project.project_path / 'myproject/settings.py'
@@ -361,14 +362,49 @@ class TestUpdateWsgiFile:
361362

362363
def test_updates_wsgi_file_from_template(self):
363364
project = DjangoProject('mydomain.com')
364-
project.wsgi_file_path = tempfile.NamedTemporaryFile().name
365+
project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)
366+
project.settings_path = Path('/path/to/settingsfolder/settings.py')
365367
template = open(Path(pythonanywhere.django_project.__file__).parent / 'wsgi_file_template.py').read()
366368

367369
project.update_wsgi_file()
368370

369371
with open(project.wsgi_file_path) as f:
370372
contents = f.read()
371-
assert contents == template.format(project_path=project.project_path)
373+
print(contents)
374+
assert contents == template.format(project=project)
375+
376+
377+
@pytest.mark.slowtest
378+
def test_actually_produces_wsgi_file_that_can_import_project_non_nested(
379+
self, fake_home, non_nested_submodule, virtualenvs_folder
380+
):
381+
project = DjangoProject('mydomain.com')
382+
shutil.copytree(non_nested_submodule, project.project_path)
383+
project.create_virtualenv('3.6')
384+< 10000 /span>
project.find_django_files()
385+
project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)
386+
387+
project.update_wsgi_file()
388+
389+
print(open(project.wsgi_file_path).read())
390+
subprocess.check_output([project.virtualenv_path / 'bin/python', project.wsgi_file_path])
391+
392+
393+
@pytest.mark.slowtest
394+
def test_actually_produces_wsgi_file_that_can_import_nested_project(
395+
self, fake_home, more_nested_submodule, virtualenvs_folder
396+
):
397+
project = DjangoProject('mydomain.com')
398+
shutil.copytree(more_nested_submodule, project.project_path)
399+
project.create_virtualenv('3.6')
400+
project.find_django_files()
401+
project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)
402+
403+
project.update_wsgi_file()
404+
405+
print(open(project.wsgi_file_path).read())
406+
subprocess.check_output([project.virtualenv_path / 'bin/python', project.wsgi_file_path])
407+
372408

373409

374410

tests/test_pa_autoconfigure_django.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def test_actually_works_against_example_repo(self, fake_home, virtualenvs_folder
7979

8080

8181
def xtest_todos():
82-
assert not 'correct working dir / sys.path for nested projects'
8382
assert not 'existing-project sanity checks eg requirements empty'
8483
assert not 'nuke option shouldnt barf if nothing to nuke'
8584
assert not 'SECRET_KEY'

0 commit comments

Comments
 (0)
0