How to use the tavern._plugins.rest.response.RestResponse function in tavern

To help you get started, we’ve selected a few tavern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
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"}
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_status_code_warns(example_response, includes):
    """Should continue if the status code is nonexistent
    """
    example_response["status_code"] = 231234

    with patch("tavern._plugins.rest.response.logger.warning") as wmock:
        RestResponse(Mock(), "Test 1", example_response, includes)

    assert wmock.called
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_validate_single_value_response(self, example_response, includes, value):
        """Check validating single value response (string, int, etc)."""
        del example_response["body"]

        r = RestResponse(Mock(), "Test 1", example_response, includes)

        class FakeResponse:
            headers = example_response["headers"]
            content = "test".encode("utf8")

            def json(self):
                return value

            status_code = example_response["status_code"]

        r.verify(FakeResponse())
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_validate_and_save(self, example_response, includes):
        """Test full verification + return saved values
        """
        example_response["save"] = {"body": {"test_code": "code"}}
        r = RestResponse(Mock(), "Test 1", example_response, includes)

        class FakeResponse:
            headers = example_response["headers"]
            content = "test".encode("utf8")

            def json(self):
                return example_response["body"]

            status_code = example_response["status_code"]

        saved = r.verify(FakeResponse())

        assert saved == {"test_code": example_response["body"]["code"]}
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
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"]}
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
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"]}
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_validate_nested_anything(self, example_response, includes):
        """Check that nested 'anything' comparisons work

        This is a bit hacky because we're directly checking the ANYTHING
        comparison - need to add an integration test too
        """

        example_response["body"] = {"nested": {"subthing": ANYTHING}}

        expected = {"nested": {"subthing": "blah"}}

        r = RestResponse(Mock(), "Test 1", example_response, includes)

        r._validate_block("body", expected)

        assert not r.errors
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_saved_value_in_validate(self, nested_response, nested_schema, includes):
        r = RestResponse(Mock(), "Test 1", nested_schema, includes)

        class FakeResponse:
            headers = nested_response["headers"]
            content = "test".encode("utf8")

            def json(self):
                return nested_response["body"]

            status_code = nested_response["status_code"]

        r.verify(FakeResponse())
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_simple_validate_redirect_query_params(self, example_response, includes):
        """Make sure a simple value comparison works
        """

        r = RestResponse(Mock(), "Test 1", example_response, includes)

        r._validate_block("redirect_query_params", {"search": "breadsticks"})

        assert not r.errors
github taverntesting / tavern / tests / unit / response / test_rest.py View on Github external
def test_validate_multiple_status_codes_passes(self, example_response, includes):
        """Check it can match mutliple status codes"""

        example_response["status_code"] = [100, 200, 300]

        r = RestResponse(Mock(), "Test 1", example_response, includes)

        r._check_status_code(100, {})

        assert not r.errors