예제 #1
0
def AddTestsToSuite(suite_key_str, test_info_list):
    """Adds tests to a suite."""
    if not suite_key_str:
        raise MissingSuiteError('There is no suite defined.')
    suite_key = db.Key(suite_key_str)
    if not test_info_list:
        return
    map_list = []
    # Deals with a potentially very large list.
    while True:
        if len(map_list) == DEFAULT_PUT_DELETE_MAX:
            db.put(map_list)
            map_list = []
        if len(test_info_list) >= DEFAULT_TEST_ID_LIST_LENGTH:
            map_list.append(
                SuiteTestsMap(
                    suite=suite_key,
                    test_info_list_str=basic_util.DumpJsonStr(
                        test_info_list[:DEFAULT_TEST_ID_LIST_LENGTH])))
            del test_info_list[:DEFAULT_TEST_ID_LIST_LENGTH]
        else:
            if test_info_list:
                map_list.append(
                    SuiteTestsMap(suite=suite_key,
                                  test_info_list_str=basic_util.DumpJsonStr(
                                      test_info_list)))
            break
    if map_list:
        db.put(map_list)
예제 #2
0
 def post(self):
   """Loads a run template."""
   run_key_str = self.GetOptionalParameter('runKey', '')
   run_template_key_str = self.GetOptionalParameter('runTemplateKey', '')
   if run_key_str:
     run = bite_run.GetModel(run_key_str)
     run_template = run.run_template
   else:
     run_template = bite_run.GetTemplateEntity(run_template_key_str)
   if run_template:
     self.response.out.write(
         basic_util.DumpJsonStr(
             {'suiteKey': str(run_template.suite.key()),
              'runKey': run_key_str,
              'runTemplateKey': str(run_template.key()),
              'runName': run_template.name,
              'runDesc': run_template.description,
              'filteredLabels': run_template.filtered_labels,
              'dimensionLabels': run_template.test_dimension_labels,
              'runTokens': run_template.tokens,
              'runRecurMethod': not run_template.run_once,
              'interval': bite_suite.ParseWatchdogSetting(
                  run_template.watchdog_setting),
              'runStartUrl': run_template.start_url}))
   else:
     error_log = 'No specified run template is available.'
     logging.error(error_log)
     self.response.out.write(error_log)
예제 #3
0
 def post(self):
   """Shows the Bite suites info."""
   project_name = self.GetOptionalParameter('projectName', '')
   data = bite_event.GetEventsData(common_util.GetEventData,
                                   project_name)
   self.response.out.write(
       basic_util.DumpJsonStr({'details': data}))
예제 #4
0
  def post(self):
    """Shows the requested runs."""
    suite_key_str = self.GetOptionalParameter('suiteKey')
    suite_name = self.GetOptionalParameter('suiteName')
    project_name = self.GetOptionalParameter('projectName')
    run_filter = self.GetOptionalParameter('filter', 'all')

    if not suite_key_str:
      suite_key_str = str(bite_suite.LoadSuite(suite_name, project_name).key())

    runs = []
    if (run_filter == 'running' or
        run_filter == 'queued' or
        run_filter == 'completed'):
      runs = bite_run.GetRunsOfSuite(suite_key_str, True, status=run_filter,
                                     max_num=DEFAULT_RUNS_NUMBER_PER_PAGE)
    elif run_filter.startswith('day'):
      days = int(run_filter[3:])
      logging.info('Start from the past : ' + str(days))
      runs = bite_run.GetRunsOfSuite(suite_key_str, True, past_days=days,
                                     max_num=DEFAULT_RUNS_NUMBER_PER_PAGE)
    elif run_filter == 'all':
      runs = bite_run.GetRunsOfSuite(suite_key_str, True,
                                     max_num=DEFAULT_RUNS_NUMBER_PER_PAGE)
    self.response.out.write(basic_util.DumpJsonStr(
        {'runs': bite_run.GetRunsData(runs)}))
예제 #5
0
def GetSuiteWatchdogStr(watchdog_setting, interval):
    """Creates a watchdog setting string to save."""
    if not watchdog_setting:
        watchdog_setting = {}
    if interval:
        watchdog_setting['every'] = interval
    return basic_util.DumpJsonStr(watchdog_setting)
예제 #6
0
  def post(self):
    """Returns to client the run's results summary."""
    run_key_str = self.GetRequiredParameter('runKey')
    run = bite_run.GetModel(run_key_str)
    completed_numbers = bite_run.GetTestsNumberOfStatus(run_key_str)
    passed_num = completed_numbers['passed']
    failed_num = completed_numbers['failed']
    run_start_time = run.start_time
    run_lead = ''
    if run.created_by:
      run_lead = run.created_by.email()
    data = {}
    self.AddRunSummary(data, passed_num, failed_num,
                       run_start_time, run_lead, run)
    details = {
        'startTimeStr': data['start_time_str'],
        'elapsedTimeStr': data['elapsed_time_str'],
        'numOfTesters': '',
        'resultsLabels': run.labels,
        'passedNum': data['passed_num'],
        'failedNum': data['failed_num'],
        'uncompletedNum': data['uncompleted_num'],
        'summaryRows': [
            {'type': 'All',
             'pass': data['passed_str'],
             'fail': data['failed_str'],
             'notRun': data['uncompleted_str'],
             'total': run.tests_number}
        ],

    }
    self.response.out.write(
        basic_util.DumpJsonStr({'data': details}))
예제 #7
0
 def post(self):
     """Loads the projects."""
     user = users.get_current_user()
     if not user:
         self.redirect(users.create_login_url(self.request.uri))
     source = self.GetRequiredParameter('source')
     project_info_list = []
     self.response.out.write(basic_util.DumpJsonStr(project_info_list))
예제 #8
0
 def post(self):
   suite_key_str = self.GetRequiredParameter('suiteKey')
   runs = bite_run.GetRunsOfSuite(suite_key_str)
   runs_info = [
       {'name': run.name, 'key': str(run.key())}
       for run in runs]
   self.response.out.write(
       basic_util.DumpJsonStr({'runs': runs_info}))
예제 #9
0
 def post(self):
   project_name = self.GetRequiredParameter('projectName')
   suites = bite_suite.LoadAllSuitesOfProject(project_name)
   suite_info = [
       {'name': suite.name, 'key': str(suite.key())}
       for suite in suites]
   self.response.out.write(
       basic_util.DumpJsonStr({'suites': suite_info}))
예제 #10
0
def GetSuiteConfigStr(configs, tokens, start_url=''):
    """Creates a suite config str."""
    if not configs:
        configs = {}
    if isinstance(configs, str):
        configs = basic_util.ParseJsonStr(configs)['configs']
    configs['tokens'] = tokens
    configs['start_url'] = start_url
    return basic_util.DumpJsonStr({'configs': configs})
예제 #11
0
def GetSuiteReportStr(report, email_from, email_to, failure_thresh):
    """Creates a suite report str."""
    if not report:
        report = {}
    if isinstance(report, str):
        report = basic_util.ParseJsonStr(report)['report']
    report['email_from'] = email_from
    report['email_to'] = email_to
    report['failure_thresh'] = failure_thresh
    return basic_util.DumpJsonStr({'report': report})
예제 #12
0
 def post(self):
   """Returns the run's detailed results."""
   run_key_str = self.GetRequiredParameter('runKey')
   results = bite_result.GetResultsOfRun(run_key_str, 9999)
   data = {}
   data['results'] = self.AddRunDetails(results)
   details = {
       'numOfTests': len(data['results']),
       'resultRows': data['results']
   }
   self.response.out.write(
       basic_util.DumpJsonStr({'data': details}))
예제 #13
0
    def post(self):
        """Fetches tests from tests deposit."""
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))
        source = self.GetRequiredParameter('source')
        project = self.GetOptionalParameter('project', '')
        project_id = self.GetOptionalParameter('projectId', '')
        labels_str = self.GetOptionalParameter('labels', '')
        test_info_list = []

        self.response.out.write(
            basic_util.DumpJsonStr({'tests': test_info_list}))
예제 #14
0
 def post(self):
   """Shows the Bite runs info."""
   run_filter = self.GetOptionalParameter('filter', 'all')
   project_name = self.GetOptionalParameter('projectName', '')
   if run_filter == 'scheduled':
     data = self._GetScheduledRunsData(project_name)
   else:
     runs, templates = bite_run.GetLatestRunsThroughTemplate(
         run_filter, project_name)
     data = bite_run.GetRunsData(runs)
     data.extend(bite_run.GetEmptyTemplateData(templates))
   self.response.out.write(
       basic_util.DumpJsonStr({'details': data}))
예제 #15
0
  def _dumpLabels(self, labels):
    """Dumps the label string.

    The label string in Json format should be:
    {'labels': ['label1', 'label2', ...]}

    Args:
      labels: A list of labels of a suite.

    Returns:
      A Json string of suite labels list.
    """
    if not labels or not isinstance(labels, list):
      labels = []
    return basic_util.DumpJsonStr({'labels': labels})
예제 #16
0
 def post(self):
     """Fetches a random result matching criteria."""
     tokens = self.GetOptionalParameter('tokens', '')
     run = bite_run.GetSpecifiedRun(tokens)
     job = {}
     result = {}
     if run:
         job = bite_result.GetRandomQueuedJob(run)
     if job:
         result = {
             'result': {
                 'id': job.key().id(),
                 'testId': job.test_id,
                 'parent': str(job.parent().key())
             }
         }
     self.response.out.write(basic_util.DumpJsonStr(result))
예제 #17
0
 def post(self):
   """Starts a run and kicks off the tests."""
   run_key_str = self.GetRequiredParameter('runKey')
   run = bite_run.GetModel(run_key_str)
   results_num = self.GetOptionalIntParameter('resultsNum', 5)
   completed_numbers = bite_run.GetTestsNumberOfStatus(run_key_str)
   passed_num = completed_numbers['passed']
   failed_num = completed_numbers['failed']
   run_start_time = run.start_time
   run_lead = ''
   if run.created_by:
     run_lead = run.created_by.email()
   results = bite_result.GetResultsOfRun(run_key_str, results_num)
   details = {}
   self.AddRunSummary(details, passed_num, failed_num,
                      run_start_time, run_lead, run)
   details['results'] = self.AddRunDetails(results)
   self.response.out.write(
       basic_util.DumpJsonStr({'details': details}))
예제 #18
0
 def post(self):
   """Loads a specified suite."""
   suite_name = self.GetOptionalParameter('suiteName', '')
   project_name = self.GetOptionalParameter('projectName', '')
   suite_key_str = self.GetOptionalParameter('suiteKey', '')
   suite = bite_suite.LoadSuite(suite_name, project_name, suite_key_str)
   if suite:
     labels = self._dumpLabels(suite.labels)
     version_url = suite.latest_version_url
     if version_url is None:
       version_url = ''
     self.response.out.write(
         basic_util.DumpJsonStr(
             {'suiteName': suite.name,
              'suiteKey': str(suite.key()),
              'description': suite.description,
              'projectName': suite.parent().name,
              'labels': labels,
              'token': bite_suite.GetSuiteTokens(suite),
              'startUrl': bite_suite.GetStartUrl(suite),
              'interval': bite_suite.ParseWatchdogSetting(
                  suite.watchdog_setting),
              'versionUrl': version_url,
              'emailFrom': bite_suite.GetSuiteAttribute(
                  suite, 'report_setting', 'email_from'),
              'emailTo': bite_suite.GetSuiteAttribute(
                  suite, 'report_setting', 'email_to'),
              'failureThresh': bite_suite.GetSuiteAttribute(
                  suite, 'report_setting', 'failure_thresh'),
              'testSource': suite.test_source,
              'retryTimes': suite.retry_times,
              'defaultTimeout': suite.default_timeout,
              'deleteDeadline': suite.auto_delete_deadline,
              'reminder': suite.reminder_setting}))
   else:
     error_log = 'No specified suite is available.'
     logging.error(error_log)
     self.response.out.write(error_log)
예제 #19
0
 def post(self):
   """Shows the Bite suites info."""
   project_name = self.GetOptionalParameter('projectName', '')
   data = self._GetSuitesData(project_name)
   self.response.out.write(
       basic_util.DumpJsonStr({'details': data}))
예제 #20
0
 def post(self):
     """Updates the result."""
     resultKeyStr = self.GetRequiredParameter('resultKey')
     result = bite_result.LoadResultByKeyStr(resultKeyStr)
     params = {'screenshot': str(result.screenshot), 'log': str(result.log)}
     self.response.out.write(basic_util.DumpJsonStr(params))