def test__run_runs_command(self): amt_power_driver = AMTPowerDriver() amt_power_driver.env = None command = (factory.make_name("command"),) power_pass = factory.make_name("power_pass") stdin = factory.make_name("stdin").encode("utf-8") popen_mock = self.patch_popen(return_value=(b"stdout", b"")) result = amt_power_driver._run(command, power_pass, stdin) self.expectThat(popen_mock.communicate, MockCalledOnceWith(stdin)) self.expectThat(result, Equals(b"stdout"))
def test__run_runs_command(self): amt_power_driver = AMTPowerDriver() amt_power_driver.env = None command = factory.make_name('command'), power_pass = factory.make_name('power_pass') stdin = factory.make_name('stdin').encode('utf-8') popen_mock = self.patch_popen(return_value=(b'stdout', b'')) result = amt_power_driver._run(command, power_pass, stdin) self.expectThat(popen_mock.communicate, MockCalledOnceWith(stdin)) self.expectThat(result, Equals(b'stdout'))
def test_run_runs_command(self): amt_power_driver = AMTPowerDriver() amt_power_driver.env = None command = (factory.make_name("command"), ) power_pass = factory.make_name("power_pass") stdin = factory.make_name("stdin").encode("utf-8") run_command_mock = self.patch_run_command(stdout=b"stdout") result = amt_power_driver._run(command, power_pass, stdin) run_command_mock.assert_called_once_with( *command, stdin=stdin, extra_environ={"AMT_PASSWORD": power_pass}, decode=False) self.expectThat(result, Equals(b"stdout"))