1
1
from pathlib import Path
2
- from pythonanywhere .virtualenvs import create_virtualenv , Virtualenv
2
+ from pythonanywhere .virtualenvs import Virtualenv
3
3
4
4
5
5
class TestVirtualenv :
@@ -10,32 +10,40 @@ def test_path(self, virtualenvs_folder):
10
10
11
11
12
12
def test_create_uses_bash_and_sources_virtualenvwrapper (self , mock_subprocess ):
13
- create_virtualenv ('domain.com' , '2.7' , 'django' , nuke = False )
13
+ v = Virtualenv ('domain.com' , '2.7' )
14
+ v .create (nuke = False )
14
15
args , kwargs = mock_subprocess .check_call .call_args
15
16
command_list = args [0 ]
16
17
assert command_list [:2 ] == ['bash' , '-c' ]
17
18
assert command_list [2 ].startswith ('source virtualenvwrapper.sh && mkvirtualenv' )
18
19
19
20
20
21
def test_create_calls_mkvirtualenv_with_python_version_and_domain (self , mock_subprocess ):
21
- create_virtualenv ('domain.com' , '2.7' , 'django' , nuke = False )
22
+ v = Virtualenv ('domain.com' , '2.7' )
23
+ v .create (nuke = False )
22
24
args , kwargs = mock_subprocess .check_call .call_args
23
25
command_list = args [0 ]
24
26
bash_command = command_list [2 ]
25
27
assert 'mkvirtualenv --python=/usr/bin/python2.7 domain.com' in bash_command
26
28
27
29
28
- def test_create_pip_installs_packages (self , mock_subprocess ):
29
- create_virtualenv ('domain.com' , '2.7' , 'package1 package2==1.1.2' , nuke = False )
30
+ def test_nuke_option_deletes_virtualenv (self , mock_subprocess , virtualenvs_folder ):
31
+ v = Virtualenv ('domain.com' , '2.7' )
32
+ v .create (nuke = True )
30
33
args , kwargs = mock_subprocess .check_call .call_args
31
34
command_list = args [0 ]
32
- assert command_list [2 ].endswith ('pip install package1 package2==1.1.2' )
35
+ assert command_list [:2 ] == ['bash' , '-c' ]
36
+ assert command_list [2 ].startswith ('source virtualenvwrapper.sh && rmvirtualenv domain.com' )
33
37
34
38
35
- def test_create_nuke_option_deletes_virtualenv_first (self , mock_subprocess , virtualenvs_folder ):
36
- create_virtualenv ('domain.com' , '2.7' , 'django' , nuke = True )
37
- args , kwargs = mock_subprocess .check_call .call_args
39
+ def test_install_pip_installs_packages (self , mock_subprocess ):
40
+ packages = 'package1 package2==1.1.2'
41
+ v = Virtualenv ('domain.com' , '2.7' )
42
+ v .create (nuke = False )
43
+ v .pip_install (packages )
44
+ args , kwargs = mock_subprocess .check_call .call_args_list [- 1 ]
38
45
command_list = args [0 ]
39
- assert command_list [:2 ] == ['bash' , '-c' ]
40
- assert command_list [2 ].startswith ('source virtualenvwrapper.sh && rmvirtualenv domain.com && mkvirtualenv' )
46
+ pip_path = str (v .path / 'bin/pip' )
47
+ assert command_list == [pip_path , 'install' , packages ]
48
+
41
49
0 commit comments