示例#1
0
def test_status_code_warns(example_response, includes):
    """Should continue if the status code is nonexistent
    """
    example_response["status_code"] = 231234

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

    assert wmock.called
示例#2
0
    def test_incorrect_status_code(self, example_response, includes):
        """Test full verification + return saved values
        """
        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 = 400

        with pytest.raises(exceptions.TestFailError):
            r.verify(FakeResponse())

        assert r.errors
示例#3
0
    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"]}
示例#4
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
示例#5
0
    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]
        }
示例#6
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