How to use add_request_args method in tavern

Best Python code snippet using tavern

rest.py

Source: rest.py Github

copy

Full Screen

...50 if "method" not in rspec:51 logger.debug("Using default GET method")52 rspec["method"] = "GET"53 fspec = format_keys(rspec, test_block_config["variables"])54 def add_request_args(keys: list, optional: bool):55 """56 Builds the request_args dict57 :param keys:58 :param optional:59 """60 for key in keys:61 try:62 if key == 'headers' and key in fspec:63 request_args[key] = {'Content-type': "application/​json"}64 for header_key in fspec[key].keys():65 if header_key == '$ext':66 ext_func = get_wrapped_request_function(fspec[key]["$ext"])67 request_args[key].update(ext_func(fspec, request_args))68 elif isinstance(fspec[key][header_key], dict):69 ext_func = get_wrapped_request_function(fspec[key][header_key]["$ext"])70 request_args[key][header_key] = ext_func(fspec, request_args)71 else:72 request_args[key][header_key] = fspec[key][header_key]73 elif '$ext' in fspec[key]:74 ext_func = get_wrapped_request_function(fspec[key]["$ext"])75 request_args[key] = ext_func(fspec, request_args)76 else:77 request_args[key] = fspec[key]78 except KeyError:79 if optional or (key in request_args):80 continue81 # This should never happen82 raise83 add_request_args(required_in_file, False)84 add_request_args(optional_in_file, True)85 if "auth" in fspec:86 request_args["auth"] = tuple(fspec["auth"])87 for key in optional_in_file:88 try:89 func = get_wrapped_create_function(request_args[key].pop("$ext"))90 except (KeyError, TypeError):91 pass92 else:93 request_args[key] = func()94 # If there's any nested json in parameters, urlencode it95 # if you pass nested json to 'params' then requests silently fails and just96 # passes the 'top level' key, ignoring all the nested json. I don't think97 # there's a standard way to do this, but urlencoding it seems sensible98 # eg https:/​/​openid.net/​specs/​openid-connect-core-1_0.html#ClaimsParameter...

Full Screen

Full Screen

test_admin.py

Source: test_admin.py Github

copy

Full Screen

...17 admin.register(Image, ImageAdmin)18 super(ImageAdminTest, cls).setUpTestData()19 cls.obj = Image.objects.create(image=Image.create_empty_image_file(name='hello.jpg'), alt="World")20 # @property21 # def add_request_args(self):22 # raise NotImplementedError23 def test_autocomplete(self):24 url = f"{self._get_url('autocomplete')}"25 response = self.client.get(url + "?term=hello", follow=True)26 self.assertEqual(response.request.get('PATH_INFO'), url)27 self.assertEqual(response.status_code, 200)28 self.assertEqual(len(response.json()["results"]), 1, response.content)29 def test_get_on_image_upload_returns_404(self):30 url = self._get_url('image_upload')31 response = self.client.get(url)32 self.assertEqual(response.status_code, 404, response.content)33 def test_get_on_delete_upload_returns_404(self):34 url = self._get_url('image_delete', self.obj.pk)35 response = self.client.get(url)36 self.assertEqual(response.status_code, 404, response.content)37 def test_valid_post_on_image_upload_creates_instance(self):38 url = self._get_url('image_upload')39 response = self.client.post(url,40 # content_type="application/​x-www-form-urlencoded",41 follow=True,42 **self.add_request_args(),43 )44 self.assertEqual(response.status_code, 201, response.content)45 self.assertEqual(self.model.objects.count(), 2)46 def test_invalid_post_on_image_upload_does_not_create_instance(self):47 url = self._get_url('image_upload')48 response = self.client.post(url,49 data={},50 follow=True,51 )52 self.assertEqual(response.status_code, 400, response.content)53 self.assertEqual(self.model.objects.count(), 1)54 def test_valid_post_on_image_deletes_pk(self):55 to_delete=Image.objects.create(image=Image.create_empty_image_file(name='to_delete.jpg'), alt="To Delete")56 url = self._get_url('image_delete', to_delete.pk)57 self.assertEqual(self.model.objects.count(), 2)58 response = self.client.post(url)59 self.assertEqual(response.status_code, 201, response.content)60 self.assertEqual(self.model.objects.count(), 1)61 def test_inexisting_post_on_image_delete_returns_404(self):62 pk=Image.objects.all().aggregate(Max('id'))['id__max']+163 url = self._get_url('image_delete', pk)64 response = self.client.post(url,)65 self.assertEqual(response.status_code, 404, response.content)66 self.assertEqual(self.model.objects.count(), 1)67 def add_request_args(self):68 form = ImageForm(69 data={'folder': settings.BASE_FOLDER, },70 files={'image': Image.create_empty_image_file(), })71 self.assertTrue(form.is_valid(), form.errors)...

Full Screen

Full Screen

arguments.py

Source: arguments.py Github

copy

Full Screen

1import argparse2def add_request_args(parser):3 parser.add_argument(4 "-d0", "--start-date", required=False, default="25-10-2021", help="Start Date"5 )6 parser.add_argument(7 "-d1", "--end-date", required=False, default="25-11-2021", help="End Date"8 )9 parser.add_argument(10 "-i",11 "--invoice-number", required=False, help="Invoice Number",12 )13 parser.add_argument(14 "-a",15 "--clockify-api-key",16 required=False,17 help="Clockify API Key",18 )19 parser.add_argument(20 "-c",21 "--config",22 required=False,23 help="Config File",24 )25 parser.add_argument(26 "-e",27 "--export-type",28 required=False,29 help="Export Type",30 default="pdf",31 )32def create_request_parser(parent):33 parser = parent.add_parser("generate", help="generator module")34 add_request_args(parser)35def parse_args():36 parser = argparse.ArgumentParser(prog="invoicify", description="CLI with some awesome things")37 parser.add_argument(38 "-l",39 "--log-level",40 default="INFO",41 help="Set log level, defaults to %(default)s",42 )43 add_request_args(parser)44 subparser = parser.add_subparsers(45 title="commands", dest="commands", help="Provided source specific subparsers"46 )47 create_request_parser(subparser)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Create Custom Menus with CSS Select

When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.

Why does DevOps recommend shift-left testing principles?

Companies are using DevOps to quickly respond to changing market dynamics and customer requirements.

How to Recognize and Hire Top QA / DevOps Engineers

With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.

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.

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

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