How to use _replace_headers_template method in gabbi

Best Python code snippet using gabbi_python

case.py

Source:case.py Github

copy

Full Screen

...450 'unable to load data as %s' % self.content_type) from exc451 else:452 self.response_data = None453 self.output = decoded_output454 def _replace_headers_template(self, test_name, headers):455 replaced_headers = {}456 try:457 for name in headers:458 replaced_name = self.replace_template(name)459 replaced_headers[replaced_name] = self.replace_template(460 headers[name]461 )462 except TypeError as exc:463 raise exception.GabbiFormatError(464 'malformed headers in test %s: %s' % (test_name, exc))465 return replaced_headers466 def _run_test(self):467 """Make an HTTP request and compare the response with expectations."""468 test = self.test_data469 base_url = self.replace_template(test['url'])470 # Save the URL after replacers but before query_parameters471 self.url = base_url472 full_url = self._parse_url(base_url)473 # Replace variables in headers with variable values. This includes both474 # in the header key and the header value.475 test['request_headers'] = self._replace_headers_template(476 test['name'], test['request_headers'])477 test['response_headers'] = self._replace_headers_template(478 test['name'], test['response_headers'])479 method = test['method'].upper()480 headers = test['request_headers']481 if test['data'] != '':482 body = self._test_data_to_string(483 test['data'],484 utils.extract_content_type(headers, default='')[0])485 else:486 body = ''487 # ensure body is bytes, encoding as UTF-8 because that's488 # what we do here489 if isinstance(body, six.text_type):490 body = body.encode('UTF-8')491 if test['poll']:...

Full Screen

Full Screen

test_replacers.py

Source:test_replacers.py Github

copy

Full Screen

1#2# Licensed under the Apache License, Version 2.0 (the "License"); you may3# not use this file except in compliance with the License. You may obtain4# a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the11# License for the specific language governing permissions and limitations12# under the License.13"""A place to put test of the replacers.14"""15import os16import unittest17from gabbi import case18from gabbi import exception19class EnvironReplaceTest(unittest.TestCase):20 def test_environ_boolean(self):21 """Environment variables are always strings22 That doesn't always suit our purposes, so test that "True"23 and "False" become booleans as a special case.24 """25 http_case = case.HTTPTestCase('test_request')26 message = "$ENVIRON['moo']"27 os.environ['moo'] = "True"28 self.assertEqual(True, http_case._environ_replace(message))29 os.environ['moo'] = "False"30 self.assertEqual(False, http_case._environ_replace(message))31 os.environ['moo'] = "true"32 self.assertEqual(True, http_case._environ_replace(message))33 os.environ['moo'] = "faLse"34 self.assertEqual(False, http_case._environ_replace(message))35 os.environ['moo'] = "null"36 self.assertEqual(None, http_case._environ_replace(message))37 os.environ['moo'] = "1"38 self.assertEqual(1, http_case._environ_replace(message))39 os.environ['moo'] = "cow"40 self.assertEqual("cow", http_case._environ_replace(message))41 message = '$ENVIRON["moo"]'42 os.environ['moo'] = "True"43 self.assertEqual(True, http_case._environ_replace(message))44class TestReplaceHeaders(unittest.TestCase):45 def test_empty_headers(self):46 """A None value in headers should cause a GabbiFormatError."""47 http_case = case.HTTPTestCase('test_request')48 self.assertRaises(49 exception.GabbiFormatError,...

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