OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 import os |
| 3 |
| 4 import unittest |
| 5 |
| 6 from pexpect import pxssh |
| 7 |
| 8 class SSHTestBase(unittest.TestCase): |
| 9 def setUp(self): |
| 10 self.orig_path = os.environ.get('PATH') |
| 11 fakessh_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'f
akessh')) |
| 12 os.environ['PATH'] = fakessh_dir + \ |
| 13 ((os.pathsep + self.orig_path) if self.orig_path else '') |
| 14 |
| 15 def tearDown(self): |
| 16 if self.orig_path: |
| 17 os.environ['PATH'] = self.orig_path |
| 18 else: |
| 19 del os.environ['PATH'] |
| 20 |
| 21 class PxsshTestCase(SSHTestBase): |
| 22 def test_fake_ssh(self): |
| 23 ssh = pxssh.pxssh() |
| 24 #ssh.logfile_read = sys.stdout # DEBUG |
| 25 ssh.login('server', 'me', password='s3cret') |
| 26 ssh.sendline('ping') |
| 27 ssh.expect('pong', timeout=10) |
| 28 assert ssh.prompt(timeout=10) |
| 29 ssh.logout() |
| 30 |
| 31 def test_wrong_pw(self): |
| 32 ssh = pxssh.pxssh() |
| 33 try: |
| 34 ssh.login('server', 'me', password='wr0ng') |
| 35 except pxssh.ExceptionPxssh: |
| 36 pass |
| 37 else: |
| 38 assert False, 'Password should have been refused' |
| 39 |
| 40 def test_failed_set_unique_prompt(self): |
| 41 ssh = pxssh.pxssh() |
| 42 ssh.set_unique_prompt = lambda: False |
| 43 try: |
| 44 ssh.login('server', 'me', password='s3cret', |
| 45 auto_prompt_reset=True) |
| 46 except pxssh.ExceptionPxssh: |
| 47 pass |
| 48 else: |
| 49 assert False, 'should have raised exception, pxssh.ExceptionPxssh' |
| 50 |
| 51 |
| 52 if __name__ == '__main__': |
| 53 unittest.main() |
OLD | NEW |