8000 create_virtualenv now takes django version · pythonanywhere/helper_scripts@12de305 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12de305

Browse files
committed
create_virtualenv now takes django version
1 parent 866d391 commit 12de305

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

pythonanywhere/django_project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ def __init__(self, domain):
1515
self.wsgi_file_path = '/var/www/' + domain.replace('.', '_') + '_wsgi.py'
1616

1717

18-
def create_virtualenv(self, nuke):
18+
def create_virtualenv(self, django_version, nuke):
19+
packages = 'django' if django_version == 'latest' else f'django=={django_version}'
1920
self.virtualenv_path = create_virtualenv(
20-
self.domain, self.python_version, 'django', nuke=nuke
21+
self.domain, self.python_version, packages, nuke=nuke
2122
)
2223

2324

scripts/pa_start_django_webapp_with_virtualenv.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
reload_webapp,
2323
)
2424

25-
from pythonanywhere.virtualenvs import create_virtualenv
2625
from pythonanywhere.django_project import DjangoProject
2726
from pythonanywhere.sanity_checks import sanity_checks
2827

@@ -32,16 +31,15 @@ def main(domain, django_version, python_version, nuke):
3231
username = getpass.getuser().lower()
3332
domain = f'{username}.pythonanywhere.com'
3433
sanity_checks(domain, nuke=nuke)
35-
packages = 'django' if django_version == 'latest' else f'django=={django_version}'
36-
virtualenv = create_virtualenv(domain, python_version, packages, nuke=nuke)
3734

3835
project = DjangoProject(domain)
39-
project.virtualenv_path = virtualenv
36+
project.python_version = python_version
37+
project.create_virtualenv(django_version, nuke=nuke)
4038
project.run_startproject(nuke=nuke)
4139
project.update_settings_file()
4240
project.run_collectstatic()
4341

44-
create_webapp(domain, python_version, virtualenv, project.project_path, nuke=nuke)
42+
create_webapp(domain, python_version, project.virtualenv_path, project.project_path, nuke=nuke)
4543
add_static_file_mappings(domain, project.project_path)
4644

4745
project.update_wsgi_file()

tests/test_django_project.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ def test_wsgi_file_path(self, fake_home):
2323

2424
class TestCreateVirtualenv:
2525

26-
def test_calls_create_virtualenv_with_latest_django_by_default(self):
26+
def test_calls_create_virtualenv(self):
2727
project = DjangoProject('mydomain.com')
2828
project.python_version = 'python.version'
2929
with patch('pythonanywhere.django_project.create_virtualenv') as mock_create_virtualenv:
30-
project.create_virtualenv(nuke='nuke option')
30+
project.create_virtualenv(django_version='django.version', nuke='nuke option')
31+
assert mock_create_virtualenv.call_args == call(
32+
project.domain, 'python.version', 'django==django.version', nuke='nuke option'
33+
)
34+
35+
36+
def test_special_cases_latest_django_version(self):
37+
project = DjangoProject('mydomain.com')
38+
project.python_version = 'python.version'
39+
with patch('pythonanywhere.django_project.create_virtualenv') as mock_create_virtualenv:
40+
project.create_virtualenv(django_version='latest', nuke='nuke option')
3141
assert mock_create_virtualenv.call_args == call(
3242
project.domain, 'python.version', 'django', nuke='nuke option'
3343
)
@@ -37,7 +47,7 @@ def test_sets_virtualenv_attribute(self):
3747
project = DjangoProject('mydomain.com')
3848
project.python_version = 'python.version'
3949
with patch('pythonanywhere.django_project.create_virtualenv') as mock_create_virtualenv:
40-
project.create_virtualenv(nuke='nuke option')
50+
project.create_virtualenv(django_version='django.version', nuke='nuke option')
4151
assert project.virtualenv_path == mock_create_virtualenv.return_value
4252

4353

tests/test_pa_start_django_webapp_with_virtualenv.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def mock_main_functions():
1616
functions = [
1717
'DjangoProject',
1818
'sanity_checks',
19-
'create_virtualenv',
2019
'create_webapp',
2120
'add_static_file_mappings',
2221
'reload_webapp',
@@ -44,21 +43,19 @@ def test_calls_all_stuff_in_right_order(self, mock_main_functions):
4443
mock_django_project = mock_main_functions.DjangoProject.return_value
4544
assert mock_main_functions.method_calls == [
4645
call.sanity_checks('www.domain.com', nuke='nuke option'),
47-
call.create_virtualenv(
48-
'www.domain.com', 'python.version', 'django==django.version', nuke='nuke option'
49-
),
5046
call.DjangoProject('www.domain.com'),
5147
call.create_webapp(
5248
'www.domain.com',
5349
'python.version',
54-
mock_main_functions.create_virtualenv.return_value,
50+
mock_django_project.virtualenv_path,
5551
mock_django_project.project_path,
5652
nuke='nuke option'
5753
),
5854
call.add_static_file_mappings('www.domain.com', mock_django_project.project_path),
5955
call.reload_webapp('www.domain.com')
6056
]
6157
assert mock_django_project.method_calls == [
58+
call.create_virtualenv('django.version', nuke='nuke option'),
6259
call.run_startproject(nuke='nuke option'),
6360
call.update_settings_file(),
6461
call.run_collectstatic(),
@@ -69,8 +66,8 @@ def test_calls_all_stuff_in_right_order(self, mock_main_functions):
6966
def test_domain_defaults_to_using_current_username(self, mock_main_functions):
7067
username = getpass.getuser()
7168
main('your-username.pythonanywhere.com', 'django.version', 'python.version', nuke=False)
72-
assert mock_main_functions.create_virtualenv.call_args == call(
73-
username + '.pythonanywhere.com', 'python.version', 'django==django.version', nuke=False
69+
assert mock_main_functions.DjangoProject.call_args == call(
70+
username + '.pythonanywhere.com'
7471
)
7572
assert mock_main_functions.reload_webapp.call_args == call(
7673
username + '.pythonanywhere.com',
@@ -81,21 +78,14 @@ def test_lowercases_username(self, mock_main_functions):
8178
with patch('scripts.pa_start_django_webapp_with_virtualenv.getpass') as mock_getpass:
8279
mock_getpass.getuser.return_value = 'UserName1'
8380
main('your-username.pythonanywhere.com', 'django.version', 'python.version', 'nukey')
84-
assert mock_main_functions.create_virtualenv.call_args == call(
85-
'username1.pythonanywhere.com', 'python.version', 'django==django.version', nuke='nukey'
81+
assert mock_main_functions.DjangoProject.call_args == call(
82+
'username1.pythonanywhere.com'
8683
)
8784
assert mock_main_functions.reload_webapp.call_args == call(
8885
'username1.pythonanywhere.com',
8986
)
9087

9188

92-
def test_django_latest_is_just_django_for_virtualenv(self, mock_main_functions):
93-
main('www.domain.com', 'latest', 'python.version', nuke='nuke option')
94-
assert mock_main_functions.create_virtualenv.call_args == call(
95-
'www.domain.com', 'python.version', 'django', nuke='nuke option'
96-
)
97-
98-
9989
@pytest.mark.slowtest
10090
def test_creates_django_project_in_virtualenv_with_hacked_settings_and_static_files(
10191
self, fake_home, virtualenvs_folder, api_responses, api_token

0 commit comments

Comments
 (0)
0