Best Python code snippet using pyresttest_python
test_tests.py
Source:test_tests.py
...330 self.assertEqual(1, len(binds))331 self.assertEqual('value', binds['var'])332 # Test that updates context correctly333 context = Context()334 test.update_context_before(context)335 self.assertEqual('value', context.get_value('var'))336 self.assertTrue(test.is_context_modifier())337 def test_test_url_templating(self):338 test = Test()339 test.set_url('$cheese', isTemplate=True)340 self.assertTrue(test.is_dynamic())341 self.assertEqual('$cheese', test.get_url())342 self.assertTrue(test.templates['url'])343 context = Context()344 context.bind_variable('cheese', 'stilton')345 self.assertEqual('stilton', test.get_url(context=context))346 realized = test.realize(context)347 self.assertEqual('stilton', realized.url)348 def test_test_content_templating(self):349 test = Test()350 handler = ContentHandler()351 handler.is_template_content = True352 handler.content = '{"first_name": "Gaius","id": "$id","last_name": "Baltar","login": "$login"}'353 context = Context()354 context.bind_variables({'id': 9, 'login': 'kvothe'})355 test.set_body(handler)356 templated = test.realize(context=context)357 self.assertEqual(string.Template(handler.content).safe_substitute(context.get_values()),358 templated.body)359 def test_header_templating(self):360 test = Test()361 head_templated = {'$key': "$val"}362 context = Context()363 context.bind_variables({'key': 'cheese', 'val': 'gouda'})364 # No templating applied365 test.headers = head_templated366 head = test.get_headers()367 self.assertEqual(1, len(head))368 self.assertEqual('$val', head['$key'])369 test.set_headers(head_templated, isTemplate=True)370 self.assertTrue(test.templates)371 self.assertTrue(test.NAME_HEADERS in test.templates)372 # No context, no templating373 head = test.headers374 self.assertEqual(1, len(head))375 self.assertEqual('$val', head['$key'])376 # Templated with context377 head = test.get_headers(context=context)378 self.assertEqual(1, len(head))379 self.assertEqual('gouda', head['cheese'])380 def test_update_context_variables(self):381 test = Test()382 context = Context()383 context.bind_variable('foo', 'broken')384 test.variable_binds = {'foo': 'correct', 'test': 'value'}385 test.update_context_before(context)386 self.assertEqual('correct', context.get_value('foo'))387 self.assertEqual('value', context.get_value('test'))388 def test_update_context_generators(self):389 """ Test updating context variables using generator """390 test = Test()391 context = Context()392 context.bind_variable('foo', 'broken')393 test.variable_binds = {'foo': 'initial_value'}394 test.generator_binds = {'foo': 'gen'}395 context.add_generator('gen', generators.generator_basic_ids())396 test.update_context_before(context)397 self.assertEqual(1, context.get_value('foo'))398 test.update_context_before(context)399 self.assertEqual(2, context.get_value('foo'))400if __name__ == '__main__':...
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!!