def setUp(self):
        """Sets up the test harness."""
        testutil.HandlerTestBase.setUp(self)

        for _ in range(100):
            TestKind().put()
        self.start = handlers.StartJobHandler()
        self.start.initialize(mock_webapp.MockRequest(),
                              mock_webapp.MockResponse())
        self.start.request.path = "/mapreduce/command/start"
        self.start.request.set("name", "my job 1")
        self.start.request.set("mapper_input_reader",
                               "mapreduce.input_readers.DatastoreInputReader")
        self.start.request.set("mapper_handler", "__main__.TestMap")
        self.start.request.set("mapper_params.entity_kind",
                               "__main__.TestKind")

        self.start.request.headers["X-Requested-With"] = "XMLHttpRequest"

        self.start.post()
        result = simplejson.loads(self.start.response.out.getvalue())
        self.mapreduce_id = result["mapreduce_id"]

        self.handler = status.GetJobDetailHandler()
        self.handler.initialize(mock_webapp.MockRequest(),
                                mock_webapp.MockResponse())
        self.handler.request.path = "/mapreduce/command/list"

        self.handler.request.headers["X-Requested-With"] = "XMLHttpRequest"
 def setUp(self):
     """Sets up the test harness."""
     testutil.HandlerTestBase.setUp(self)
     self.handler = status.ResourceHandler()
     self.handler.initialize(mock_webapp.MockRequest(),
                             mock_webapp.MockResponse())
     self.handler.request.path = "/mapreduce/path"
 def setUp(self):
     """Sets up the test harness."""
     testutil.HandlerTestBase.setUp(self)
     self.handler = status.ListConfigsHandler()
     self.handler.initialize(mock_webapp.MockRequest(),
                             mock_webapp.MockResponse())
     self.handler.request.path = "/mapreduce/command/path"
     self.handler.request.headers["X-Requested-With"] = "XMLHttpRequest"
Exemple #4
0
def execute_task(task, handlers_map=None):
    """Execute mapper's executor task.

  This will try to determine the correct mapper handler for the task, will set
  up all mock environment necessary for task execution, and execute the task
  itself.

  This function can be used for functional-style testing of functionality
  depending on mapper framework.
  """
    if not handlers_map:
        handlers_map = main.create_handlers_map()

    url = task["url"]
    handler = None

    for (re_str, handler_class) in handlers_map:
        re_str = "^" + re_str + "($|\\?)"
        if re.match(re_str, url):
            handler = handler_class()
            break

    if not handler:
        raise Exception("Can't determine handler for %s" % task)

    handler.initialize(mock_webapp.MockRequest(), mock_webapp.MockResponse())
    handler.request.set_url(url)

    handler.request.environ["HTTP_HOST"] = "myapp.appspot.com"
    for k, v in task.get("headers", []):
        handler.request.headers[k] = v
        environ_key = "HTTP_" + k.replace("-", "_").upper()
        handler.request.environ[environ_key] = v
    handler.request.environ["HTTP_X_APPENGINE_TASKNAME"] = (task.get(
        "name", "default_task_name"))
    handler.request.environ["HTTP_X_APPENGINE_QUEUENAME"] = (task.get(
        "queue_name", "default"))
    handler.request.environ["PATH_INFO"] = handler.request.path

    saved_os_environ = os.environ
    try:
        os.environ = dict(os.environ)
        os.environ.update(handler.request.environ)
        if task["method"] == "POST":
            for k, v in decode_task_payload(task).items():
                handler.request.set(k, v)
            handler.post()
        elif task["method"] == "GET":
            handler.get()
        else:
            raise Exception("Unsupported method: %s" % task.method)
    finally:
        os.environ = saved_os_environ

    if handler.response.status != 200:
        raise Exception("Handler failure: %s (%s). \nTask: %s\nHandler: %s" %
                        (handler.response.status,
                         handler.response.status_message, task, handler))
    def setUp(self):
        """Sets up the test harness."""
        testutil.HandlerTestBase.setUp(self)
        self.start = handlers.StartJobHandler()
        self.start.initialize(mock_webapp.MockRequest(),
                              mock_webapp.MockResponse())
        self.start.request.path = "/mapreduce/command/start"
        self.start.request.set("mapper_input_reader",
                               "mapreduce.input_readers.DatastoreInputReader")
        self.start.request.set("mapper_handler", "__main__.TestMap")
        self.start.request.set("mapper_params.entity_kind",
                               "__main__.TestKind")
        self.start.request.headers["X-Requested-With"] = "XMLHttpRequest"

        self.handler = status.ListJobsHandler()
        self.handler.initialize(mock_webapp.MockRequest(),
                                mock_webapp.MockResponse())
        self.handler.request.path = "/mapreduce/command/list"

        self.handler.request.headers["X-Requested-With"] = "XMLHttpRequest"
Exemple #6
0
  def testError(self):
    """Test that an error sets the expected response fields."""
    handler = JsonErrorHandler(Exception('bill hicks'))
    request = mock_webapp.MockRequest()
    response = mock_webapp.MockResponse()
    request.headers["X-Requested-With"] = "XMLHttpRequest"
    handler.initialize(request, response)

    handler._handle_wrapper()
    self.assertEquals("Exception", handler.json_response["error_class"])
    self.assertEquals("bill hicks",
                      handler.json_response["error_message"])
Exemple #7
0
  def testMissingYamlError(self):
    """Test that this error sets the expected response fields."""
    handler = JsonErrorHandler(errors.MissingYamlError)
    request = mock_webapp.MockRequest()
    response = mock_webapp.MockResponse()
    request.headers["X-Requested-With"] = "XMLHttpRequest"
    handler.initialize(request, response)

    handler._handle_wrapper()
    self.assertEquals("Notice", handler.json_response["error_class"])
    self.assertEquals("Could not find 'mapreduce.yaml'",
                      handler.json_response["error_message"])
 def KickOffMapreduce(self):
     """Executes pending kickoff task."""
     kickoff_task = self.taskqueue.GetTasks("default")[0]
     handler = handlers.KickOffJobHandler()
     handler.initialize(mock_webapp.MockRequest(),
                        mock_webapp.MockResponse())
     handler.request.path = "/mapreduce/kickoffjob_callback"
     handler.request.params.update(
         cgi.parse_qsl(base64.b64decode(kickoff_task["body"])))
     handler.request.headers["X-AppEngine-QueueName"] = "default"
     handler.post()
     self.taskqueue.DeleteTask("default", kickoff_task["name"])
Exemple #9
0
 def setUp(self):
   self.handler = base_handler.JsonHandler()
   self.handler.initialize(mock_webapp.MockRequest(),
                           mock_webapp.MockResponse())