Beispiel #1
0
    def setUp(self):
        self.default_cols = 'a b c'
        self.builtin_cols = 'a b x y z'
        self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)

        self.art1 = fake.MakeTestIssue(
            789,
            1,
            'a summary',
            '',
            0,
            derived_owner_id=111,
            star_count=12,
            derived_labels='Priority-Medium Hot Mstone-1 Mstone-2',
            derived_status='Overdue')
        self.art2 = fake.MakeTestIssue(
            789,
            1,
            'a summary',
            'New',
            111,
            star_count=12,
            merged_into=200001,
            labels='Priority-Medium Type-DEFECT Hot Mstone-1 Mstone-2')
        self.users_by_id = {
            111: framework_views.StuffUserView(111, '*****@*****.**', True),
        }
Beispiel #2
0
 def setUp(self):
     self.issue1 = MakeTestIssue(local_id=1,
                                 issue_id=100001,
                                 summary='One',
                                 status="New")
     self.issue2 = MakeTestIssue(local_id=2,
                                 issue_id=100002,
                                 summary='Two',
                                 status="Fixed")
     self.issue3 = MakeTestIssue(local_id=3,
                                 issue_id=100003,
                                 summary='Three',
                                 status="UndefinedString")
     self.issue5 = MakeTestIssue(local_id=5,
                                 issue_id=100005,
                                 summary='FiveUnviewable',
                                 status="Fixed")
     self.table_cell_kws = {
         'col': None,
         'users_by_id': self.USERS_BY_ID,
         'non_col_labels': [],
         'label_values': {},
         'related_issues': {},
         'config': tracker_bizobj.MakeDefaultProjectIssueConfig(678),
         'viewable_iids_set': {100001, 100002, 100003}
     }
Beispiel #3
0
    def testPaginateComments_Visible(self):
        mr = testing_helpers.MakeMonorailRequest()
        config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
        issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111L)
        issuecomment_list = [tracker_pb2.IssueComment()]
        # 500 comments, none deleted.
        for _ in range(500):
            issuecomment_list.append(tracker_pb2.IssueComment())
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[1:], visible_comments)
        self.assertFalse(pagination.visible)

        # 501 comments, none deleted.
        issuecomment_list.append(tracker_pb2.IssueComment())
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[2:], visible_comments)
        self.assertTrue(pagination.visible)
        self.assertEqual(2, pagination.last)
        self.assertEqual(501, pagination.start)

        # 501 comments, 1 of them deleted.
        issuecomment_list[1].deleted_by = 123
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[2:], visible_comments)
        self.assertFalse(pagination.visible)
 def testFindFieldDef_Normal(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(field_name='EstDays')
   config.field_defs = [fd]
   self.assertEqual(fd, tracker_bizobj.FindFieldDef('EstDays', config))
   self.assertEqual(fd, tracker_bizobj.FindFieldDef('ESTDAYS', config))
   self.assertIsNone(tracker_bizobj.FindFieldDef('Unknown', config))
 def setUp(self):
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     cd1 = tracker_bizobj.MakeComponentDef(1, 789, 'BackEnd', 'doc', False,
                                           [], [111L], 0, 122L)
     cd2 = tracker_bizobj.MakeComponentDef(2, 789, 'BackEnd>DB', 'doc',
                                           True, [], [111L], 0, 122L)
     self.config.component_defs = [cd1, cd2]
Beispiel #6
0
 def testConvertFieldValues_Errors(self):
     """We don't crash on bad requests."""
     mar = mock.Mock()
     mar.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     mar.config.field_defs = [
         tracker_bizobj.MakeFieldDef(2, 789, 'EstDays',
                                     tracker_pb2.FieldTypes.INT_TYPE, None,
                                     None, False, False, False, 0, 99, None,
                                     False, None, None, None, None, 'doc',
                                     False),
     ]
     field_values = [
         api_pb2_v1.FieldValue(
             fieldName='Unknown',
             operator=api_pb2_v1.FieldValueOperator.clear),
     ]
     actual = api_pb2_v1_helpers.convert_field_values(
         field_values, mar, self.services)
     (fv_list_add, fv_list_remove, fv_list_clear, label_list_add,
      label_list_remove) = actual
     self.assertEquals([], fv_list_add)
     self.assertEquals([], fv_list_remove)
     self.assertEquals([], fv_list_clear)
     self.assertEquals([], label_list_add)
     self.assertEquals([], label_list_remove)
Beispiel #7
0
 def setUpServlet(self, servlet_factory):
     # pylint: disable=attribute-defined-outside-init
     self.services = service_manager.Services(
         project=fake.ProjectService(),
         config=fake.ConfigService(),
         user=fake.UserService(),
         issue=fake.IssueService(),
         template=Mock(spec=template_svc.TemplateService),
         features=fake.FeaturesService())
     self.servlet = servlet_factory('req', 'res', services=self.services)
     self.project = self.services.project.TestAddProject('proj',
                                                         project_id=789,
                                                         contrib_ids=[333])
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     self.services.config.StoreConfig(None, self.config)
     self.cnxn = fake.MonorailConnection()
     self.mr = testing_helpers.MakeMonorailRequest(path='/p/proj/admin',
                                                   project=self.project)
     self.mox = mox.Mox()
     self.test_template = tracker_bizobj.MakeIssueTemplate(
         'Test Template', 'sum', 'New', 111, 'content', [], [], [], [])
     self.test_template.template_id = 12345
     self.test_templates = testing_helpers.DefaultTemplates()
     self.test_templates.append(self.test_template)
     self.services.template.GetProjectTemplates\
         .return_value = self.test_templates
     self.services.template.GetTemplateSetForProject\
         .return_value = [(12345, 'Test template', 0)]
    def testPaginateComments_Visible(self):
        mr = testing_helpers.MakeMonorailRequest()
        config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
        issue = fake.MakeTestIssue(789, 1, 'summary', 'New', 111)
        issuecomment_list = [tracker_pb2.IssueComment()]
        # full page of comments, none deleted.
        for _ in range(framework_constants.DEFAULT_COMMENTS_PER_PAGE):
            issuecomment_list.append(tracker_pb2.IssueComment())
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config, self.services)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[1:], visible_comments)
        self.assertFalse(pagination.visible)

        # One comment on second page, none deleted.
        issuecomment_list.append(tracker_pb2.IssueComment())
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config, self.services)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[2:], visible_comments)
        self.assertTrue(pagination.visible)
        self.assertEqual(2, pagination.last)
        self.assertEqual(framework_constants.DEFAULT_COMMENTS_PER_PAGE + 1,
                         pagination.start)

        # One comment on second page, 1 of them deleted.
        issuecomment_list[1].deleted_by = 123
        description, visible_comments, pagination = issuepeek.PaginateComments(
            mr, issue, issuecomment_list, config, self.services)
        self.assertEqual([issuecomment_list[0]], description)
        self.assertEqual(issuecomment_list[2:], visible_comments)
        self.assertFalse(pagination.visible)
 def setUp(self):
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     self.services = service_manager.Services(user=fake.UserService())
     self.mr = testing_helpers.MakeMonorailRequest(project=fake.Project(),
                                                   services=self.services)
     self.mr.cnxn = fake.MonorailConnection()
     self.errors = template_helpers.EZTError()
 def testFindAncestorComponents_NoMatch(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI>Splash')
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=2, path='UI>AboutBox'))
   actual = tracker_bizobj.FindAncestorComponents(config, cd)
   self.assertEqual([], actual)
    def testSortIssues(self):
        services = service_manager.Services(cache_manager=fake.CacheManager())
        sorting.InitializeArtValues(services)

        mr = testing_helpers.MakeMonorailRequest(
            path='/p/proj/issues/list?q=foo')
        mr.sort_spec = 'priority'
        issue_1 = fake.MakeTestIssue(789,
                                     1,
                                     'one',
                                     'New',
                                     111L,
                                     labels=['Priority-High'])
        issue_2 = fake.MakeTestIssue(789,
                                     2,
                                     'two',
                                     'New',
                                     111L,
                                     labels=['Priority-Low'])
        issue_3 = fake.MakeTestIssue(789,
                                     3,
                                     'three',
                                     'New',
                                     111L,
                                     labels=['Priority-Medium'])
        issues = [issue_1, issue_2, issue_3]
        config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)

        sorted_issues = frontendsearchpipeline._SortIssues(
            mr, issues, config, {})

        self.assertEqual(
            [issue_1, issue_3, issue_2],  # Order is high, medium, low.
            sorted_issues)
Beispiel #12
0
 def setUp(self):
     self.cnxn = 'fake cnxn'
     self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     self.services = service_manager.Services(user=fake.UserService(),
                                              project=fake.ProjectService(),
                                              issue=fake.IssueService(),
                                              config=fake.ConfigService())
     self.services.user.TestAddUser('*****@*****.**', 111)
 def testFindComponentDefByID_NoMatch(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=1, path='UI>Splash'))
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=2, path='UI>AboutBox'))
   actual = tracker_bizobj.FindComponentDefByID(999, config)
   self.assertIsNone(actual)
  def testHarmonizeConfigs(self):
    c1 = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
    harmonized = tracker_bizobj.HarmonizeConfigs([c1])
    self.assertListEqual(
        [stat.status for stat in c1.well_known_statuses],
        [stat.status for stat in harmonized.well_known_statuses])
    self.assertListEqual(
        [lab.label for lab in c1.well_known_labels],
        [lab.label for lab in harmonized.well_known_labels])
    self.assertEqual('', harmonized.default_sort_spec)

    c2 = tracker_bizobj.MakeDefaultProjectIssueConfig(678)
    tracker_bizobj.SetConfigStatuses(c2, [
        ('Unconfirmed', '', True, False),
        ('New', '', True, True),
        ('Accepted', '', True, False),
        ('Begun', '', True, False),
        ('Fixed', '', False, False),
        ('Obsolete', '', False, False)])
    tracker_bizobj.SetConfigLabels(c2, [
        ('Pri-0', '', False),
        ('Priority-High', '', True),
        ('Pri-1', '', False),
        ('Priority-Medium', '', True),
        ('Pri-2', '', False),
        ('Priority-Low', '', True),
        ('Pri-3', '', False),
        ('Pri-4', '', False)])
    c2.default_sort_spec = 'Pri -status'

    harmonized = tracker_bizobj.HarmonizeConfigs([c1, c2])
    result_statuses = [stat.status
                       for stat in harmonized.well_known_statuses]
    result_labels = [lab.label
                     for lab in harmonized.well_known_labels]
    self.assertListEqual(
        ['Unconfirmed', 'New', 'Accepted', 'Begun', 'Started', 'Fixed',
         'Obsolete', 'Verified', 'Invalid', 'Duplicate', 'WontFix', 'Done'],
        result_statuses)
    self.assertListEqual(
        ['Pri-0', 'Type-Defect', 'Type-Enhancement', 'Type-Task',
         'Type-Other', 'Priority-Critical', 'Priority-High',
         'Pri-1', 'Priority-Medium', 'Pri-2', 'Priority-Low', 'Pri-3',
         'Pri-4'],
        result_labels[:result_labels.index('OpSys-All')])
    self.assertEqual('Pri -status', harmonized.default_sort_spec.strip())
 def testMakeFieldClearedAmendment_Normal(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(field_id=1, field_name='Rabbit')
   config.field_defs.append(fd)
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '----', [], [], 'Rabbit'),
       tracker_bizobj.MakeFieldClearedAmendment(1, config))
 def testFindComponentDefByID_MatchFound(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI>Splash')
   config.component_defs.append(cd)
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=2, path='UI>AboutBox'))
   actual = tracker_bizobj.FindComponentDefByID(1, config)
   self.assertEqual(cd, actual)
 def testFindDescendantComponents_SomeMatch(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI')
   config.component_defs.append(cd)
   cd2 = tracker_pb2.ComponentDef(component_id=2, path='UI>Splash')
   config.component_defs.append(cd2)
   actual = tracker_bizobj.FindDescendantComponents(config, cd)
   self.assertEqual([cd2], actual)
 def testUsersInvolvedInConfig_Normal(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   config.templates[0].owner_id = 111L
   config.templates[0].admin_ids = [111L, 222L]
   config.field_defs = [tracker_pb2.FieldDef(admin_ids=[333L])]
   self.assertEqual(
       {111L, 222L, 333L},
       tracker_bizobj.UsersInvolvedInConfig(config))
 def testConvertFieldValues_Normal(self):
   """The client wants to edit a custom field."""
   mar = mock.Mock()
   mar.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   mar.config.field_defs = [
       tracker_bizobj.MakeFieldDef(
           1, 789, 'Priority', tracker_pb2.FieldTypes.ENUM_TYPE, None, None,
           False, False, False, None, None, None, False, None, None, None,
           None, 'doc', False),
       tracker_bizobj.MakeFieldDef(
           2, 789, 'EstDays', tracker_pb2.FieldTypes.INT_TYPE, None, None,
           False, False, False, 0, 99, None, False, None, None, None,
           None, 'doc', False),
       tracker_bizobj.MakeFieldDef(
           3, 789, 'Nickname', tracker_pb2.FieldTypes.STR_TYPE, None, None,
           False, False, False, None, None, None, False, None, None, None,
           None, 'doc', False),
       tracker_bizobj.MakeFieldDef(
           4, 789, 'Verifier', tracker_pb2.FieldTypes.USER_TYPE, None, None,
           False, False, False, None, None, None, False, None, None, None,
           None, 'doc', False),
       tracker_bizobj.MakeFieldDef(
           5, 789, 'Deadline', tracker_pb2.FieldTypes.DATE_TYPE, None, None,
           False, False, False, None, None, None, False, None, None, None,
           None, 'doc', False),
       tracker_bizobj.MakeFieldDef(
           6, 789, 'Homepage', tracker_pb2.FieldTypes.URL_TYPE, None, None,
           False, False, False, None, None, None, False, None, None, None,
           None, 'doc', False),
       ]
   field_values = [
       api_pb2_v1.FieldValue(fieldName='Priority', fieldValue='High'),
       api_pb2_v1.FieldValue(fieldName='EstDays', fieldValue='4'),
       api_pb2_v1.FieldValue(fieldName='Nickname', fieldValue='Scout'),
       api_pb2_v1.FieldValue(
           fieldName='Verifier', fieldValue='*****@*****.**'),
       api_pb2_v1.FieldValue(fieldName='Deadline', fieldValue='2017-12-06'),
       api_pb2_v1.FieldValue(
           fieldName='Homepage', fieldValue='http://example.com'),
       ]
   actual = api_pb2_v1_helpers.convert_field_values(
       field_values, mar, self.services)
   (fv_list_add, fv_list_remove, fv_list_clear,
    label_list_add, label_list_remove) = actual
   self.assertEquals(
     [tracker_bizobj.MakeFieldValue(2, 4, None, None, None, None, False),
      tracker_bizobj.MakeFieldValue(3, None, 'Scout', None, None, None, False),
      tracker_bizobj.MakeFieldValue(4, None, None, 111, None, None, False),
      tracker_bizobj.MakeFieldValue(
          5, None, None, None, 1512518400, None, False),
      tracker_bizobj.MakeFieldValue(
          6, None, None, None, None, 'http://example.com', False),
      ],
     fv_list_add)
   self.assertEquals([], fv_list_remove)
   self.assertEquals([], fv_list_clear)
   self.assertEquals(['Priority-High'], label_list_add)
   self.assertEquals([], label_list_remove)
 def testMakeComponentsAmendment_Normal(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   config.component_defs = [
       tracker_pb2.ComponentDef(component_id=1, path='UI'),
       tracker_pb2.ComponentDef(component_id=2, path='DB')]
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.COMPONENTS, '-UI DB', [], []),
       tracker_bizobj.MakeComponentsAmendment([2], [1], config))
 def testGetIssueComponentsAndAncestors_AffectsSomeComponents(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   cd = tracker_pb2.ComponentDef(component_id=1, path='UI')
   config.component_defs.append(cd)
   cd2 = tracker_pb2.ComponentDef(component_id=2, path='UI>Splash')
   config.component_defs.append(cd2)
   issue = tracker_pb2.Issue(component_ids=[2])
   actual = tracker_bizobj.GetIssueComponentsAndAncestors(issue, config)
   self.assertEqual([cd, cd2], actual)
 def testGetGrantedPerms_NothingGranted(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(field_id=1)  # Nothing granted
   config.field_defs = [fd]
   fv = tracker_pb2.FieldValue(field_id=1, user_id=222L)
   issue = tracker_pb2.Issue(field_values=[fv])
   self.assertEqual(
       set(),
       tracker_bizobj.GetGrantedPerms(issue, {111L, 222L}, config))
Beispiel #23
0
    def GatherHelpData(self, mr, page_data):
        """Return a dict of values to drive on-page user help.

    Args:
      mr: common information parsed from the HTTP request.
      page_data: Dictionary of base and page template data.

    Returns:
      A dict of values to drive on-page user help, to be added to page_data.
    """
        help_data = super(IssueList, self).GatherHelpData(mr, page_data)
        dismissed = []
        if mr.auth.user_pb:
            with work_env.WorkEnv(mr, self.services) as we:
                userprefs = we.GetUserPrefs(mr.auth.user_id)
            dismissed = [
                pv.name for pv in userprefs.prefs if pv.value == 'true'
            ]

        if mr.project_id:
            config = self.services.config.GetProjectConfig(
                mr.cnxn, mr.project_id)
        else:
            config = tracker_bizobj.MakeDefaultProjectIssueConfig(None)

        try:
            _query_ast, is_fulltext_query = searchpipeline.ParseQuery(
                mr, config, self.services)
        except query2ast.InvalidQueryError:
            is_fulltext_query = False

        query_plus_col_spec = '%r %r' % (mr.query and mr.query.lower(),
                                         mr.col_spec and mr.col_spec.lower())
        uses_timestamp_term = any(col_name in query_plus_col_spec
                                  for col_name in ('ownermodified',
                                                   'statusmodified',
                                                   'componentmodified'))

        if (mr.mode == 'grid' and mr.cells == 'tiles' and
                len(page_data.get('results', [])) > settings.max_tiles_in_grid
                and 'showing_ids_instead_of_tiles' not in dismissed):
            help_data['cue'] = 'showing_ids_instead_of_tiles'
        elif (_AnyDerivedValues(page_data.get('table_data', []))
              and 'italics_mean_derived' not in dismissed):
            help_data['cue'] = 'italics_mean_derived'
        elif (uses_timestamp_term and 'issue_timestamps' not in dismissed):
            help_data['cue'] = 'issue_timestamps'
        # Note that the following are only offered to signed in users because
        # otherwise the first one would appear all the time to anon users.
        elif (mr.auth.user_id and mr.mode != 'grid'
              and 'dit_keystrokes' not in dismissed):
            help_data['cue'] = 'dit_keystrokes'
        elif (mr.auth.user_id and is_fulltext_query
              and 'stale_fulltext' not in dismissed):
            help_data['cue'] = 'stale_fulltext'

        return help_data
 def testFindMatchingComponentIDs_NoMatch(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=1, path='UI>Splash'))
   config.component_defs.append(tracker_pb2.ComponentDef(
       component_id=2, path='UI>AboutBox'))
   actual = tracker_bizobj.FindMatchingComponentIDs('DB', config)
   self.assertEqual([], actual)
   actual = tracker_bizobj.FindMatchingComponentIDs('DB', config, exact=False)
   self.assertEqual([], actual)
 def testMakeFieldAmendment_SingleValued(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(field_id=1, field_name='Size')
   config.field_defs.append(fd)
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, 'Large', [], [], 'Size'),
       tracker_bizobj.MakeFieldAmendment(1, config, ['Large'], ['Small']))
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '----', [], [], 'Size'),
       tracker_bizobj.MakeFieldAmendment(1, config, [], ['Small']))
Beispiel #26
0
 def testConvertFieldValues_ClearAndRemove(self):
     """The client wants to clear and remove some custom fields."""
     mar = mock.Mock()
     mar.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
     mar.config.field_defs = [
         tracker_bizobj.MakeFieldDef(1, 789, 'Priority',
                                     tracker_pb2.FieldTypes.ENUM_TYPE, None,
                                     None, False, False, False, None, None,
                                     None, False, None, None, None, None,
                                     'doc', False),
         tracker_bizobj.MakeFieldDef(11, 789, 'OS',
                                     tracker_pb2.FieldTypes.ENUM_TYPE, None,
                                     None, False, False, False, None, None,
                                     None, False, None, None, None, None,
                                     'doc', False),
         tracker_bizobj.MakeFieldDef(2, 789, 'EstDays',
                                     tracker_pb2.FieldTypes.INT_TYPE, None,
                                     None, False, False, False, 0, 99, None,
                                     False, None, None, None, None, 'doc',
                                     False),
         tracker_bizobj.MakeFieldDef(3, 789, 'Nickname',
                                     tracker_pb2.FieldTypes.STR_TYPE, None,
                                     None, False, False, False, None, None,
                                     None, False, None, None, None, None,
                                     'doc', False),
     ]
     field_values = [
         api_pb2_v1.FieldValue(
             fieldName='Priority',
             fieldValue='High',
             operator=api_pb2_v1.FieldValueOperator.remove),
         api_pb2_v1.FieldValue(
             fieldName='OS', operator=api_pb2_v1.FieldValueOperator.clear),
         api_pb2_v1.FieldValue(
             fieldName='EstDays',
             operator=api_pb2_v1.FieldValueOperator.clear),
         api_pb2_v1.FieldValue(
             fieldName='Nickname',
             fieldValue='Scout',
             operator=api_pb2_v1.FieldValueOperator.remove),
     ]
     actual = api_pb2_v1_helpers.convert_field_values(
         field_values, mar, self.services)
     (fv_list_add, fv_list_remove, fv_list_clear, label_list_add,
      label_list_remove) = actual
     self.assertEquals([], fv_list_add)
     self.assertEquals([
         tracker_bizobj.MakeFieldValue(3, None, 'Scout', None, None, None,
                                       False)
     ], fv_list_remove)
     self.assertEquals([11, 2], fv_list_clear)
     self.assertEquals([], label_list_add)
     self.assertEquals(['Priority-High'], label_list_remove)
 def testAttachDefaultApprovers(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   config.approval_defs = [
       tracker_pb2.ApprovalDef(
           approval_id=23, approver_ids=[222], survey='Question?'),
       tracker_pb2.ApprovalDef(
           approval_id=24, approver_ids=[111], survey='Question?')]
   approval_values = [tracker_pb2.ApprovalValue(
        approval_id=24, phase_id=1,
        status=tracker_pb2.ApprovalStatus.NEEDS_REVIEW)]
   issueentry._AttachDefaultApprovers(config, approval_values)
   self.assertEqual(approval_values[0].approver_ids, [111])
  def testConvertApprovals(self):
    """Test we can convert ApprovalValues."""
    cnxn = None
    config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
    config.field_defs = [
      tracker_bizobj.MakeFieldDef(
            1, 789, 'DesignReview', tracker_pb2.FieldTypes.APPROVAL_TYPE, None,
            None, False, False, False, None, None, None, False, None, None,
            None, None, 'doc', False),
        tracker_bizobj.MakeFieldDef(
            2, 789, 'PrivacyReview', tracker_pb2.FieldTypes.APPROVAL_TYPE, None,
            None, False, False, False, 0, 99, None, False, None, None, None,
            None, 'doc', False),
        tracker_bizobj.MakeFieldDef(
            5, 789, 'UXReview', tracker_pb2.FieldTypes.APPROVAL_TYPE, None,
            None, False, False, False, None, None, None, False, None, None,
            None, None, 'doc', False),
        tracker_bizobj.MakeFieldDef(
            6, 789, 'Homepage', tracker_pb2.FieldTypes.URL_TYPE, None, None,
            False, False, False, None, None, None, False, None, None, None,
            None, 'doc', False),
        ]
    phases = [
        tracker_pb2.Phase(phase_id=1),
        tracker_pb2.Phase(phase_id=2, name="JustAPhase", rank=3),
    ]
    ts = 1536260059
    expected = [
        api_pb2_v1.Approval(
            approvalName="DesignReview",
            approvers=[self.person_1],
            setter=self.person_1,
            status=api_pb2_v1.ApprovalStatus.needsReview,
            setOn=datetime.datetime.fromtimestamp(ts),
        ),
        api_pb2_v1.Approval(
            approvalName="UXReview",
            approvers=[self.person_1],
            status=api_pb2_v1.ApprovalStatus.notSet,
            phaseName="JustAPhase",
        ),
    ]
    avs = [
        tracker_pb2.ApprovalValue(
            approval_id=1, approver_ids=[111], setter_id=111,
            status=tracker_pb2.ApprovalStatus.NEEDS_REVIEW, set_on=ts),
        tracker_pb2.ApprovalValue(
            approval_id=5, approver_ids=[111], phase_id=2)
    ]
    actual = api_pb2_v1_helpers.convert_approvals(
        cnxn, avs, self.services, config, phases)

    self.assertEqual(actual, expected)
 def testGetGrantedPerms_Normal(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(field_id=1, grants_perm='Highlight')
   config.field_defs = [fd]
   fv = tracker_pb2.FieldValue(field_id=1, user_id=222L)
   issue = tracker_pb2.Issue(field_values=[fv])
   self.assertEqual(
       set(),
       tracker_bizobj.GetGrantedPerms(issue, {111L}, config))
   self.assertEqual(
       set(['highlight']),
       tracker_bizobj.GetGrantedPerms(issue, {111L, 222L}, config))
 def testMakeFieldAmendment_MultiValued(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(
       field_id=1, field_name='Days', is_multivalued=True)
   config.field_defs.append(fd)
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '-Mon Tue Wed', [], [], 'Days'),
       tracker_bizobj.MakeFieldAmendment(1, config, ['Tue', 'Wed'], ['Mon']))
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '-Mon', [], [], 'Days'),
       tracker_bizobj.MakeFieldAmendment(1, config, [], ['Mon']))