Skip to content

Commit dba12f4

Browse files
committed
test fixes, and add travis ci badge to README
1 parent 967123c commit dba12f4

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sudo: false
33
language: python
44

55
python:
6+
- 3.5
67
- 3.6
78
- 3.7
89

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://travis-ci.org/pythonanywhere/helper_scripts.svg?branch=master)](https://travis-ci.org/pythonanywhere/helper_scripts)
2+
13
# PythonAnywhere helper scripts
24

35
These scripts are designed to be run from PythonAnywhere consoles

pythonanywhere/virtualenvs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ def __eq__(self, other):
1717

1818

1919
def create(self, nuke):
20-
print(snakesay('Creating virtualenv with Python{python_version}'.format(python_version=self.python_version)))
21-
command = 'mkvirtualenv --python=/usr/bin/python{python_version} {domain}'.format(
22-
python_version=self.python_version,
23-
domain=self.domain,
20+
print(snakesay("Creating virtualenv with Python{python_version}".format(python_version=self.python_version)))
21+
command = "mkvirtualenv --python=python{python_version} {domain}".format(
22+
python_version=self.python_version, domain=self.domain
2423
)
2524
if nuke:
2625
command = 'rmvirtualenv {domain} && {command}'.format(

tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ def fake_home(local_pip_cache):
4848

4949
@pytest.fixture
5050
def virtualenvs_folder():
51-
actual_virtualenvs = Path('/home/{user}/.virtualenvs'.format(user=getuser()))
52-
old_virtualenvs = set(Path(actual_virtualenvs).iterdir())
51+
actual_virtualenvs = Path("/home/{user}/.virtualenvs".format(user=getuser()))
52+
if actual_virtualenvs.is_dir():
53+
old_virtualenvs = set(Path(actual_virtualenvs).iterdir())
54+
else:
55+
old_virtualenvs = {}
5356

5457
tempdir = _get_temp_dir()
5558
old_workon = os.environ.get('WORKON_HOME')

tests/test_api.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ def test_raises_if_post_does_not_20x(self, api_responses, api_token):
161161

162162
def test_raises_if_post_returns_a_200_with_status_error(self, api_responses, api_token):
163163
expected_post_url = get_api_endpoint().format(username=getpass.getuser(), flavor="webapps")
164-
api_responses.add(responses.POST, expected_post_url, status=200, body=json.dumps({
165-
"status": "ERROR", "error_type": "bad", "error_message": "bad things happened"
166-
}))
164+
api_responses.add(
165+
responses.POST,
166+
expected_post_url,
167+
status=200,
168+
body=json.dumps({"status": "ERROR", "error_type": "bad", "error_message": "bad things happened"}),
169+
)
167170

168171
with pytest.raises(Exception) as e:
169172
Webapp('mydomain.com').create('2.7', '/virtualenv/path', '/project/path', nuke=False)
@@ -371,18 +374,26 @@ def test_raises_if_delete_does_not_20x(self, api_responses, api_token):
371374
class TestGetWebappLogs:
372375

373376
def test_get_list_of_logs(self, api_responses, api_token):
374-
expected_url = get_api_endpoint().format(
375-
username=getpass.getuser(), flavor="files") + "tree/?path=/var/log/"
376-
api_responses.add(responses.GET, expected_url, status=200,
377-
body="['/var/log/blah','/var/log/mydomain.com.access.log',\
378-
'/var/log/mydomain.com.access.log.1',\
379-
'/var/log/mydomain.com.access.log.2.gz',\
380-
'/var/log/mydomain.com.error.log',\
381-
'/var/log/mydomain.com.error.log.1',\
382-
'/var/log/mydomain.com.error.log.2.gz',\
383-
'/var/log/mydomain.com.server.log',\
384-
'/var/log/mydomain.com.server.log.1',\
385-
'/var/log/mydomain.com.server.log.2.gz']")
377+
expected_url = get_api_endpoint().format(username=getpass.getuser(), flavor="files") + "tree/?path=/var/log/"
378+
api_responses.add(
379+
responses.GET,
380+
expected_url,
381+
status=200,
382+
body=json.dumps(
383+
[
384+
"/var/log/blah",
385+
"/var/log/mydomain.com.access.log",
386+
"/var/log/mydomain.com.access.log.1",
387+
"/var/log/mydomain.com.access.log.2.gz",
388+
"/var/log/mydomain.com.error.log",
389+
"/var/log/mydomain.com.error.log.1",
390+
"/var/log/mydomain.com.error.log.2.gz",
391+
"/var/log/mydomain.com.server.log",
392+
"/var/log/mydomain.com.server.log.1",
393+
"/var/log/mydomain.com.server.log.2.gz",
394+
]
395+
),
396+
)
386397

387398
logs = Webapp("mydomain.com").get_log_info()
388399

tests/test_django_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def test_if_requirements_txt_exists(self, fake_home):
7070

7171

7272
@pytest.fixture
73-
def project_with_mock_virtualenv():
74-
project = DjangoProject('mydomain.com', 'python.version')
73+
def project_with_mock_virtualenv(virtualenvs_folder):
74+
project = DjangoProject("mydomain.com", "python.version")
7575
project.virtualenv.create = Mock()
7676
project.virtualenv.pip_install = Mock()
7777
yield project

tests/test_virtualenvs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def test_create_calls_mkvirtualenv_with_python_version_and_domain(self, mock_sub
2727
args, kwargs = mock_subprocess.check_call.call_args
2828
command_list = args[0]
2929
bash_command = command_list[2]
30-
assert 'mkvirtualenv --python=/usr/bin/python2.7 domain.com' in bash_command
31-
30+
assert "mkvirtualenv --python=python2.7 domain.com" in bash_command
3231

3332
def test_nuke_option_deletes_virtualenv(self, mock_subprocess, virtualenvs_folder):
3433
v = Virtualenv('domain.com', '2.7')

0 commit comments

Comments
 (0)