From 8c10404443aa50366361f9ee0ba7ca19d7b8f8ff Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 24 Sep 2014 17:03:53 -0400 Subject: [PATCH] create tests for the new sudo detection method --- remoto/tests/test_connection.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/remoto/tests/test_connection.py b/remoto/tests/test_connection.py index 324da7c..67fd05d 100644 --- a/remoto/tests/test_connection.py +++ b/remoto/tests/test_connection.py @@ -1,3 +1,4 @@ +from mock import Mock from py.test import raises from remoto import connection @@ -85,3 +86,31 @@ class TestMakeConnectionString(object): conn_string = conn._make_connection_string('localhost', _needs_ssh=lambda x: True) assert conn_string == 'ssh=localhost//python=python' + def test_makes_sudo_python_with_forced_sudo(self): + conn = connection.Connection('localhost', sudo=True, eager=False) + conn_string = conn._make_connection_string('localhost', _needs_ssh=lambda x: False, use_sudo=True) + assert conn_string == 'popen//python=sudo python' + + def test_does_not_make_sudo_python_with_forced_sudo(self): + conn = connection.Connection('localhost', sudo=True, eager=False) + conn_string = conn._make_connection_string('localhost', _needs_ssh=lambda x: False, use_sudo=False) + assert conn_string == 'popen//python=python' + + +class TestDetectSudo(object): + + def setup(self): + self.execnet = Mock() + self.execnet.return_value = self.execnet + self.execnet.makegateway.return_value = self.execnet + self.execnet.remote_exec.return_value = self.execnet + + def test_does_not_need_sudo(self): + self.execnet.receive.return_value = 'root' + conn = connection.Connection('localhost', sudo=True, eager=False) + assert conn._detect_sudo(_execnet=self.execnet) is False + + def test_does_need_sudo(self): + self.execnet.receive.return_value = 'alfredo' + conn = connection.Connection('localhost', sudo=True, eager=False) + assert conn._detect_sudo(_execnet=self.execnet) is True -- 2.47.3