How to use _make_header method in tappy

Best Python code snippet using tappy_python

test_microversions.py

Source: test_microversions.py Github

copy

Full Screen

...31 ret_header = 'compute %s' % ret_header32 self.assertEqual(ret_header,33 res.headers[self.header_name])34 return res35 def _make_header(self, req_header):36 if 'nova' in self.header_name.lower():37 headers = {self.header_name: req_header}38 else:39 headers = {self.header_name: 'compute %s' % req_header}40 return headers41 def test_microversions_no_header(self):42 req = fakes.HTTPRequest.blank(43 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID,44 method='GET')45 res = req.get_response(self.app)46 self.assertEqual(200, res.status_int)47 resp_json = jsonutils.loads(res.body)48 self.assertEqual('val', resp_json['param'])49 def test_microversions_return_header(self):50 req = fakes.HTTPRequest.blank(51 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID)52 res = req.get_response(self.app)53 self.assertEqual(200, res.status_int)54 resp_json = jsonutils.loads(res.body)55 self.assertEqual('val', resp_json['param'])56 if 'nova' in self.header_name.lower():57 self.assertEqual("2.1", res.headers[self.header_name])58 else:59 self.assertEqual("compute 2.1", res.headers[self.header_name])60 self.assertIn(self.header_name, res.headers.getall('Vary'))61 @mock.patch("nova.api.openstack.api_version_request.max_api_version")62 def test_microversions_return_header_non_default(self,63 mock_maxver):64 mock_maxver.return_value = api_version.APIVersionRequest("2.3")65 req = fakes.HTTPRequest.blank(66 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID)67 req.headers = self._make_header('2.3')68 res = req.get_response(self.app)69 self.assertEqual(200, res.status_int)70 resp_json = jsonutils.loads(res.body)71 self.assertEqual('val2', resp_json['param'])72 if 'nova' in self.header_name.lower():73 self.assertEqual("2.3", res.headers[self.header_name])74 else:75 self.assertEqual("compute 2.3", res.headers[self.header_name])76 self.assertIn(self.header_name, res.headers.getall('Vary'))77 @mock.patch("nova.api.openstack.api_version_request.max_api_version")78 def test_microversions_return_header_fault(self, mock_maxver):79 mock_maxver.return_value = api_version.APIVersionRequest("3.0")80 req = fakes.HTTPRequest.blank(81 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID)82 req.headers = self._make_header('3.0')83 res = req.get_response(self.app)84 self.assertEqual(400, res.status_int)85 if 'nova' in self.header_name.lower():86 self.assertEqual("3.0", res.headers[self.header_name])87 else:88 self.assertEqual("compute 3.0", res.headers[self.header_name])89 self.assertIn(self.header_name, res.headers.getall('Vary'))90 @mock.patch("nova.api.openstack.api_version_request.max_api_version")91 def _check_microversion_response(self, url, req_version, resp_param,92 mock_maxver):93 mock_maxver.return_value = api_version.APIVersionRequest('2.3')94 req = fakes.HTTPRequest.blank(url)95 req.headers = self._make_header(req_version)96 res = req.get_response(self.app)97 self.assertEqual(200, res.status_int)98 resp_json = jsonutils.loads(res.body)99 self.assertEqual(resp_param, resp_json['param'])100 def test_microversions_with_header(self):101 self._check_microversion_response(102 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID,103 '2.3', 'val2')104 def test_microversions_with_header_exact_match(self):105 self._check_microversion_response(106 '/​v2/​%s/​microversions' % fakes.FAKE_PROJECT_ID,107 '2.2', 'val2')108 def test_microversions2_no_2_1_version(self):109 self._check_microversion_response(110 '/​v2/​%s/​microversions2' % fakes.FAKE_PROJECT_ID,111 '2.3', 'controller2_val1')112 @mock.patch("nova.api.openstack.api_version_request.max_api_version")113 def test_microversions2_later_version(self, mock_maxver):114 mock_maxver.return_value = api_version.APIVersionRequest("3.1")115 req = fakes.HTTPRequest.blank(116 '/​v2/​%s/​microversions2' % fakes.FAKE_PROJECT_ID)117 req.headers = self._make_header('3.0')118 res = req.get_response(self.app)119 self.assertEqual(202, res.status_int)120 resp_json = jsonutils.loads(res.body)121 self.assertEqual('controller2_val2', resp_json['param'])122 @mock.patch("nova.api.openstack.api_version_request.max_api_version")123 def test_microversions2_version_too_high(self, mock_maxver):124 mock_maxver.return_value = api_version.APIVersionRequest("3.5")125 req = fakes.HTTPRequest.blank(126 '/​v2/​%s/​microversions2' % fakes.FAKE_PROJECT_ID)127 req.headers = {self.header_name: '3.2'}128 res = req.get_response(self.app)129 self.assertEqual(404, res.status_int)130 def test_microversions2_version_too_low(self):131 req = fakes.HTTPRequest.blank(132 '/​v2/​%s/​microversions2' % fakes.FAKE_PROJECT_ID)133 req.headers = {self.header_name: '2.1'}134 res = req.get_response(self.app)135 self.assertEqual(404, res.status_int)136 @mock.patch("nova.api.openstack.api_version_request.max_api_version")137 def test_microversions_global_version_too_high(self,138 mock_maxver):139 mock_maxver.return_value = api_version.APIVersionRequest("3.5")140 req = fakes.HTTPRequest.blank(141 '/​v2/​%s/​microversions2' % fakes.FAKE_PROJECT_ID)142 req.headers = self._make_header('3.7')143 res = req.get_response(self.app)144 self.assertEqual(406, res.status_int)145 res_json = jsonutils.loads(res.body)146 self.assertEqual("Version 3.7 is not supported by the API. "147 "Minimum is 2.1 and maximum is 3.5.",148 res_json['computeFault']['message'])149 @mock.patch("nova.api.openstack.api_version_request.max_api_version")150 def test_microversions_schema(self, mock_maxver):151 mock_maxver.return_value = api_version.APIVersionRequest("3.3")152 req = fakes.HTTPRequest.blank(153 '/​v2/​%s/​microversions3' % fakes.FAKE_PROJECT_ID)154 req.method = 'POST'155 req.headers = self._make_header('2.2')156 req.environ['CONTENT_TYPE'] = "application/​json"157 req.body = jsonutils.dump_as_bytes({'dummy': {'val': 'foo'}})158 res = req.get_response(self.app)159 self.assertEqual(200, res.status_int)160 resp_json = jsonutils.loads(res.body)161 self.assertEqual('create_val1', resp_json['param'])162 if 'nova' in self.header_name.lower():163 self.assertEqual("2.2", res.headers[self.header_name])164 else:165 self.assertEqual("compute 2.2", res.headers[self.header_name])166 self.assertIn(self.header_name, res.headers.getall('Vary'))167 @mock.patch("nova.api.openstack.api_version_request.max_api_version")168 def test_microversions_schema_fail(self, mock_maxver):169 mock_maxver.return_value = api_version.APIVersionRequest("3.3")170 req = fakes.HTTPRequest.blank(171 '/​v2/​%s/​microversions3' % fakes.FAKE_PROJECT_ID)172 req.method = 'POST'173 req.headers = {self.header_name: '2.2'}174 req.environ['CONTENT_TYPE'] = "application/​json"175 req.body = jsonutils.dump_as_bytes({'dummy': {'invalid_param': 'foo'}})176 res = req.get_response(self.app)177 self.assertEqual(400, res.status_int)178 resp_json = jsonutils.loads(res.body)179 self.assertTrue(resp_json['badRequest']['message'].startswith(180 "Invalid input for field/​attribute dummy."))181 @mock.patch("nova.api.openstack.api_version_request.max_api_version")182 def test_microversions_schema_out_of_version_check(self,183 mock_maxver):184 mock_maxver.return_value = api_version.APIVersionRequest("3.3")185 req = fakes.HTTPRequest.blank(186 '/​v2/​%s/​microversions3/​1' % fakes.FAKE_PROJECT_ID)187 req.method = 'PUT'188 req.headers = self._make_header('2.2')189 req.body = jsonutils.dump_as_bytes({'dummy': {'inv_val': 'foo'}})190 req.environ['CONTENT_TYPE'] = "application/​json"191 res = req.get_response(self.app)192 self.assertEqual(200, res.status_int)193 resp_json = jsonutils.loads(res.body)194 self.assertEqual('update_val1', resp_json['param'])195 if 'nova' in self.header_name.lower():196 self.assertEqual("2.2", res.headers[self.header_name])197 else:198 self.assertEqual("compute 2.2", res.headers[self.header_name])199 @mock.patch("nova.api.openstack.api_version_request.max_api_version")200 def test_microversions_schema_second_version(self,201 mock_maxver):202 mock_maxver.return_value = api_version.APIVersionRequest("3.3")203 req = fakes.HTTPRequest.blank(204 '/​v2/​%s/​microversions3/​1' % fakes.FAKE_PROJECT_ID)205 req.headers = self._make_header('2.10')206 req.environ['CONTENT_TYPE'] = "application/​json"207 req.method = 'PUT'208 req.body = jsonutils.dump_as_bytes({'dummy': {'val2': 'foo'}})209 res = req.get_response(self.app)210 self.assertEqual(200, res.status_int)211 resp_json = jsonutils.loads(res.body)212 self.assertEqual('update_val1', resp_json['param'])213 if 'nova' in self.header_name.lower():214 self.assertEqual("2.10", res.headers[self.header_name])215 else:216 self.assertEqual("compute 2.10", res.headers[self.header_name])217 @mock.patch("nova.api.openstack.api_version_request.max_api_version")218 def _test_microversions_inner_function(self, version, expected_resp,219 mock_maxver):220 mock_maxver.return_value = api_version.APIVersionRequest("2.2")221 req = fakes.HTTPRequest.blank(222 '/​v2/​%s/​microversions4' % fakes.FAKE_PROJECT_ID)223 req.headers = self._make_header(version)224 req.environ['CONTENT_TYPE'] = "application/​json"225 req.method = 'POST'226 req.body = b''227 res = req.get_response(self.app)228 self.assertEqual(200, res.status_int)229 resp_json = jsonutils.loads(res.body)230 self.assertEqual(expected_resp, resp_json['param'])231 if 'nova' not in self.header_name.lower():232 version = 'compute %s' % version233 self.assertEqual(version, res.headers[self.header_name])234 def test_microversions_inner_function_v22(self):235 self._test_microversions_inner_function('2.2', 'controller4_val2')236 def test_microversions_inner_function_v21(self):237 self._test_microversions_inner_function('2.1', 'controller4_val1')238 @mock.patch("nova.api.openstack.api_version_request.max_api_version")239 def _test_microversions_actions(self, ret_code, ret_header, req_header,240 mock_maxver):241 mock_maxver.return_value = api_version.APIVersionRequest("2.3")242 req = fakes.HTTPRequest.blank(243 '/​v2/​%s/​microversions3/​1/​action' % fakes.FAKE_PROJECT_ID)244 if req_header:245 req.headers = self._make_header(req_header)246 req.method = 'POST'247 req.body = jsonutils.dump_as_bytes({'foo': None})248 res = self._test_microversions(self.app, req, ret_code,249 ret_header=ret_header)250 if ret_code == 202:251 resp_json = jsonutils.loads(res.body)252 self.assertEqual({'foo': 'bar'}, resp_json)253 def test_microversions_actions(self):254 self._test_microversions_actions(202, "2.1", "2.1")255 def test_microversions_actions_too_high(self):256 self._test_microversions_actions(404, "2.3", "2.3")257 def test_microversions_actions_no_header(self):258 self._test_microversions_actions(202, "2.1", None)259class MicroversionsTest(LegacyMicroversionsTest):...

Full Screen

Full Screen

cc_debug.py

Source: cc_debug.py Github

copy

Full Screen

...16from cloudinit import type_utils17from cloudinit import util18import copy19from StringIO import StringIO20def _make_header(text):21 header = StringIO()22 header.write("-" * 80)23 header.write("\n")24 header.write(text.center(80, ' '))25 header.write("\n")26 header.write("-" * 80)27 header.write("\n")28 return header.getvalue()29def handle(name, cfg, cloud, log, args):30 verbose = util.get_cfg_by_path(cfg, ('debug', 'verbose'), default=True)31 if args:32 # if args are provided (from cmdline) then explicitly set verbose33 out_file = args[0]34 verbose = True35 else:36 out_file = util.get_cfg_by_path(cfg, ('debug', 'output'))37 if not verbose:38 log.debug(("Skipping module named %s,"39 " verbose printing disabled"), name)40 return41 # Clean out some keys that we just don't care about showing...42 dump_cfg = copy.deepcopy(cfg)43 for k in ['log_cfgs']:44 dump_cfg.pop(k, None)45 all_keys = list(dump_cfg.keys())46 for k in all_keys:47 if k.startswith("_"):48 dump_cfg.pop(k, None)49 # Now dump it...50 to_print = StringIO()51 to_print.write(_make_header("Config"))52 to_print.write(util.yaml_dumps(dump_cfg))53 to_print.write("\n")54 to_print.write(_make_header("MetaData"))55 to_print.write(util.yaml_dumps(cloud.datasource.metadata))56 to_print.write("\n")57 to_print.write(_make_header("Misc"))58 to_print.write("Datasource: %s\n" %59 (type_utils.obj_name(cloud.datasource)))60 to_print.write("Distro: %s\n" % (type_utils.obj_name(cloud.distro)))61 to_print.write("Hostname: %s\n" % (cloud.get_hostname(True)))62 to_print.write("Instance ID: %s\n" % (cloud.get_instance_id()))63 to_print.write("Locale: %s\n" % (cloud.get_locale()))64 to_print.write("Launch IDX: %s\n" % (cloud.launch_index))65 contents = to_print.getvalue()66 content_to_file = []67 for line in contents.splitlines():68 line = "ci-info: %s\n" % (line)69 content_to_file.append(line)70 if out_file:71 util.write_file(out_file, "".join(content_to_file), 0644, "w")...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

What exactly do Scrum Masters perform throughout the course of a typical day

Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”

Starting & growing a QA Testing career

The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.

Feeding your QA Career – Developing Instinctive & Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

Testing in Production: A Detailed Guide

When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.

What will come after “agile”?

I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.

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