Exemplo n.º 1
0
    def post(self):
        """Accepts post requests.

    Expects a test_run as a parameter and updates the associated version file to
    use the expectations associated with that test run.
    """
        test_run = self.request.get('test_run')

        # Fail if test_run parameter is missing.
        if not test_run:
            self.response.header['Content-Type'] = 'json/application'
            self.response.write(
                json.dumps(
                    {'error': '\'test_run\' must be supplied to rebaseline.'}))
            return
        # Otherwise, set up the utilities.
        bucket = gs_bucket.GoogleCloudStorageBucket(constants.BUCKET)
        chrome_util = chrome_utils.ChromeUtils(bucket)
        # Update versions file.
        try:
            chrome_util.RebaselineToTestRun(test_run)
        except:
            self.response.header['Content-Type'] = 'json/application'
            self.response.write(
                json.dumps(
                    {'error': 'Can not rebaseline to the given test run.'}))
            return
        # Redirect back to the sites list for the test run.
        self.redirect('/?test_run=%s' % test_run)
    def get(self):
        """Handles a get request to the main_view page.

    If the test_run parameter is specified, then a page displaying all of
    the failed runs in the test_run will be shown. Otherwise a view listing
    all of the test_runs available for viewing will be displayed.
    """
        test_run = self.request.get('test_run')
        bucket = gs_bucket.GoogleCloudStorageBucket(constants.BUCKET)
        ispy = ispy_utils.ISpyUtils(bucket)
        # Load the view.
        if test_run:
            self._GetForTestRun(test_run, ispy)
            return
        self._GetAllTestRuns(ispy)
Exemplo n.º 3
0
  def get(self):
    """Handles get requests to the ImageHandler.

    GET Parameters:
      file_path: A path to an image resource in Google Cloud Storage.
    """
    file_path = self.request.get('file_path')
    if not file_path:
      self.error(404)
      return
    bucket = gs_bucket.GoogleCloudStorageBucket(constants.BUCKET)
    try:
      image = bucket.DownloadFile(file_path)
    except cloud_bucket.FileNotFoundError:
      self.error(404)
    else:
      self.response.headers['Content-Type'] = 'image/png'
      self.response.out.write(image)
Exemplo n.º 4
0
    def post(self):
        """Accepts post requests.

    This method will accept a post request containing device, site and
    device_id parameters. This method takes the diff of the run
    indicated by it's parameters and adds it to the mask of the run's
    test. It will then delete the run it is applied to and redirect
    to the device list view.
    """
        test_run = self.request.get('test_run')
        expectation = self.request.get('expectation')

        # Short-circuit if a parameter is missing.
        if not (test_run and expectation):
            self.response.headers['Content-Type'] = 'json/application'
            self.response.write(
                json.dumps({
                    'error':
                    '\'test_run\' and \'expectation\' must be '
                    'supplied to update a mask.'
                }))
            return
        # Otherwise, set up the utilities.
        self.bucket = gs_bucket.GoogleCloudStorageBucket(constants.BUCKET)
        self.ispy = ispy_utils.ISpyUtils(self.bucket)
        # Short-circuit if the failure does not exist.
        if not self.ispy.FailureExists(test_run, expectation):
            self.response.headers['Content-Type'] = 'json/application'
            self.response.write(
                json.dumps({
                    'error':
                    'Could not update mask because failure does not exist.'
                }))
            return
        # Get the failure namedtuple (which also computes the diff).
        failure = self.ispy.GetFailure(test_run, expectation)
        # Upload the new mask in place of the original.
        self.ispy.UpdateImage(
            ispy_utils.GetExpectationPath(expectation, 'mask.png'),
            image_tools.ConvertDiffToMask(failure.diff))
        # Now that there is no diff for the two images, remove the failure.
        self.ispy.RemoveFailure(test_run, expectation)
        # Redirect back to the sites list for the test run.
        self.redirect('/?test_run=%s' % test_run)