Exemple #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
Exemple #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
Exemple #3
0
    def test_validate_nested_body(self, example_response, includes):
        """Make sure a nested value comparison works"""

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

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

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

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

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

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

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

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

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

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

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

        assert not r.errors
Exemple #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
Exemple #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
Exemple #8
0
    def test_validate_wrong_list_dict(self, example_response, includes):
        """We expected a list, but we got a dict in the response"""

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

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

        r._validate_block("json", bad_expected)

        assert r.errors
Exemple #9
0
    def test_validate_nested_null(self, example_response, includes):
        """Check that nested 'null' comparisons do not work"""

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

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

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

        r._validate_block("json", expected)

        assert r.errors
Exemple #10
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
Exemple #11
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(FutureWarning):
            r._validate_block("body", expected)

        assert not r.errors