def test_content_location_200_positive(mock_case, mock_response): mock_response.status_code = 200 mock_case.endpoint.method = "patch" # no content-location header, should raise an error with pytest.raises(AssertionError, match="For successful PUT or PATCH response"): rules.content_location(mock_response, mock_case)
def test_content_location_201_positive(mock_case, mock_response): mock_response.status_code = 201 # no content-location header, should raise an error with pytest.raises( AssertionError, match="For 201 response, should provide Content-Location"): rules.content_location(mock_response, mock_case)
def test_content_location_201_negative(mock_case, mock_response): mock_response.status_code = 201 mock_response.headers[ "Content-Location"] = "http://fakeapi.com/created_resource" mock_response.headers["Location"] = "http://fakeapi.com/created_resource" # content-location header given and matches Location header rules.content_location(mock_response, mock_case)
def test_content_location_201_positive_1(mock_case, mock_response): mock_response.status_code = 201 mock_response.headers[ "Content-Location"] = "http://fakeapi.com/created_resource" # content-location header given but no Location header in response with pytest.raises(AssertionError, match="Content-Location header should match"): rules.content_location(mock_response, mock_case)
def test_content_location_200_negative_1(mock_case, mock_response): mock_response.status_code = 200 mock_response.headers["Content-Location"] = "/path1" mock_case.endpoint.method = "put" mock_case.endpoint.path = "/path1" mock_case.endpoint.base_url = "http://localhost" # content-location header given and matches the relative path rules.content_location(mock_response, mock_case)
def test_content_location_202_positive(mock_case, mock_response): mock_response.status_code = 202 mock_response.headers["Mock-Header"] = "mock/value" mock_case.endpoint.method = "delete" # content-location header not provided with pytest.raises( AssertionError, match="For 202 response from a DELETE, PATCH, POST, or PUT"): rules.content_location(mock_response, mock_case)
def test_content_location_200_positive_1(mock_case, mock_response): mock_response.status_code = 200 mock_response.headers["Content-Location"] = "/wrong/relative/path" mock_case.endpoint.method = "patch" mock_case.endpoint.path = "/path1" mock_case.endpoint.base_url = "http://localhost" # content-location header given but does not match request uri with pytest.raises( AssertionError, match="Content-Location header should match the request URI"): rules.content_location(mock_response, mock_case)
def test_content_location_202_negative(mock_case, mock_response): mock_response.status_code = 202 mock_response.headers["Content-Location"] = "mock/value" mock_case.endpoint.method = "post" # content-location header provided rules.content_location(mock_response, mock_case)
def test_content_location_201_negative_1(mock_case, mock_response): mock_response.status_code = 200 mock_case.endpoint.method = "get" # check does not apply to 200 response from a GET rules.content_location(mock_response, mock_case)