Best Python code snippet using localstack_python
test_ssh.py
Source:test_ssh.py
1import os, io2import mock3from twisted.trial import unittest4from ..cli import cmd_ssh5OTHERS = ["config", "config~", "known_hosts", "known_hosts~"]6class FindPubkey(unittest.TestCase):7 def test_find_one(self):8 files = OTHERS + ["id_rsa.pub", "id_rsa"]9 pubkey_data = u"ssh-rsa AAAAkeystuff email@host\n"10 pubkey_file = io.StringIO(pubkey_data)11 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):12 with mock.patch("os.listdir", return_value=files) as ld:13 with mock.patch("wormhole.cli.cmd_ssh.open",14 return_value=pubkey_file):15 res = cmd_ssh.find_public_key()16 self.assertEqual(ld.mock_calls,17 [mock.call(os.path.expanduser("~/.ssh/"))])18 self.assertEqual(len(res), 3, res)19 kind, keyid, pubkey = res20 self.assertEqual(kind, "ssh-rsa")21 self.assertEqual(keyid, "email@host")22 self.assertEqual(pubkey, pubkey_data)23 def test_find_none(self):24 files = OTHERS # no pubkey25 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):26 with mock.patch("os.listdir", return_value=files):27 e = self.assertRaises(cmd_ssh.PubkeyError,28 cmd_ssh.find_public_key)29 dot_ssh = os.path.expanduser("~/.ssh/")30 self.assertEqual(str(e), "No public keys in '{}'".format(dot_ssh))31 def test_bad_hint(self):32 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=False):33 e = self.assertRaises(cmd_ssh.PubkeyError,34 cmd_ssh.find_public_key,35 hint="bogus/path")36 self.assertEqual(str(e), "Can't find 'bogus/path'")37 def test_find_multiple(self):38 files = OTHERS + ["id_rsa.pub", "id_rsa", "id_dsa.pub", "id_dsa"]39 pubkey_data = u"ssh-rsa AAAAkeystuff email@host\n"40 pubkey_file = io.StringIO(pubkey_data)41 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):42 with mock.patch("os.listdir", return_value=files):43 responses = iter(["frog", "NaN", "-1", "0"])44 with mock.patch("click.prompt",45 side_effect=lambda p: next(responses)):46 with mock.patch("wormhole.cli.cmd_ssh.open",47 return_value=pubkey_file):48 res = cmd_ssh.find_public_key()49 self.assertEqual(len(res), 3, res)50 kind, keyid, pubkey = res51 self.assertEqual(kind, "ssh-rsa")52 self.assertEqual(keyid, "email@host")...
59039_test_ssh.py
Source:59039_test_ssh.py
1import os, io2import mock3from twisted.trial import unittest4from ..cli import cmd_ssh5OTHERS = ["config", "config~", "known_hosts", "known_hosts~"]6class FindPubkey(unittest.TestCase):7 def test_find_one(self):8 files = OTHERS + ["id_rsa.pub", "id_rsa"]9 pubkey_data = u"ssh-rsa AAAAkeystuff email@host\n"10 pubkey_file = io.StringIO(pubkey_data)11 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):12 with mock.patch("os.listdir", return_value=files) as ld:13 with mock.patch("wormhole.cli.cmd_ssh.open",14 return_value=pubkey_file):15 res = cmd_ssh.find_public_key()16 self.assertEqual(ld.mock_calls,17 [mock.call(os.path.expanduser("~/.ssh/"))])18 self.assertEqual(len(res), 3, res)19 kind, keyid, pubkey = res20 self.assertEqual(kind, "ssh-rsa")21 self.assertEqual(keyid, "email@host")22 self.assertEqual(pubkey, pubkey_data)23 def test_find_none(self):24 files = OTHERS # no pubkey25 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):26 with mock.patch("os.listdir", return_value=files):27 e = self.assertRaises(cmd_ssh.PubkeyError,28 cmd_ssh.find_public_key)29 dot_ssh = os.path.expanduser("~/.ssh/")30 self.assertEqual(str(e), "No public keys in '{}'".format(dot_ssh))31 def test_bad_hint(self):32 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=False):33 e = self.assertRaises(cmd_ssh.PubkeyError,34 cmd_ssh.find_public_key,35 hint="bogus/path")36 self.assertEqual(str(e), "Can't find 'bogus/path'")37 def test_find_multiple(self):38 files = OTHERS + ["id_rsa.pub", "id_rsa", "id_dsa.pub", "id_dsa"]39 pubkey_data = u"ssh-rsa AAAAkeystuff email@host\n"40 pubkey_file = io.StringIO(pubkey_data)41 with mock.patch("wormhole.cli.cmd_ssh.exists", return_value=True):42 with mock.patch("os.listdir", return_value=files):43 responses = iter(["frog", "NaN", "-1", "0"])44 with mock.patch("click.prompt",45 side_effect=lambda p: next(responses)):46 with mock.patch("wormhole.cli.cmd_ssh.open",47 return_value=pubkey_file):48 res = cmd_ssh.find_public_key()49 self.assertEqual(len(res), 3, res)50 kind, keyid, pubkey = res51 self.assertEqual(kind, "ssh-rsa")52 self.assertEqual(keyid, "email@host")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!