old_contents: # Copyright 2016 The Chromium Authors. All rights reserved.
  # Use of this source code is governed by a BSD-style license that can be
  # found in the LICENSE file.
  
  import webapp2
  
  from dashboard.pinpoint.models import change
  from dashboard.pinpoint.models import job as job_module
  
  
  class New(webapp2.RequestHandler):
    """Handler that cooks up a fresh Pinpoint job."""
  
    def post(self):
      # TODO(dtu): Read the parameters from the request object.
      # Not doing it for now because it's easier to run tests this way.
      configuration = 'Mac Pro 10.11 Perf'
      test_suite = 'speedometer'
      test = None
      metric = None
      deps = (change.Dep('src', '2c1f8ed028edcb44c954cb2a0625a8f278933481'),
              change.Dep('src', '858ceafc7cf4f11a6549b8c1ace839a45d943d68'),)
  
      # Validate parameters.
      if metric and not test_suite:
        raise ValueError("Specified a metric but there's no test_suite to run.")
  
      # Validate commit hashes.
      for dep in deps:
        dep.Validate()
  
      # Convert parameters to canonical internal representation.
  
      # Create job.
      job = job_module.Job.New(
          configuration=configuration,
          test_suite=test_suite,
          test=test,
          metric=metric,
          auto_explore=True)
  
      # Add changes.
      for dep in deps:
        job.AddChange(change.Change(dep))
  
      # Put job into datastore.
      job_id = job.put().urlsafe()
  
      # Start job.
      job.Start()
      job.put()
  
      # Show status page.
      # TODO: Should return a JSON result instead. Use Cloud Endpoints.
      self.redirect('/job/' + job_id)
  
new_contents: # Copyright 2016 The Chromium Authors. All rights reserved.
  # Use of this source code is governed by a BSD-style license that can be
  # found in the LICENSE file.
  
  import webapp2
  
  from dashboard.pinpoint.models import change
  from dashboard.pinpoint.models import job as job_module
  
  
  class New(webapp2.RequestHandler):
    """Handler that cooks up a fresh Pinpoint job."""
  
    def post(self):
      """Start a new Pinpoint job."""
  
      # TODO(dtu): Read the parameters from the request object.
      # Not doing it for now because it's easier to run tests this way.
      configuration = 'Mac Pro 10.11 Perf'
      test_suite = 'speedometer'
      test = None
      metric = None
      auto_explore = True
  
      change_1 = {
          'base_commit': {
              'repository': 'src',
              'git_hash': '2c1f8ed028edcb44c954cb2a0625a8f278933481',
          }
      }
      change_2 = {
          'base_commit': {
              'repository': 'src',
              'git_hash': '858ceafc7cf4f11a6549b8c1ace839a45d943d68',
          }
      }
  
      # Validate parameters.
      try:
        if metric and not test_suite:
          raise ValueError("Specified a metric but there's no test_suite to run.")
        changes = (change.Change.FromDict(change_1),
                   change.Change.FromDict(change_2))
      except (KeyError, ValueError) as e:
        self.response.set_status(400)
        self.response.write(e)
        return
  
      # Convert parameters to canonical internal representation.
  
      # Create job.
      job = job_module.Job.New(
          configuration=configuration,
          test_suite=test_suite,
          test=test,
          metric=metric,
          auto_explore=auto_explore)
  
      # Add changes.
      for c in changes:
        job.AddChange(c)
  
      # Put job into datastore.
      job_id = job.put().urlsafe()
  
      # Start job.
      job.Start()
      job.put()
  
      self.response.write(job_id)
  
subject: Use Change.FromDict() in the /new handler.