def setUp(self): self.oms_ssh = OmsShellProtocol() auth = getUtility(IAuthentication, context=None) user = auth.getPrincipal('user') user.groups.append('admins') self.oms_ssh.batch = True self.oms_ssh.logged_in(user) self.oms_ssh.batch = False self.terminal = mock.Mock() self.oms_ssh.terminal = self.terminal self.oms_ssh.connectionMade() # the standard model doesn't have any command or path which # is a prefix of another (len > 1), I don't want to force changes # to the model just for testing completion, so we have monkey patch # the commands() function and add a command 'hello'. self.orig_commands = registry.commands class HelloCmd(Cmd): name = 'hello' registry.commands = lambda: dict(hello=HelloCmd, **self.orig_commands())
def setUp(self): self.oms_ssh = OmsShellProtocol() auth = getUtility(IAuthentication, context=None) user = auth.getPrincipal('user') user.groups.append('admins') self.oms_ssh.batch = True self.oms_ssh.logged_in(user) self.oms_ssh.batch = False self.oms_ssh.history_save_enabled = False self.terminal = mock.Mock() self.oms_ssh.terminal = self.terminal self.oms_ssh.enable_colors = False # Since uuids are random, static files/subdirectories like 'by-name' # subdir could be arbitrarily placed among them. # Let's monkeypatch the Container._new_id method to reasonably ensure # that created objects will always come first. # Order wasn't guaranted by OOBTree, now we sort in `ls` so this will work. self.old_new_id = Container._new_id Container._new_id = lambda self_: '0000_' + self.old_new_id(self_)
def connection_made(self, terminal, size): self.shell = OmsShellProtocol() self.shell.set_terminal(terminal) self.shell.connectionMade() self.shell.terminalSize(size[0], size[1]) self.shell.logged_in(self.principal)