def Check(self, method, url, payload=None, replace=None):
    """Records output of a given url accessed with a given method.

    Args:
      method: HTTP method. May be "GET" or "POST".
      url: String repesenting an url.
      payload: JSON-able payload that will be sent when "POST" method is used.
      replace: Dictionary of key->value pairs. In the recorded JSON output
               every "key" string will be replaced with its "value"
               counterpart. This way we can properly handle dynamically
               generated values (like hunts IDs) in the regression data.
    Raises:
      ValueError: if unsupported method argument is passed. Currently only
                  "GET" and "POST" are supported.
    """
    parsed_url = urlparse.urlparse(url)
    request = utils.DataObject(method=method,
                               scheme="http",
                               path=parsed_url.path,
                               environ={"SERVER_NAME": "foo.bar",
                                        "SERVER_PORT": 1234},
                               user="test")
    request.META = {
        "CONTENT_TYPE": "application/json"
    }

    if method == "GET":
      request.GET = dict(urlparse.parse_qsl(parsed_url.query))
    elif method == "POST":
      request.body = json.dumps(payload or "")
    else:
      raise ValueError(method % "Unsupported method: %s.")

    with self.NoAuthorizationChecks():
      http_response = http_api.RenderHttpResponse(request)

    content = http_response.content

    xssi_token = ")]}'\n"
    if content.startswith(xssi_token):
      content = content[len(xssi_token):]

    # replace the values of all tracebacks by <traceback content>
    regex = re.compile(r'"traceBack": "Traceback[^"\\]*(?:\\.[^"\\]*)*"',
                       re.DOTALL)
    content = regex.sub('"traceBack": "<traceback content>"', content)

    if replace:
      if hasattr(replace, "__call__"):
        replace = replace()

      for substr, repl in replace.items():
        if hasattr(substr, "sub"):  # regex
          content = substr.sub(repl, content)
          url = substr.sub(repl, url)
        else:
          content = content.replace(substr, repl)
          url = url.replace(substr, repl)

    parsed_content = json.loads(content)
    check_result = dict(method=method, url=url,
                        test_class=self.__class__.__name__,
                        response=parsed_content)

    if payload:
      check_result["request_payload"] = payload

    stripped_content = http_api.HttpRequestHandler.StripTypeInfo(parsed_content)
    if parsed_content != stripped_content:
      check_result["type_stripped_response"] = stripped_content

    self.checks.append(check_result)
dataset/ETHPy150Open google/grr/grr/gui/api_test_lib.py/ApiCallHandlerRegressionTest.Check/swapped operands of `%`