8000 add static files mappings is now a couple of methods · pythonanywhere/helper_scripts@2db8fca · GitHub
[go: up one dir, main page]

Skip to content

Commit 2db8fca

Browse files
committed
add static files mappings is now a couple of methods
1 parent 46903a8 commit 2db8fca

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

pythonanywhere/api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ def create(self, python_version, virtualenv_path, project_path, nuke):
8888

8989

9090

91-
def add_static_file_mappings(domain, project_path):
92-
print(snakesay('Adding static files mappings for /static/ and /media/'))
93-
94-
url = API_ENDPOINT.format(username=getpass.getuser()) + domain + '/static_files/'
95-
call_api(url, 'post', json=dict(
96-
url='/static/', path=str(Path(project_path) / 'static'),
97-
))
98-
call_api(url, 'post', json=dict(
99-
url='/media/', path=str(Path(project_path) / 'media'),
100-
))
91+
def add_default_static_files_mappings(self, project_path):
92+
print(snakesay('Adding static files mappings for /static/ and /media/'))
93+
94+
url = API_ENDPOINT.format(username=getpass.getuser()) + self.domain + '/static_files/'
95+
call_api(url, 'post', json=dict(
96+
url='/static/', path=str(Path(project_path) / 'static'),
97+
))
98+
call_api(url, 'post', json=dict(
99+
url='/media/', path=str(Path(project_path) / 'media'),
100+
))
101101

102102

103103

pythonanywhere/django_project.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ def update_wsgi_file(self):
9292
def create_webapp(self, nuke):
9393
self.webapp.create(self.python_version, self.virtualenv_path, self.project_path, nuke=nuke)
9494

95+
96+
def add_static_file_mappings(self):
97+
self.webapp.add_default_static_files_mappings(self.project_path)
98+
99+

scripts/pa_autoconfigure_django.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def main(repo_url, domain, python_version, nuke):
4343
project = DjangoProject(domain)
4444
project.sanity_checks(nuke=nuke)
4545
project.create_virtualenv(python_version, 'django', nuke=nuke)
46-
47-
4846
project.update_settings_file()
4947
project.run_collectstatic()
5048
project.create_webapp(nuke=nuke)

scripts/pa_start_django_webapp_with_virtualenv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from pythonanywhere.snakesay import snakesay
1919
from pythonanywhere.api import (
20-
add_static_file_mappings,
2120
reload_webapp,
2221
)
2322

@@ -36,7 +35,7 @@ def main(domain, django_version, python_version, nuke):
3635
project.update_settings_file()
3736
project.run_collectstatic()
3837
project.create_webapp(nuke=nuke)
39-
add_static_file_mappings(domain, project.project_path)
38+
project.add_static_file_mappings()
4039

4140
project.update_wsgi_file()
4241

tests/test_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
PYTHON_VERSIONS,
1010
AuthenticationError,
1111
Webapp,
12-
add_static_file_mappings,
1312
call_api,
1413
reload_webapp,
1514
)
@@ -186,14 +185,14 @@ def test_ignores_404_from_delete_call_when_nuking(self, api_responses, api_token
186185

187186

188187

189-
class TestAddStaticFilesMapping:
188+
class TestAddDefaultStaticFilesMapping:
190189

191190
def test_does_two_posts_to_static_files_endpoint(self, api_token, api_responses):
192191
expected_url = API_ENDPOINT.format(username=getpass.getuser()) + 'mydomain.com/static_files/'
193192
api_responses.add(responses 67F4 .POST, expected_url, status=201)
194193
api_responses.add(responses.POST, expected_url, status=201)
195194

196-
add_static_file_mappings('mydomain.com', '/project/path')
195+
Webapp('mydomain.com').add_default_static_files_mappings('/project/path')
197196

198197
post1 = api_responses.calls[0]
199198
assert post1.request.url == expected_url

tests/test_django_project.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def test_updates_wsgi_file_from_template(self):
225225
assert contents == template.format(project_path=project.project_path)
226226

227227

228+
228229
class TestCreateWebapp:
229230

230231
def test_calls_webapp_create(self):
@@ -238,3 +239,14 @@ def test_calls_webapp_create(self):
238239
)
239240

240241

242+
243+
class TestAddStaticFilesMappings:
244+
245+
def test_calls_webapp_add_default_static_files_mappings(self):
246+
project = DjangoProject('mydomain.com')
247+
project.webapp.add_default_static_files_mappings = Mock()
248+
project.add_static_file_mappings()
249+
assert project.webapp.add_default_static_files_mappings.call_args == call(
250+
project.project_path,
251+
)
252+

tests/test_pa_start_django_webapp_with_virtualenv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def mock_main_functions():
1515
patchers = []
1616
functions = [
1717
'DjangoProject',
18-
'add_static_file_mappings',
1918
'reload_webapp',
2019
]
2120
for function in functions:
@@ -41,7 +40,6 @@ def test_calls_all_stuff_in_right_order(self, mock_main_functions):
4140
mock_django_project = mock_main_functions.DjangoProject.return_value
4241
assert mock_main_functions.method_calls == [
4342
call.DjangoProject('www.domain.com'),
44-
call.add_static_file_mappings('www.domain.com', mock_django_project.project_path),
4543
call.reload_webapp('www.domain.com')
4644
]
4745
assert mock_django_project.method_calls == [
@@ -51,6 +49,7 @@ def test_calls_all_stuff_in_right_order(self, mock_main_functions):
5149
call.update_settings_file(),
5250
call.run_collectstatic(),
5351
call.create_webapp(nuke='nuke option'),
52+
call.add_static_file_mappings(),
5453
call.update_wsgi_file(),
5554
]
5655

0 commit comments

Comments
 (0)
0