Пример #1
0
 def testConvertPhases(self):
   """We can convert Phases."""
   phases = [
       tracker_pb2.Phase(name="JustAPhase", rank=1),
       tracker_pb2.Phase(name="Can'tPhaseMe", rank=4),
       tracker_pb2.Phase(phase_id=11, rank=5),
       tracker_pb2.Phase(rank=3),
       tracker_pb2.Phase(name="Phase"),
   ]
   expected = [
       api_pb2_v1.Phase(phaseName="JustAPhase", rank=1),
       api_pb2_v1.Phase(phaseName="Can'tPhaseMe", rank=4),
       api_pb2_v1.Phase(phaseName="Phase"),
   ]
   actual = api_pb2_v1_helpers.convert_phases(phases)
   self.assertEqual(actual, expected)
Пример #2
0
def convert_phases(phases):
    """Convert an Issue's Monorail Phase PBs to API Phase."""
    converted_phases = []
    for idx, phase in enumerate(phases):
        if not phase.name:
            try:
                logging.warning('Phase %d has no name, skipping conversion.' %
                                phase.phase_id)
            except TypeError:
                logging.warning(
                    'Phase #%d (%s) has no name or id, skipping conversion.' %
                    (idx, phase))
            continue
        converted = api_pb2_v1.Phase(phaseName=phase.name, rank=phase.rank)
        converted_phases.append(converted)
    return converted_phases
Пример #3
0
  def testConvertIssue(self):
    """Convert an internal Issue PB to an IssueWrapper API PB."""
    self.services.project.TestAddProject(
        'test-project', owner_ids=[2], project_id=12345)
    self.services.user.TestAddUser('*****@*****.**', 111)

    mar = mock.Mock()
    mar.cnxn = None
    mar.project_name = 'test-project'
    mar.project_id = 12345
    mar.auth.effective_ids = {111}
    mar.perms = permissions.READ_ONLY_PERMISSIONSET
    mar.profiler = profiler.Profiler()
    mar.config = tracker_bizobj.MakeDefaultProjectIssueConfig(12345)
    mar.config.field_defs = [
        tracker_bizobj.MakeFieldDef(
            1, 12345, 'EstDays', tracker_pb2.FieldTypes.INT_TYPE, None, None,
            False, False, False, None, None, None, False, None, None, None,
            None, 'doc', False, approval_id=2),
        tracker_bizobj.MakeFieldDef(
            2, 12345, 'DesignReview', tracker_pb2.FieldTypes.APPROVAL_TYPE,
            None, None, False, False, False, None, None, None, False, None,
            None, None, None, 'doc', False),
        tracker_bizobj.MakeFieldDef(
            3, 12345, 'StringField', tracker_pb2.FieldTypes.STR_TYPE, None,
            None, False, False, False, None, None, None, False, None, None,
            None, None, 'doc', False),
        tracker_bizobj.MakeFieldDef(
            4, 12345, 'DressReview', tracker_pb2.FieldTypes.APPROVAL_TYPE,
            None, None, False, False, False, None, None, None, False, None,
            None, None, None, 'doc', False),
        ]
    self.services.config.StoreConfig(mar.cnxn, mar.config)

    now = 1472067725
    now_dt = datetime.datetime.fromtimestamp(now)

    fvs = [
      tracker_bizobj.MakeFieldValue(
          1, 4, None, None, None, None, False, phase_id=4),
      tracker_bizobj.MakeFieldValue(
          3, None, 'string', None, None, None, False, phase_id=4),
      # missing phase
      tracker_bizobj.MakeFieldValue(
          3, None, u'\xe2\x9d\xa4\xef\xb8\x8f', None, None, None, False,
          phase_id=2),
    ]
    phases = [
        tracker_pb2.Phase(phase_id=3, name="JustAPhase", rank=4),
        tracker_pb2.Phase(phase_id=4, name="NotAPhase", rank=9)
        ]
    approval_values = [
        tracker_pb2.ApprovalValue(
            approval_id=2, phase_id=3, approver_ids=[111]),
        tracker_pb2.ApprovalValue(approval_id=4, approver_ids=[111])
    ]
    issue = fake.MakeTestIssue(
        12345, 1, 'one', 'New', 111, field_values=fvs,
        approval_values=approval_values, phases=phases)
    issue.opened_timestamp = now
    issue.owner_modified_timestamp = now
    issue.status_modified_timestamp = now
    issue.component_modified_timestamp = now
    # TODO(jrobbins): set up a lot more fields.

    for cls in [api_pb2_v1.IssueWrapper, api_pb2_v1.IssuesGetInsertResponse]:
      result = api_pb2_v1_helpers.convert_issue(cls, issue, mar, self.services)
      self.assertEquals(1, result.id)
      self.assertEquals('one', result.title)
      self.assertEquals('one', result.summary)
      self.assertEquals(now_dt, result.published)
      self.assertEquals(now_dt, result.owner_modified)
      self.assertEquals(now_dt, result.status_modified)
      self.assertEquals(now_dt, result.component_modified)
      self.assertEquals(
          result.fieldValues,
          [api_pb2_v1.FieldValue(
              fieldName='EstDays', fieldValue='4', approvalName='DesignReview',
              derived=False),
           api_pb2_v1.FieldValue(fieldName='StringField', fieldValue='string',
                                 phaseName="NotAPhase", derived=False),
           api_pb2_v1.FieldValue(fieldName='StringField',
                                 fieldValue=u'\xe2\x9d\xa4\xef\xb8\x8f',
                                 derived=False),
          ]
      )
      self.assertEqual(
          result.approvalValues,
          [api_pb2_v1.Approval(
            approvalName="DesignReview",
            approvers=[self.person_1],
            status=api_pb2_v1.ApprovalStatus.notSet,
            phaseName="JustAPhase",
          ),
           api_pb2_v1.Approval(
               approvalName="DressReview",
               approvers=[self.person_1],
               status=api_pb2_v1.ApprovalStatus.notSet,
           )]
      )
      self.assertEqual(
          result.phases,
          [api_pb2_v1.Phase(phaseName="JustAPhase", rank=4),
           api_pb2_v1.Phase(phaseName="NotAPhase", rank=9)
          ])