8000 simplify mocking of api calls in top-level test yay · pythonanywhere/helper_scripts@241ead3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 241ead3

Browse files
committed
simplify mocking of api calls in top-level test yay
1 parent 96142a5 commit 241ead3

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

tests/test_pa_start_django_webapp_with_virtualenv.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,13 @@ def test_lowercases_username(self):
4545

4646

4747
@pytest.mark.slowtest
48-
def test_creates_django_project_in_virtualenv_with_hacked_settings_and_static_files(
49-
self, fake_home, virtualenvs_folder, api_responses, api_token
48+
def test_actually_creates_django_project_in_virtualenv_with_hacked_settings_and_static_files(
49+
self, fake_home, virtualenvs_folder, api_token
5050
):
5151

52-
webapps_url = API_ENDPOINT.format(username=getpass.getuser())
53-
webapp_url = API_ENDPOINT.format(username=getpass.getuser()) + 'mydomain.com/'
54-
reload_url = webapp_url + 'reload/'
55-
static_url = API_ENDPOINT.format(username=getpass.getuser()) + 'mydomain.com/static_files/'
56-
57-
api_responses.add(responses.GET, webapp_url, status=404)
58-
api_responses.add(responses.POST, webapps_url, status=201, body=json.dumps({'status': 'OK'}))
59-
api_responses.add(responses.PATCH, webapp_url, status=200)
60-
api_responses.add(responses.POST, reload_url, status=200, body=json.dumps({'status': 'OK'}))
61-
api_responses.add(responses.POST, static_url, status=201)
62-
api_responses.add(responses.POST, static_url, status=201)
63-
64-
6552
with patch('scripts.pa_start_django_webapp_with_virtualenv.DjangoProject.update_wsgi_file'):
66-
main('mydomain.com', '1.9.2', '2.7', nuke=False)
53+
with patch('pythonanywhere.api.call_api'):
54+
main('mydomain.com', '1.9.2', '2.7', nuke=False)
6755

6856
django_version = subprocess.check_output([
6957
virtualenvs_folder / 'mydomain.com/bin/python',
@@ -82,27 +70,13 @@ def test_creates_django_project_in_virtualenv_with_hacked_settings_and_static_fi
8270

8371
@pytest.mark.slowtest
8472
def test_nuke_option_lets_you_run_twice(
85-
self, fake_home, virtualenvs_folder, api_responses, api_token
73+
self, fake_home, virtualenvs_folder, api_token
8674
):
8775

88-
webapps_url = API_ENDPOINT.format(username=getpass.getuser())
89-
webapp_url = API_ENDPOINT.format(username=getpass.getuser()) + 'mydomain.com/'
90-
reload_url = webapp_url + 'reload/'
91-
static_files_url = webapp_url + 'static_files/'
92-
93-
api_responses.add(responses.GET, webapp_url, status=404)
94-
api_responses.add(responses.POST, webapps_url, status=201, body=json.dumps({'status': 'OK'}))
95-
api_responses.add(responses.PATCH, webapp_url, status=200)
96-
api_responses.add(responses.POST, reload_url, status=200, body=json.dumps({'status': 'OK'}))
97-
api_responses.add(responses.POST, static_files_url, status=201)
98-
api_responses.add(responses.POST, static_files_url, status=201)
99-
10076
with patch('scripts.pa_start_django_webapp_with_virtualenv.DjangoProject.update_wsgi_file'):
101-
main('mydomain.com', '1.9.2', '2.7', nuke=False)
102-
103-
api_responses.add(responses.DELETE, webapp_url, status=200)
104-
105-
main('mydomain.com', '1.11.3', '3.6', nuke=True)
77+
with patch('pythonanywhere.api.call_api'):
78+
main('mydomain.com', '1.9.2', '2.7', nuke=False)
79+
main('mydomain.com', '1.11.3', '3.6', nuke=True)
10680

10781
django_version = subprocess.check_output([
10882
virtualenvs_folder / 'mydomain.com/bin/python',

0 commit comments

Comments
 (0)
0