How to use maybe_get_save_values_from_save_block method in tavern

Best Python code snippet using tavern

test_rest.py

Source:test_rest.py Github

copy

Full Screen

...37 def test_save_body(self, example_response, includes):38 """Save a key from the body into the right name"""39 example_response["save"] = {"json": {"test_code": "code"}}40 r = RestResponse(Mock(), "Test 1", example_response, includes)41 saved = r.maybe_get_save_values_from_save_block(42 "json", example_response["json"]43 )44 assert saved == {"test_code": example_response["json"]["code"]}45 def test_save_body_nested(self, example_response, includes):46 """Save a key from the body into the right name"""47 example_response["json"]["nested"] = {"subthing": "blah"}48 example_response["save"] = {"json": {"test_nested_thing": "nested.subthing"}}49 r = RestResponse(Mock(), "Test 1", example_response, includes)50 saved = r.maybe_get_save_values_from_save_block(51 "json", example_response["json"]52 )53 assert saved == {54 "test_nested_thing": example_response["json"]["nested"]["subthing"]55 }56 def test_save_body_nested_list(self, example_response, includes):57 """Save a key from the body into the right name"""58 example_response["json"]["nested"] = {"subthing": ["abc", "def"]}59 example_response["save"] = {"json": {"test_nested_thing": "nested.subthing[0]"}}60 r = RestResponse(Mock(), "Test 1", example_response, includes)61 saved = r.maybe_get_save_values_from_save_block(62 "json", example_response["json"]63 )64 assert saved == {65 "test_nested_thing": example_response["json"]["nested"]["subthing"][0]66 }67 def test_save_header(self, example_response, includes):68 """Save a key from the headers into the right name"""69 example_response["save"] = {"headers": {"next_location": "location"}}70 r = RestResponse(Mock(), "Test 1", example_response, includes)71 saved = r.maybe_get_save_values_from_save_block(72 "headers", example_response["headers"]73 )74 assert saved == {"next_location": example_response["headers"]["location"]}75 def test_save_redirect_query_param(self, example_response, includes):76 """Save a key from the query parameters of the redirect location"""77 example_response["save"] = {"redirect_query_params": {"test_search": "search"}}78 r = RestResponse(Mock(), "Test 1", example_response, includes)79 saved = r.maybe_get_save_values_from_save_block(80 "redirect_query_params", {"search": "breadsticks"}81 )82 assert saved == {"test_search": "breadsticks"}83 @pytest.mark.parametrize("save_from", ("json", "headers", "redirect_query_params"))84 def test_bad_save(self, save_from, example_response, includes):85 example_response["save"] = {save_from: {"abc": "123"}}86 r = RestResponse(Mock(), "Test 1", example_response, includes)87 saved = r.maybe_get_save_values_from_save_block(save_from, {})88 assert not saved89 assert r.errors90class TestValidate:91 def test_simple_validate_body(self, example_response, includes):92 """Make sure a simple value comparison works"""93 r = RestResponse(Mock(), "Test 1", example_response, includes)94 r._validate_block("json", example_response["json"])95 assert not r.errors96 def test_validate_list_body(self, example_response, includes):97 """Make sure a list response can be validated"""98 example_response["json"] = ["a", 1, "b"]99 r = RestResponse(Mock(), "Test 1", example_response, includes)100 r._validate_block("json", example_response["json"])101 assert not r.errors...

Full Screen

Full Screen

response.py

Source:response.py Github

copy

Full Screen

...141 )142 self._maybe_run_validate_functions(response)143 # Get any keys to save144 saved = {}145 saved.update(self.maybe_get_save_values_from_save_block("json", body))146 saved.update(147 self.maybe_get_save_values_from_save_block("headers", response.headers)148 )149 saved.update(150 self.maybe_get_save_values_from_save_block(151 "redirect_query_params", redirect_query_params152 )153 )154 saved.update(self.maybe_get_save_values_from_ext(response, self.expected))155 # Check cookies156 for cookie in self.expected.get("cookies", []):157 if cookie not in response.cookies:158 self._adderr("No cookie named '%s' in response", cookie)159 if self.errors:160 raise exceptions.TestFailError(161 "Test '{:s}' failed:\n{:s}".format(self.name, self._str_errors()),162 failures=self.errors,163 )164 return saved...

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