Пример #1
0
class VirtualEnvTest(mox.MoxTestBase):
    def setUp(self):
        super(VirtualEnvTest, self).setUp()
        self.mock_host_controller = self.mox.CreateMock(RemoteHostController)
        self.mock_feedback = self.mox.CreateMock(ExecutionFeedback)

        self.expected_virtualenv_path = '/some/env/path'

        self.mock_host_controller.feedback = self.mock_feedback

        self.virtualenv = VirtualEnv(self.expected_virtualenv_path,
                                     self.mock_host_controller)

    def test_can_list_installed_virtualenv_packages(self):
        """fab.tests.environment.python.virtualenv_test  Can list installed virtualenv packages"""

        self.mock_feedback.comment('Installed packages:')
        self.mock_host_controller.run(
            self._expected_call_within_virtualenv('pip freeze'))
        self.mox.ReplayAll()

        self.virtualenv.list_installed_packages()

    def test_can_run_command_within_virtualenv(self):
        """fab.tests.environment.python.virtualenv_test  Can run command from within the virtualenv"""

        virtualenv_command = 'command text'
        command_response = 'some response'

        self.mock_host_controller.run(
            self._expected_call_within_virtualenv(
                virtualenv_command)).AndReturn(command_response)
        self.mox.ReplayAll()

        self.assertEqual(
            command_response,
            self.virtualenv.run_within_virtualenv(virtualenv_command))

    def _expected_call_within_virtualenv(self, command):
        return 'source %s/bin/activate && %s' % (self.expected_virtualenv_path,
                                                 command)