Best Python code snippet using tempest_python
test_subunit_describe_calls.py
Source:test_subunit_describe_calls.py
...113 return data114 def _assert_cli_message(self, data):115 data = self._bytes_to_string(data)116 self.assertIn("Running subunit_describe_calls ...", data)117 def _assert_deprecated_warning(self, stdout):118 self.assertIn(119 b"Use of: 'subunit-describe-calls' is deprecated, "120 b"please use: 'tempest subunit-describe-calls'", stdout)121 def _assert_expect_json(self, json_data):122 expected_file_name = os.path.join(123 os.path.dirname(os.path.abspath(__file__)),124 'subunit_describe_calls_data', 'calls_subunit_expected.json')125 with open(expected_file_name, "rb") as read_file:126 expected_result = json.load(read_file)127 self.assertDictEqual(expected_result, json_data)128 def _assert_headers_and_bodies(self, data):129 data = self._bytes_to_string(data)130 self.assertIn('- request headers:', data)131 self.assertIn('- request body:', data)132 self.assertIn('- response headers:', data)133 self.assertIn('- response body:', data)134 def _assert_methods_details(self, data):135 data = self._bytes_to_string(data)136 self.assertIn('foo', data)137 self.assertIn('- 200 POST request for Nova to v2.1/<id>/',138 data)139 self.assertIn('- 200 DELETE request for Nova to v2.1/<id>/',140 data)141 self.assertIn('- 200 GET request for Nova to v2.1/<id>/',142 data)143 self.assertIn('- 404 DELETE request for Nova to v2.1/<id>/',144 data)145 def _assert_mutual_exclusive_message(self, stderr):146 self.assertIn(b"usage: subunit-describe-calls "147 b"[-h] [-s [<subunit file>]]", stderr)148 self.assertIn(b"[-n <non subunit name>] [-o <output file>]",149 stderr)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):...
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!!