示例#1
0
def get_result():
  """Get the result for the crash stats page."""
  params = dict(request.iterparams())
  params['type'] = params.get('type', 'regression')
  page = helpers.cast(request.get('page') or 1, int, "'page' is not an int.")

  is_revision_empty = 'revision' not in params

  query = big_query_query.Query()
  crash_access.add_scope(query, params, 'security_flag', 'job_type',
                         'fuzzer_name')

  if is_revision_empty:
    total_count = 0
    rows = []
  else:
    filters.add(query, params, FILTERS)
    rows, total_count = get(
        params=params,
        query=query,
        offset=(page - 1) * PAGE_SIZE,
        limit=PAGE_SIZE)
    helpers.log('Regression', helpers.VIEW_OPERATION)

  result = {
      'totalPages': (total_count // PAGE_SIZE) + 1,
      'page': page,
      'pageSize': PAGE_SIZE,
      'items': rows,
      'totalCount': total_count,
      'isRevisionEmpty': is_revision_empty
  }
  return result, params
示例#2
0
    def test_multiple_fields(self):
        """Test add multiple filters."""
        self.params['string_param'] = 'value'
        self.params['int_param'] = '123'
        self.params['bool_param'] = 'yes'

        filters.add(self.query, self.params, self.filters)

        self.query.assert_has_calls([
            mock.call.filter('string_field', 'value'),
            mock.call.filter('int_field', 123),
            mock.call.filter('bool_field', True),
        ])
示例#3
0
def add_filters(query, params):
    """Add filters based on params."""
    if not filters.has_params(params, FILTERS) and not params.get('showall'):
        params['open'] = 'yes'

    query.filter('status', 'Processed')
    query.filter('is_a_duplicate_flag', False)

    # For queries that use inequality we need to order by that field. Otherwise,
    # use the timestamp.
    if 'revision_greater_than' in params:
        query.order('crash_revision', is_desc=True)
    else:
        query.order('timestamp', is_desc=True)

    filters.add(query, params, FILTERS)
示例#4
0
def get_result():
  """Get the result for the crash stats page."""
  params = dict(request.iterparams())
  page = helpers.cast(request.get('page') or 1, int, "'page' is not an int.")
  group_by = params.get('group', 'platform')
  params['group'] = group_by
  sort_by = params.get('sort', 'total_count')
  params['sort'] = sort_by
  params['number'] = params.get('number', 'count')

  # Conditions for individual records.
  query = crash_stats.Query()
  query.group_by = group_by
  query.sort_by = sort_by
  crash_access.add_scope(query, params, 'security_flag', 'job_type',
                         'fuzzer_name')
  filters.add(query, params, FILTERS)

  # Conditions after grouping.
  group_query = crash_stats.Query()
  filters.add(group_query, params, GROUP_FILTERS)

  try:
    total_count, rows = crash_stats.get(
        query=query,
        group_query=group_query,
        offset=(page - 1) * PAGE_SIZE,
        limit=PAGE_SIZE)
  except ValueError:
    raise helpers.EarlyExitException('Invalid filters', 400)

  attach_testcases(rows)

  helpers.log('CrashStats', helpers.VIEW_OPERATION)

  result = {
      'totalPages': (total_count // PAGE_SIZE) + 1,
      'page': page,
      'pageSize': PAGE_SIZE,
      'items': rows,
      'totalCount': total_count
  }
  return result, params
示例#5
0
文件: jobs.py 项目: phwd/clusterfuzz
def get_results(this):
    """Get results for the jobs page."""

    # Return jobs sorted alphabetically by name
    query = datastore_query.Query(data_types.Job)
    query.order('name', is_desc=False)
    params = dict(this.request.iterparams())
    filters.add(query, params, FILTERS)

    page = helpers.cast(
        this.request.get('page') or 1, int, "'page' is not an int.")
    items, total_pages, total_items, has_more = query.fetch_page(
        page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT)

    result = {
        'hasMore': has_more,
        'items': [_job_to_dict(item) for item in items],
        'page': page,
        'pageSize': PAGE_SIZE,
        'totalItems': total_items,
        'totalPages': total_pages,
    }
    return result, params
示例#6
0
def get_results():
    """Get results for the bots page."""
    # Return bots sorted alphabetically by bot_name
    query = datastore_query.Query(data_types.Heartbeat)
    query.order('bot_name', is_desc=False)
    params = dict(request.iterparams())
    filters.add(query, params, FILTERS)

    page = helpers.cast(request.get('page', 1), int, "'page' is not an int.")
    items, total_pages, total_items, has_more = query.fetch_page(
        page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT)
    items = _convert_heartbeats_to_dicts(items)
    helpers.log('Bots', helpers.VIEW_OPERATION)

    result = {
        'hasMore': has_more,
        'items': items,
        'page': page,
        'pageSize': PAGE_SIZE,
        'totalItems': total_items,
        'totalPages': total_pages,
    }
    return result, params
示例#7
0
 def test_no_field(self):
     """Test no field."""
     filters.add(self.query, self.params, self.filters)
     self.query.filter.assert_has_calls([])