How to use _assert_no_headers_and_bodies method in tempest

Best Python code snippet using tempest_python

test_subunit_describe_calls.py

Source:test_subunit_describe_calls.py Github

copy

Full Screen

...150 self.assertIn(b"[-p <ports file>] [-v | -a]", stderr)151 self.assertIn(152 b"subunit-describe-calls: error: argument -v/--verbose: "153 b"not allowed with argument -a/--all-stdout", stderr)154 def _assert_no_headers_and_bodies(self, data):155 data = self._bytes_to_string(data)156 self.assertNotIn('- request headers:', data)157 self.assertNotIn('- request body:', data)158 self.assertNotIn('- response headers:', data)159 self.assertNotIn('- response body:', data)160class TestMainCli(TestCliBase):161 """Test cases that use subunit_describe_calls module main interface162 via subprocess calls to make sure the total user experience163 is well defined and tested. This interface is deprecated.164 Note: these test do not affect code coverage percentages.165 """166 def test_main_output_file(self):167 temp_file = tempfile.mkstemp()[1]168 p = subprocess.Popen([169 'subunit-describe-calls', '-s', self._subunit_file,170 '-o', temp_file], stdin=subprocess.PIPE,171 stdout=subprocess.PIPE, stderr=subprocess.PIPE)172 stdout, stderr = p.communicate()173 self.assertEqual(0, p.returncode)174 self._assert_cli_message(stdout)175 self._assert_deprecated_warning(stdout)176 with open(temp_file, 'r') as file:177 data = json.loads(file.read())178 self._assert_expect_json(data)179 def test_main_verbose(self):180 p = subprocess.Popen([181 'subunit-describe-calls', '-s', self._subunit_file,182 '-v'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,183 stderr=subprocess.PIPE)184 stdout, stderr = p.communicate()185 self.assertEqual(0, p.returncode)186 self._assert_cli_message(stdout)187 self._assert_deprecated_warning(stdout)188 self._assert_methods_details(stdout)189 self._assert_headers_and_bodies(stdout)190 def test_main_all_stdout(self):191 p = subprocess.Popen([192 'subunit-describe-calls', '-s', self._subunit_file,193 '--all-stdout'], stdin=subprocess.PIPE, stdout=subprocess.PIPE,194 stderr=subprocess.PIPE)195 stdout, stderr = p.communicate()196 self.assertEqual(0, p.returncode)197 self._assert_cli_message(stdout)198 self._assert_deprecated_warning(stdout)199 self._assert_methods_details(stdout)200 self._assert_headers_and_bodies(stdout)201 def test_main(self):202 p = subprocess.Popen([203 'subunit-describe-calls', '-s', self._subunit_file],204 stdin=subprocess.PIPE, stdout=subprocess.PIPE,205 stderr=subprocess.PIPE)206 stdout, stderr = p.communicate()207 self.assertEqual(0, p.returncode)208 self._assert_cli_message(stdout)209 self._assert_deprecated_warning(stdout)210 self._assert_methods_details(stdout)211 self._assert_no_headers_and_bodies(stdout)212 def test_main_verbose_and_all_stdout(self):213 p = subprocess.Popen([214 'subunit-describe-calls', '-s', self._subunit_file,215 '-a', '-v'],216 stdin=subprocess.PIPE, stdout=subprocess.PIPE,217 stderr=subprocess.PIPE)218 stdout, stderr = p.communicate()219 self.assertEqual(2, p.returncode)220 self._assert_cli_message(stdout)221 self._assert_deprecated_warning(stdout)222 self._assert_mutual_exclusive_message(stderr)223class TestCli(TestCliBase):224 """Test cases that use tempest subunit_describe_calls cliff interface225 via subprocess calls to make sure the total user experience226 is well defined and tested.227 Note: these test do not affect code coverage percentages.228 """229 def _assert_cliff_verbose(self, stdout):230 self.assertIn(b'tempest initialize_app', stdout)231 self.assertIn(b'prepare_to_run_command TempestSubunitDescribeCalls',232 stdout)233 self.assertIn(b'tempest clean_up TempestSubunitDescribeCalls',234 stdout)235 def test_run_all_stdout(self):236 p = subprocess.Popen(['tempest', 'subunit-describe-calls',237 '-s', self._subunit_file, '-a'],238 stdin=subprocess.PIPE,239 stdout=subprocess.PIPE,240 stderr=subprocess.PIPE)241 stdout, stderr = p.communicate()242 self.assertEqual(0, p.returncode)243 self._assert_cli_message(stdout)244 self._assert_methods_details(stdout)245 self._assert_headers_and_bodies(stdout)246 def test_run_verbose(self):247 p = subprocess.Popen(['tempest', 'subunit-describe-calls',248 '-s', self._subunit_file, '-v'],249 stdin=subprocess.PIPE,250 stdout=subprocess.PIPE,251 stderr=subprocess.PIPE)252 stdout, stderr = p.communicate()253 self.assertEqual(0, p.returncode)254 self._assert_cli_message(stdout)255 self._assert_methods_details(stdout)256 self._assert_no_headers_and_bodies(stdout)257 self._assert_cliff_verbose(stderr)258 def test_run_min(self):259 p = subprocess.Popen(['tempest', 'subunit-describe-calls',260 '-s', self._subunit_file],261 stdin=subprocess.PIPE,262 stdout=subprocess.PIPE,263 stderr=subprocess.PIPE)264 stdout, stderr = p.communicate()265 self.assertEqual(0, p.returncode)266 self._assert_cli_message(stdout)267 self._assert_methods_details(stdout)268 self._assert_no_headers_and_bodies(stdout)269 def test_run_verbose_all_stdout(self):270 """Test Cliff -v argument271 Since Cliff framework has a argument at the272 abstract command level the -v or --verbose for273 this command is not processed as a boolean.274 So the use of verbose only exists for the275 deprecated main CLI interface. When the276 main is deleted this test would not be needed.277 """278 p = subprocess.Popen(['tempest', 'subunit-describe-calls',279 '-s', self._subunit_file, '-a', '-v'],280 stdin=subprocess.PIPE,281 stdout=subprocess.PIPE,282 stderr=subprocess.PIPE)283 stdout, stderr = p.communicate()284 self.assertEqual(0, p.returncode)285 self._assert_cli_message(stdout)286 self._assert_cliff_verbose(stderr)287 self._assert_methods_details(stdout)288class TestSubunitDescribeCalls(TestCliBase):289 """Test cases use the subunit_describe_calls module interface290 and effect code coverage reporting291 """292 def setUp(self):293 super(TestSubunitDescribeCalls, self).setUp()294 self.test_object = subunit_describe_calls.TempestSubunitDescribeCalls(295 app=mock.Mock(),296 app_args=mock.Mock(spec=argparse.Namespace))297 def test_parse(self):298 with open(self._subunit_file, 'r') as read_file:299 parser = subunit_describe_calls.parse(300 read_file, "pythonlogging", None)301 self._assert_expect_json(parser.test_logs)302 def test_get_description(self):303 self.assertEqual(subunit_describe_calls.DESCRIPTION,304 self.test_object.get_description())305 def test_get_parser_default_min(self):306 parser = self.test_object.get_parser('NAME')307 parsed_args = parser.parse_args([])308 self.assertIsNone(parsed_args.output_file)309 self.assertIsNone(parsed_args.ports)310 self.assertFalse(parsed_args.all_stdout)311 self.assertEqual(parsed_args.subunit, sys.stdin)312 def test_get_parser_default_max(self):313 temp_dir = tempfile.mkdtemp(prefix="parser")314 self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)315 outfile_name = os.path.join(temp_dir, 'output.json')316 open(outfile_name, 'a').close()317 portfile_name = os.path.join(temp_dir, 'ports.json')318 open(portfile_name, 'a').close()319 parser = self.test_object.get_parser('NAME')320 parsed_args = parser.parse_args(["-a", "-o " + outfile_name,321 "-p " + portfile_name])322 self.assertIsNotNone(parsed_args.output_file)323 self.assertIsNotNone(parsed_args.ports)324 self.assertTrue(parsed_args.all_stdout)325 self.assertEqual(parsed_args.subunit, sys.stdin)326 def test_take_action_min(self):327 parser = self.test_object.get_parser('NAME')328 parsed_args = parser.parse_args(["-s" + self._subunit_file],)329 with patch('sys.stdout', new=StringIO()) as mock_stdout:330 self.test_object.take_action(parsed_args)331 stdout_data = mock_stdout.getvalue()332 self._assert_methods_details(stdout_data)333 self._assert_no_headers_and_bodies(stdout_data)334 def test_take_action_all_stdout(self):335 parser = self.test_object.get_parser('NAME')336 parsed_args = parser.parse_args(["-as" + self._subunit_file],)337 with patch('sys.stdout', new=StringIO()) as mock_stdout:338 self.test_object.take_action(parsed_args)339 stdout_data = mock_stdout.getvalue()340 self._assert_methods_details(stdout_data)341 self._assert_headers_and_bodies(stdout_data)342 def test_take_action_outfile_files(self):343 temp_file = tempfile.mkstemp()[1]344 parser = self.test_object.get_parser('NAME')345 parsed_args = parser.parse_args(346 ["-as" + self._subunit_file, '-o', temp_file], )347 with patch('sys.stdout', new=StringIO()) as mock_stdout:...

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 tempest 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