1
1
from unittest .mock import call , patch
2
2
import getpass
3
+ import os
4
+ import pytest
5
+ import subprocess
3
6
4
7
from scripts .pa_autoconfigure_django import main
5
8
@@ -9,16 +12,11 @@ class TestMain:
9
12
10
13
def test_calls_all_stuff_in_right_order (self ):
11
14
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' )
18
16
assert mock_DjangoProject .call_args == call ('www.domain.com' )
19
17
assert mock_DjangoProject .return_value .method_calls == [
20
18
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' ),
22
20
call .create_virtualenv ('python.version' , nuke = 'nuke option' ),
23
21
call .update_settings_file (),
24
22
call .run_collectstatic (),
@@ -48,9 +46,37 @@ def test_lowercases_username(self):
48
46
)
49
47
50
48
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
+
51
76
52
- def test_todos ():
77
+ def xtest_todos ():
53
78
assert not 'existing-project sanity checks eg settings.py not found, requirements empty'
79
+ assert not 'nuke option shouldnt barf if nothing to nuke'
54
80
assert not 'SECRET_KEY'
55
81
assert not 'database stuff?'
56
82
0 commit comments