def test_save_body(self, example_response, includes): """Save a key from the body into the right name """ example_response["save"] = {"body": {"test_code": "code"}} r = RestResponse(Mock(), "Test 1", example_response, includes) saved = r._save_value("body", example_response["body"]) assert saved == {"test_code": example_response["body"]["code"]}
def test_bad_save(self, save_from, example_response, includes): example_response["save"] = {save_from: {"abc": "123"}} r = RestResponse(Mock(), "Test 1", example_response, includes) saved = r._save_value(save_from, {}) assert not saved assert r.errors
def test_save_header(self, example_response, includes): """Save a key from the headers into the right name """ example_response["save"] = {"headers": {"next_location": "location"}} r = RestResponse(Mock(), "Test 1", example_response, includes) saved = r._save_value("headers", example_response["headers"]) assert saved == {"next_location": example_response["headers"]["location"]}
def test_save_redirect_query_param(self, example_response, includes): """Save a key from the query parameters of the redirect location """ example_response["save"] = {"redirect_query_params": {"test_search": "search"}} r = RestResponse(Mock(), "Test 1", example_response, includes) saved = r._save_value("redirect_query_params", {"search": "breadsticks"}) assert saved == {"test_search": "breadsticks"}
def test_save_body_nested_list(self, example_response, includes): """Save a key from the body into the right name """ example_response["body"]["nested"] = {"subthing": ["abc", "def"]} example_response["save"] = {"body": {"test_nested_thing": "nested.subthing.0"}} r = RestResponse(Mock(), "Test 1", example_response, includes) saved = r._save_value("body", example_response["body"]) assert saved == { "test_nested_thing": example_response["body"]["nested"]["subthing"][0] }