예제 #1
0
 def post(self, fullname):
   conf = config.get_config()
   obj = logic.get_requested_object(fullname, conf)
   if isinstance(obj, logic.BadTest):
     if obj.exists:
       self.render_error('Error loading test object %s: \n%s' %
                         (fullname, obj.load_errors[0][1]), 500)
     else:
       self.render_error('Test object %s does not exist.' % fullname, 404)
     return
   conf = config.get_config()
   try:
     batch = runner.start_batch(fullname, conf)
   except DeadlineExceededError:
     self.render_error('Tests took too long to run.  Consider setting the '
                       '"storage" option in aeta.yaml to something other '
                       'than "immediate", such as "memcache".', 500)
     return
   if conf.storage == 'immediate':
     tasks = batch.get_tasks(conf)
     data = {'batch_info': batch.get_json(),
             'results': [task.get_json() for task in tasks]
            }
   else:
     data = {'batch_id': str(batch.key.id())}
   self.response.out.write(json.dumps(data))
예제 #2
0
  def _user_has_permission(self, environ):
    """Determines if the current user has permission to access aeta tests.

    Args:
      environ: A dictionary of WSGI environment variables.

    Returns:
      A boolean, True iff the user has permission to access aeta.  The user has
      permission iff any of these is true:
      - this is a development server
      - the "user" is the task queue running a task
      - "protected: false" in aeta.yaml
      - the user is an admin or in permitted_emails in aeta.yaml
    """
    if environ.get('SERVER_SOFTWARE', '').startswith('Dev'):
      # Development server.
      return True
    if environ.get('HTTP_X_APPENGINE_TASKNAME'):
      # This variable is set when we are in the task queue.
      return True
    conf = config.get_config()
    if not conf.protected:
      return True
    if users.is_current_user_admin():
      return True
    user = users.get_current_user()
    if user and user.email() in conf.permitted_emails:
      return True
    return False
예제 #3
0
 def get(self, fullname):
   conf = config.get_config()
   load_errors = []
   test = logic.get_requested_object(fullname, conf)
   methods = test.get_methods(conf, load_errors)
   data = {'method_names': [method.fullname for method in methods],
           'load_errors': load_errors}
   self.response.out.write(json.dumps(data))
예제 #4
0
 def get_batch(self, batch_id):
   batch = ndb.Key(models.TestBatch, batch_id).get()
   if not batch:
     msg = 'No batch with id %s found.' % batch_id
     if config.get_config().storage == 'memcache':
       msg += ('\nThis could be due to memcache failing.  ' +
               _MEMCACHE_FAILURE_MESSAGE)
     self.render_error(msg, 404)
   return batch
예제 #5
0
def get_url_mapping():
  conf = config.get_config()
  url_mapping = [(conf.url_path_static + '(.*)',
                  handlers.StaticFileRequestHandler),
                 ]
  url_mapping.extend(rest.get_handler_mapping(conf.url_path_rest))
  url_mapping.append((conf.url_path_deferred, task_deferred.DeferredHandler))
  # config attributes dynamically assigned - pylint:disable-msg=E1101
  url_mapping.append((conf.url_path + '(.*)', handlers.DefaultRequestHandler))
  return url_mapping
예제 #6
0
def defer_multi(calls, queue=_DEFAULT_QUEUE):
  """Defers multiple function calls.

  Args:
    calls: A list of DeferredCall objects.
    queue: The queue to run the tasks in.
  """
  url = config.get_config().url_path_deferred
  # Go in batches of MAX_TASKS_PER_ADD to avoid the limit.
  for batch_i in range(0, len(calls), taskqueue.MAX_TASKS_PER_ADD):
    tasks = []
    for call in calls[batch_i : batch_i + taskqueue.MAX_TASKS_PER_ADD]:
      tasks.append(taskqueue.Task(url=url, countdown=call.countdown,
                                  payload=pickle.dumps(call)))
    taskqueue.Queue(queue).add(tasks)
예제 #7
0
 def get(self, fullname):
   """Default view."""
   conf = config.get_config()
   obj = logic.get_requested_object(fullname, conf)
   if isinstance(obj, logic.BadTest):
     if obj.exists:
       self.render_error('Error loading test object %s: \n%s' %
                         (fullname, obj.load_errors[0][1]), 500)
     else:
       self.render_error('Test object %s does not exist.' % fullname, 404)
     return
   # urllib.quote is necessary for things embedded in <script> tags to avoid
   # things like quotes and </script> in the string literals.
   values = {'root_name': urllib.quote(fullname),
             'rest_path': urllib.quote(conf.url_path_rest),
             'static_path': conf.url_path_static,
            }
   self.render_page(_get_template_path('index.html'), values)