Beispiel #1
0
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            c = Context()
            with c.prefix("cd foo"):
                c.sudo("whoami")

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            assert runner.run.called, "sudo() never called runner.run()!"
            assert runner.run.call_args[0][0] == cmd
Beispiel #2
0
 def kwarg_only_adds_to_kwarg(self, Local):
     runner = Local.return_value
     context = Context()
     watcher = self.watcher_klass()
     context.sudo("whoami", watchers=[watcher])
     # When sudo() called w/ user-specified watchers, we add ours to
     # that list
     watchers = runner.run.call_args[1]["watchers"]
     # Will raise ValueError if not in the list
     watchers.remove(watcher)
     # Only remaining item in list should be our sudo responder
     assert len(watchers) == 1
     assert isinstance(watchers[0], FailingResponder)
     assert watchers[0].pattern == self.escaped_prompt
Beispiel #3
0
        def _expect_responses(self, expected, config=None, kwargs=None):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            """
            if kwargs is None:
                kwargs = {}
            Local = Mock()
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.config.runners.local = Local
            context.sudo("whoami", **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]["watchers"]
            ]
            assert prompt_responses == expected