示例#1
0
    def test_simple_validate_headers(self, example_response, includes):
        """Make sure a simple value comparison works
        """

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

        r._validate_block("headers", example_response["headers"])

        assert not r.errors
示例#2
0
    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
示例#3
0
    def test_validate_nested_body(self, example_response, includes):
        """Make sure a nested value comparison works
        """

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

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

        r._validate_block("body", example_response["body"])

        assert not r.errors
示例#4
0
    def test_validate_list_body_wrong_order(self, example_response, includes):
        """Order of list items matters
        """

        example_response["body"] = ["a", 1, "b"]

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

        r._validate_block("body", example_response["body"][::-1])

        assert r.errors
示例#5
0
    def test_validate_list_body(self, example_response, includes):
        """Make sure a list response can be validated
        """

        example_response["body"] = ["a", 1, "b"]

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

        r._validate_block("body", example_response["body"])

        assert not r.errors
示例#6
0
    def test_validate_wrong_dict_list(self, example_response, includes):
        """We expected a dict, but we got a list in the response"""

        example_response["body"] = {"a": "b"}
        bad_expected = ["a", "b", "c"]

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

        r._validate_block("body", bad_expected)

        assert r.errors
示例#7
0
    def test_validate_missing_list_key(self, example_response, includes):
        """If we expect 4 items and 3 were returned, catch error"""

        example_response["body"] = ["a", 1, "b", "c"]
        bad_expected = example_response["body"][:-1]

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

        r._validate_block("body", bad_expected)

        assert r.errors
示例#8
0
    def test_validate_nested_null(self, example_response, includes):
        """Check that nested 'null' comparisons work

        This will be removed in a future version
        """

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

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

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

        with pytest.warns(RuntimeWarning):
            r._validate_block("body", expected)

        assert not r.errors
示例#9
0
    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