How to use unmock_io method in autotest

Best Python code snippet using autotest_python

acl_unittest.py

Source:acl_unittest.py Github

copy

Full Screen

...30 acl_list = acl.acl_list()31 self.god.mock_io()32 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)33 self.assertRaises(cli_mock.ExitException, acl_list.parse)34 (out, err) = self.god.unmock_io()35 self.god.check_playback()36 self.assert_(err.find('usage'))37 def test_parse_list_acl_user(self):38 sys.argv = ['atest', 'acl0', '-u', 'user']39 self._test_parse_bad_options()40 def test_parse_list_acl_2users(self):41 sys.argv = ['atest', '-u', 'user0,user1']42 self._test_parse_bad_options()43 def test_parse_list_acl_host(self):44 sys.argv = ['atest', 'acl0', '--mach', 'mach']45 self._test_parse_bad_options()46 def test_parse_list_acl_2hosts(self):47 sys.argv = ['atest', '--mach', 'mach0,mach1']48 self._test_parse_bad_options()49 def test_parse_list_user_host(self):50 sys.argv = ['atest', '-u', 'user', '--mach', 'mach']51 self._test_parse_bad_options()52 def test_parse_list_all(self):53 sys.argv = ['atest', '-u', 'user', '--mach', 'mach', 'acl0']54 self._test_parse_bad_options()55 def test_execute_list_all_acls(self):56 self.run_cmd(argv=['atest', 'acl', 'list', '-v'],57 rpcs=[('get_acl_groups', {}, True,58 [{'id': 1L,59 'name': 'Everyone',60 'description': '',61 'users': ['debug_user'],62 'hosts': []}])],63 out_words_ok=['debug_user'])64 def test_execute_list_acls_for_acl(self):65 self.run_cmd(argv=['atest', 'acl', 'list', 'acl0'],66 rpcs=[('get_acl_groups', {'name__in': ['acl0']}, True,67 [{'id': 1L,68 'name': 'Everyone',69 'description': '',70 'users': ['user0'],71 'hosts': []}])],72 out_words_ok=['Everyone'])73 def test_execute_list_acls_for_user(self):74 self.run_cmd(argv=['atest', 'acl', 'list', '-v', '--user', 'user0'],75 rpcs=[('get_acl_groups', {'users__login': 'user0'}, True,76 [{'id': 1L,77 'name': 'Everyone',78 'description': '',79 'users': ['user0'],80 'hosts': []}])],81 out_words_ok=['user0'])82 def test_execute_list_acls_for_host(self):83 self.run_cmd(argv=['atest', 'acl', 'list', '-m', 'host0'],84 rpcs=[('get_acl_groups', {'hosts__hostname': 'host0'},85 True,86 [{'id': 1L,87 'name': 'Everyone',88 'description': '',89 'users': ['user0'],90 'hosts': ['host0']}])],91 out_words_ok=['Everyone'],92 out_words_no=['host0'])93 def test_execute_list_acls_for_host_verb(self):94 self.run_cmd(argv=['atest', 'acl', 'list', '-m', 'host0', '-v'],95 rpcs=[('get_acl_groups', {'hosts__hostname': 'host0'},96 True,97 [{'id': 1L,98 'name': 'Everyone',99 'description': '',100 'users': ['user0'],101 'hosts': ['host0']}])],102 out_words_ok=['Everyone', 'host0'])103class acl_create_unittest(cli_mock.cli_unittest):104 def test_acl_create_parse_ok(self):105 acls = acl.acl_create()106 sys.argv = ['atest', 'acl0',107 '--desc', 'my_favorite_acl']108 acls.parse()109 self.assertEqual('my_favorite_acl', acls.data['description'])110 def test_acl_create_parse_no_desc(self):111 self.god.mock_io()112 acls = acl.acl_create()113 sys.argv = ['atest', 'acl0']114 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)115 self.assertRaises(cli_mock.ExitException, acls.parse)116 self.god.check_playback()117 self.god.unmock_io()118 def test_acl_create_parse_2_acls(self):119 self.god.mock_io()120 acls = acl.acl_create()121 sys.argv = ['atest', 'acl0', 'acl1',122 '-desc', 'my_favorite_acl']123 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)124 self.assertRaises(cli_mock.ExitException, acls.parse)125 self.god.check_playback()126 self.god.unmock_io()127 def test_acl_create_parse_no_option(self):128 self.god.mock_io()129 acls = acl.acl_create()130 sys.argv = ['atest']131 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)132 self.assertRaises(cli_mock.ExitException, acls.parse)133 self.god.check_playback()134 self.god.unmock_io()135 def test_acl_create_acl_ok(self):136 self.run_cmd(argv=['atest', 'acl', 'create', 'acl0',137 '--desc', 'my_favorite_acl'],138 rpcs=[('add_acl_group',139 {'description': 'my_favorite_acl',140 'name': 'acl0'},141 True,142 3L)],143 out_words_ok=['acl0'])144 def test_acl_create_duplicate_acl(self):145 self.run_cmd(argv=['atest', 'acl', 'create', 'acl0',146 '--desc', 'my_favorite_acl'],147 rpcs=[('add_acl_group',148 {'description': 'my_favorite_acl',149 'name': 'acl0'},150 False,151 'ValidationError:'152 '''{'name': 'This value must be '''153 '''unique (acl0)'}''')],154 err_words_ok=['acl0', 'ValidationError',155 'unique'])156class acl_delete_unittest(cli_mock.cli_unittest):157 def test_acl_delete_acl_ok(self):158 self.run_cmd(argv=['atest', 'acl', 'delete', 'acl0',159 '--no-confirmation'],160 rpcs=[('delete_acl_group', {'id': 'acl0'}, True, None)],161 out_words_ok=['acl0'])162 def test_acl_delete_acl_does_not_exist(self):163 self.run_cmd(argv=['atest', 'acl', 'delete', 'acl0',164 '--no-confirmation'],165 rpcs=[('delete_acl_group', {'id': 'acl0'},166 False,167 'DoesNotExist: acl_group matching '168 'query does not exist.')],169 err_words_ok=['acl0', 'DoesNotExist'])170 def test_acl_delete_multiple_acl_ok(self):171 alist = cli_mock.create_file('acl2\nacl1')172 self.run_cmd(argv=['atest', 'acl', 'delete',173 'acl0', 'acl1', '--no-confirmation',174 '--alist', alist.name],175 rpcs=[('delete_acl_group',176 {'id': 'acl0'},177 True,178 None),179 ('delete_acl_group',180 {'id': 'acl1'},181 True,182 None),183 ('delete_acl_group',184 {'id': 'acl2'},185 True,186 None)],187 out_words_ok=['acl0', 'acl1', 'acl2', 'Deleted'])188 alist.clean()189 def test_acl_delete_multiple_acl_bad(self):190 alist = cli_mock.create_file('acl2\nacl1')191 self.run_cmd(argv=['atest', 'acl', 'delete',192 'acl0', 'acl1', '--no-confirmation',193 '--alist', alist.name],194 rpcs=[('delete_acl_group',195 {'id': 'acl0'},196 True,197 None),198 ('delete_acl_group',199 {'id': 'acl1'},200 False,201 'DoesNotExist: acl_group '202 'matching query does not exist.'),203 ('delete_acl_group',204 {'id': 'acl2'},205 True,206 None)],207 out_words_ok=['acl0', 'acl2', 'Deleted'],208 err_words_ok=['acl1', 'delete_acl_group',209 'DoesNotExist', 'acl_group',210 'matching'])211 alist.clean()212class acl_add_unittest(cli_mock.cli_unittest):213 def test_acl_add_parse_no_option(self):214 self.god.mock_io()215 acls = acl.acl_add()216 sys.argv = ['atest']217 sys.exit.expect_call(1).and_raises(cli_mock.ExitException)218 self.assertRaises(cli_mock.ExitException, acls.parse)219 self.god.unmock_io()220 self.god.check_playback()221 def test_acl_add_users_hosts(self):222 self.run_cmd(argv=['atest', 'acl', 'add', 'acl0',223 '-u', 'user0,user1', '-m', 'host0'],224 rpcs=[('acl_group_add_users',225 {'id': 'acl0',226 'users': ['user0', 'user1']},227 True,228 None),229 ('acl_group_add_hosts',230 {'id': 'acl0',231 'hosts': ['host0']},232 True,233 None)],...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful