示例#1
0
    def test_driver_command(self):
        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.return_code = "RETURN_CODE"
        out.stderr = "STDERR"

        runout = RunOut()
        runout.stdout = "STDOUT"
        runout.return_code = "RETURN_CODE"
        runout.stderr = "STDERR"

        shotgun.driver.fabric.api.run = MagicMock(return_value=runout)
        shotgun.driver.fabric.api.settings = MagicMock()
        shotgun.driver.execute = MagicMock(
            return_value=("RETURN_CODE", "STDOUT", "STDERR"))
        command = "COMMAND"

        driver = shotgun.driver.Driver({"host": "remote"}, None)
        result = driver.command(command)
        shotgun.driver.fabric.api.run.assert_called_with(command, pty=True)
        self.assertEquals(result, out)
        shotgun.driver.fabric.api.settings.assert_called_with(
            host_string="remote", timeout=2, warn_only=True)

        driver = shotgun.driver.Driver({}, None)
        result = driver.command(command)
        shotgun.driver.execute.assert_called_with(command)
        self.assertEquals(result, out)
示例#2
0
    def test_driver_command(self, mfabrun, mfabset, mexecute):
        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.return_code = "RETURN_CODE"
        out.stderr = "STDERR"

        runout = RunOut()
        runout.stdout = "STDOUT"
        runout.return_code = "RETURN_CODE"
        runout.stderr = "STDERR"

        mfabrun.return_value = runout
        mexecute.return_value = ("RETURN_CODE", "STDOUT", "STDERR")
        command = "COMMAND"

        driver = shotgun.driver.Driver(
            {"host": {"address": "remote_host"}}, None)
        result = driver.command(command)
        shotgun.driver.fabric.api.run.assert_called_with(command, pty=True)
        self.assertEqual(result, out)
        shotgun.driver.fabric.api.settings.assert_called_with(
            host_string="remote_host", timeout=2, command_timeout=10,
            warn_only=True, key_filename=None)

        driver = shotgun.driver.Driver({}, None)
        result = driver.command(command)
        shotgun.driver.execute.assert_called_with(command)
        self.assertEqual(result, out)
示例#3
0
    def test_driver_remote_command(self, mfabrun, mfabset, mccstring):
        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.return_code = "RETURN_CODE"
        mccstring.return_value.getvalue.return_value = out.stdout

        runout = RunOut()
        runout.return_code = "RETURN_CODE"
        mfabrun.return_value = runout

        command = "COMMAND"

        driver = shotgun.driver.Driver({"host": {
            "address": "remote_host"
        }}, None)
        result = driver.command(command)

        shotgun.driver.fabric.api.run.assert_called_with(command,
                                                         stdout=mock.ANY)
        shotgun.driver.fabric.api.settings.assert_called_with(
            host_string="remote_host",
            timeout=2,
            command_timeout=10,
            warn_only=True,
            key_filename=None)
        self.assertEqual(result, out)
示例#4
0
    def test_driver_local_command(self, mexecute):
        mexecute.return_value = ("RETURN_CODE", "STDOUT", "STDERR")

        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.stderr = "STDERR"
        out.return_code = "RETURN_CODE"

        command = "COMMAND"
        driver = shotgun.driver.Driver({}, None)
        result = driver.command(command)
        shotgun.driver.utils.execute.assert_called_with(command)
        self.assertEqual(result, out)
    def test_driver_local_command(self, mexecute):
        mexecute.return_value = ("RETURN_CODE", "STDOUT", "STDERR")

        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.stderr = "STDERR"
        out.return_code = "RETURN_CODE"

        command = "COMMAND"
        driver = shotgun.driver.Driver({}, None)
        result = driver.command(command)
        shotgun.driver.utils.execute.assert_called_with(command)
        self.assertEqual(result, out)
示例#6
0
    def test_command_timeout(self, mfabrun, mfabset, mstringio):
        mfabrun.side_effect = fabric.exceptions.CommandTimeout(10)

        mstdout = mock.MagicMock()
        mstdout.getvalue.return_value = 'FULL STDOUT'
        mstringio.return_value = mstdout

        command = "COMMAND"

        driver = shotgun.driver.Driver(
            {"host": {"address": "remote_host"}}, None)
        result = driver.command(command)

        mstringio.assert_has_calls([
            mock.call(writers=sys.stdout),
        ])
        mfabrun.assert_called_with(command, stdout=mstdout)
        self.assertEqual(result.stdout, 'FULL STDOUT')
    def test_driver_remote_command(self, mfabrun, mfabset, mccstring):
        out = shotgun.driver.CommandOut()
        out.stdout = "STDOUT"
        out.return_code = "RETURN_CODE"
        mccstring.return_value.getvalue.return_value = out.stdout

        runout = RunOut()
        runout.return_code = "RETURN_CODE"
        mfabrun.return_value = runout

        command = "COMMAND"

        driver = shotgun.driver.Driver(
            {"host": {"address": "remote_host"}}, None)
        result = driver.command(command)

        shotgun.driver.fabric.api.run.assert_called_with(
            command, stdout=mock.ANY)
        shotgun.driver.fabric.api.settings.assert_called_with(
            host_string="remote_host", timeout=2, command_timeout=10,
            warn_only=True, key_filename=None, abort_on_prompts=True)
        self.assertEqual(result, out)