8000 add an e2e test for autoconfigure-django · pythonanywhere/helper_scripts@9cc2e3f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cc2e3f

Browse files
committed
add an e2e test for autoconfigure-django
1 parent fc7bf21 commit 9cc2e3f

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

tests/test_pa_autoconfigure_django.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from unittest.mock import call, patch
22
import getpass
3+
import os
4+
import pytest
5+
import subprocess
36

47
from scripts.pa_autoconfigure_django import main
58

@@ -9,16 +12,11 @@ class TestMain:
912

1013
def test_calls_all_stuff_in_right_order(self):
1114
with patch('scripts.pa_autoconfigure_django.DjangoProject') as mock_DjangoProject:
12-
main(
13-
'https://github.com/pythonanywhere.com/example-django-project.git',
14-
'www.domain.com',
15-
'python.version',
16-
nuke='nuke option'
17-
)
15+
main('repo.url', 'www.domain.com', 'python.version', nuke='nuke option')
1816
assert mock_DjangoProject.call_args == call('www.domain.com')
1917
assert mock_DjangoProject.return_value.method_calls == [
2018
call.sanity_checks(nuke='nuke option'),
21-
call.download_repo('https://github.com/pythonanywhere.com/example-django-project.git', nuke='nuke option'),
19+
call.download_repo('repo.url', nuke='nuke option'),
2220
call.create_virtualenv('python.version', nuke='nuke option'),
2321
call.update_settings_file(),
2422
call.run_collectstatic(),
@@ -48,9 +46,37 @@ def test_lowercases_username(self):
4846
)
4947

5048

49+
@pytest.mark.slowtest
50+
def test_actually_works_against_example_repo(self, fake_home, virtualenvs_folder, api_token):
51+
with patch('scripts.pa_autoconfigure_django.DjangoProject.update_wsgi_file'):
52+
with patch('pythonanywhere.api.call_api'):
53+
main(
54+
'https://github.com/hjwp/example-django-project.git',
55+
'mydomain.com',
56+
'2.7',
57+
nuke=False,
58+
)
59+
60+
django_version = subprocess.check_output([
61+
virtualenvs_folder / 'mydomain.com/bin/python',
62+
'-c'
63+
'import django; print(django.get_version())'
64+
]).decode().strip()
65+
assert django_version == '1.11.1'
66+
67+
with open(fake_home / 'mydomain.com/mysite/settings.py') as f:
68+
lines = f.read().split('\n')
69+
assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
70+
assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
71+
72+
assert 'base.css' in os.listdir(fake_home / 'mydomain.com/static/admin/css')
73+
74+
75+
5176

52-
def test_todos():
77+
def xtest_todos():
5378
assert not 'existing-project sanity checks eg settings.py not found, requirements empty'
79+
assert not 'nuke option shouldnt barf if nothing to nuke'
5480
assert not 'SECRET_KEY'
5581
assert not 'database stuff?'
5682

0 commit comments

Comments
 (0)
0