def doesnt_create_env_if_it_already_exists(self): execute = MagicMock() @contextmanager def prefix(command): execute('called before prefix') execute('prefix: "%s"' % command) yield execute('called after prefix') with patch('provy.core.roles.Role.execute', execute), patch( 'fabric.api.prefix', prefix), self.env_exists('fancylib') as env_exists: venv = VirtualenvRole(prov=None, context={'user': '******'}) env_exists.return_value = True with venv('fancylib'): execute('some command') execute('some command 2') env_exists.assert_called_with('fancylib') activation_prefix_call = call( 'prefix: "source %s/fancylib/bin/activate"' % venv.get_base_directory()) expected_executes = [ call('called before prefix'), activation_prefix_call, call('some command'), call('some command 2'), call('called after prefix'), ] self.assertEqual(execute.mock_calls, expected_executes)
def wraps_the_env_usage_with_creation_activation_and_deactivation(self): execute = MagicMock() @contextmanager def prefix(command): execute('called before prefix') execute('prefix: "%s"' % command) yield execute('called after prefix') with patch('provy.core.roles.Role.execute', execute), patch('fabric.api.prefix', prefix), self.env_exists('fancylib') as env_exists: venv = VirtualenvRole(prov=None, context={'user': '******',}) env_exists.return_value = False with venv('fancylib'): execute('some command') execute('some command 2') env_exists.assert_called_with('fancylib') env_creation_call = call('virtualenv %s/fancylib' % venv.base_directory, user='******') activation_prefix_call = call('prefix: "source %s/fancylib/bin/activate"' % venv.base_directory) expected_executes = [ env_creation_call, call('called before prefix'), activation_prefix_call, call('some command'), call('some command 2'), call('called after prefix'), ] execute.assert_has_calls(expected_executes)
def refers_to_custom_subdir(self): role = VirtualenvRole(prov=None, context={'user': '******'}) role.base_directory = '/somewhere/else' self.assertEqual(role.get_base_directory(), '/somewhere/else')
def refers_to_specific_subdir_at_root_home(self): role = VirtualenvRole(prov=None, context={'user': '******'}) self.assertEqual(role.get_base_directory(), '/root/.virtualenvs')
def refers_to_specific_subdir_at_user_home(self): role = VirtualenvRole(prov=None, context={'user': '******'}) self.assertEqual(role.get_base_directory(), '/home/johndoe/.virtualenvs')
def setUp(self): super(VirtualenvRoleTest, self).setUp() self.role = VirtualenvRole(prov=None, context={'user': '******'})
def setUp(self): self.role = VirtualenvRole(prov=None, context={'user': '******',})