Exemplo n.º 1
0
  def testCustomFieldSortClauses_PhaseUser(self):
    fd_list = [
      tracker_pb2.FieldDef(field_id=1, project_id=789,
                           field_type=tracker_pb2.FieldTypes.INT_TYPE),
      tracker_pb2.FieldDef(field_id=2, project_id=788,
                           field_type=tracker_pb2.FieldTypes.STR_TYPE),
      tracker_pb2.FieldDef(field_id=3, project_id=788,
                           field_type=tracker_pb2.FieldTypes.USER_TYPE),
    ]
    left_joins, order_by = ast2sort._CustomFieldSortClauses(
        fd_list, tracker_pb2.FieldTypes.USER_TYPE, 'user_id', 'Sort0', 'DESC',
        phase_name='Stable')

    self.assertEqual(
        left_joins, [
            ('Issue2FieldValue AS Sort0_user_id '
             'ON Issue.id = Sort0_user_id.issue_id '
             'AND Sort0_user_id.field_id IN (%s)', [3]),
            ('IssuePhaseDef AS Sort0_user_id_phase '
             'ON Sort0_user_id.phase_id = Sort0_user_id_phase.id '
             'AND LOWER(Sort0_user_id_phase.name) = LOWER(%s)', ['Stable']),
            ('User AS Sort0_user_id_user '
             'ON Sort0_user_id.user_id = Sort0_user_id_user.user_id', []),
        ])
    self.assertEqual(
        order_by, [
            ('ISNULL(Sort0_user_id_user.email) DESC', []),
            ('Sort0_user_id_user.email DESC', []),
        ])
Exemplo n.º 2
0
  def testMergeLabels_SingleValuedEnums(self):
    self.config.field_defs.append(tracker_pb2.FieldDef(
        field_id=1, field_name='Size',
        field_type=tracker_pb2.FieldTypes.ENUM_TYPE,
        is_multivalued=False))
    self.config.field_defs.append(tracker_pb2.FieldDef(
        field_id=1, field_name='Branch-Name',
        field_type=tracker_pb2.FieldTypes.ENUM_TYPE,
        is_multivalued=False))

    # We can add a label for a single-valued enum.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Priority-Medium', 'OpSys-OSX'], ['Size-L'], [], self.config)
    self.assertEquals(merged_labels, ['Priority-Medium', 'OpSys-OSX', 'Size-L'])
    self.assertEquals(update_add, ['Size-L'])
    self.assertEquals(update_remove, [])

    # Adding and removing the same label adds it.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Priority-Medium'], ['Size-M'], ['Size-M'], self.config)
    self.assertEquals(merged_labels, ['Priority-Medium', 'Size-M'])
    self.assertEquals(update_add, ['Size-M'])
    self.assertEquals(update_remove, [])

    # Adding Size-L replaces Size-M.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Priority-Medium', 'Size-M'], ['Size-L', 'OpSys-Win'], [],
        self.config)
    self.assertEquals(merged_labels,
                      ['Priority-Medium', 'Size-L', 'OpSys-Win'])
    self.assertEquals(update_add, ['Size-L', 'OpSys-Win'])
    self.assertEquals(update_remove, [])

    # Adding Size-L and Size-XL replaces with L only.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Size-M', 'OpSys-OSX'], ['Size-L', 'Size-XL'], [], self.config)
    self.assertEquals(merged_labels, ['OpSys-OSX', 'Size-L'])
    self.assertEquals(update_add, ['Size-L'])
    self.assertEquals(update_remove, [])

    # Multi-part labels work as expected.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Size-M', 'OpSys-OSX'], ['Size-M-USA'], [], self.config)
    self.assertEquals(
        merged_labels, ['OpSys-OSX', 'Size-M-USA'])
    self.assertEquals(update_add, ['Size-M-USA'])
    self.assertEquals(update_remove, [])

    # Multi-part enum names only filter labels that match whole name.
    (merged_labels, update_add, update_remove) = framework_bizobj.MergeLabels(
        ['Branch-Name-Master'],
        ['Branch-Prediction', 'Branch-Name-Beta'], [], self.config)
    self.assertEquals(
        merged_labels, ['Branch-Prediction', 'Branch-Name-Beta'])
    self.assertEquals(update_add, ['Branch-Prediction', 'Branch-Name-Beta'])
    self.assertEquals(update_remove, [])
Exemplo n.º 3
0
    def testMakeBounceFieldValueViews(self):
        config = tracker_pb2.ProjectIssueConfig()
        fd = tracker_pb2.FieldDef(field_id=3,
                                  field_type=tracker_pb2.FieldTypes.INT_TYPE,
                                  applicable_type='',
                                  field_name='EstDays')
        phase_fd = tracker_pb2.FieldDef(
            field_id=4,
            field_type=tracker_pb2.FieldTypes.INT_TYPE,
            applicable_type='',
            field_name='Gump')
        config.field_defs = [
            fd, phase_fd,
            tracker_pb2.FieldDef(field_id=5,
                                 field_type=tracker_pb2.FieldTypes.STR_TYPE)
        ]
        parsed_fvs = {3: [455]}
        parsed_phase_fvs = {
            4: {
                'stable': [73, 74],
                'beta': [8],
                'beta-exp': [75]
            },
        }
        fvs = tracker_views.MakeBounceFieldValueViews(parsed_fvs,
                                                      parsed_phase_fvs, config)

        self.assertEqual(len(fvs), 4)

        estdays_ezt_fv = template_helpers.EZTItem(val=455, docstring='', idx=0)
        expected = tracker_views.FieldValueView(fd, config, [estdays_ezt_fv],
                                                [], [])
        self.assertEqual(fvs[0].field_name, expected.field_name)
        self.assertEqual(fvs[0].values[0].val, expected.values[0].val)
        self.assertEqual(fvs[0].values[0].idx, expected.values[0].idx)
        self.assertTrue(fvs[0].applicable)

        self.assertEqual(fvs[1].field_name, phase_fd.field_name)
        self.assertEqual(fvs[2].field_name, phase_fd.field_name)
        self.assertEqual(fvs[3].field_name, phase_fd.field_name)

        fd.approval_id = 23
        config.field_defs = [
            fd,
            tracker_pb2.FieldDef(
                field_id=23,
                field_name='Legal',
                field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE)
        ]
        fvs = tracker_views.MakeBounceFieldValueViews(parsed_fvs, {}, config)
        self.assertTrue(fvs[0].applicable)
    def setUp(self):
        self.mox = mox.Mox()
        self.any_field_fd = tracker_pb2.FieldDef(
            field_name='any_field', field_type=tracker_pb2.FieldTypes.STR_TYPE)
        self.summary_fd = tracker_pb2.FieldDef(
            field_name='summary', field_type=tracker_pb2.FieldTypes.STR_TYPE)
        self.milestone_fd = tracker_pb2.FieldDef(
            field_name='milestone',
            field_type=tracker_pb2.FieldTypes.STR_TYPE,
            field_id=123)
        self.fulltext_fields = ['summary']

        self.mock_index = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(search, 'Index')
        self.query = None
    def testBuildFTSQuery_SpecialPrefixQuery(self):
        special_prefix = query2ast.NON_OP_PREFIXES[0]

        # Test with summary field.
        query_ast_conj = ast_pb2.Conjunction(conds=[
            ast_pb2.MakeCond(TEXT_HAS, [self.summary_fd],
                             ['%s//google.com' % special_prefix], []),
            ast_pb2.MakeCond(TEXT_HAS, [self.milestone_fd], ['Q3', 'Q4'], [])
        ])
        fulltext_query = fulltext_helpers.BuildFTSQuery(
            query_ast_conj, self.fulltext_fields)
        self.assertEqual(
            '(summary:"%s//google.com") (custom_123:"Q3" OR custom_123:"Q4")' %
            (special_prefix), fulltext_query)

        # Test with any field.
        any_fd = tracker_pb2.FieldDef(
            field_name=ast_pb2.ANY_FIELD,
            field_type=tracker_pb2.FieldTypes.STR_TYPE)
        query_ast_conj = ast_pb2.Conjunction(conds=[
            ast_pb2.MakeCond(TEXT_HAS, [any_fd],
                             ['%s//google.com' % special_prefix], []),
            ast_pb2.MakeCond(TEXT_HAS, [self.milestone_fd], ['Q3', 'Q4'], [])
        ])
        fulltext_query = fulltext_helpers.BuildFTSQuery(
            query_ast_conj, self.fulltext_fields)
        self.assertEqual(
            '("%s//google.com") (custom_123:"Q3" OR custom_123:"Q4")' %
            (special_prefix), fulltext_query)
 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))
Exemplo n.º 7
0
    def testPreprocessCustomCond_User(self):
        fd = tracker_pb2.FieldDef(field_id=1,
                                  field_name='TPM',
                                  field_type=tracker_pb2.FieldTypes.USER_TYPE)
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [fd],
                                ['*****@*****.**'], [])
        new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                                 self.services, True)
        self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
        self.assertEqual(cond.field_defs, new_cond.field_defs)
        self.assertEqual([111], new_cond.int_values)
        self.assertEqual([], new_cond.str_values)

        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [fd], ['111'], [])
        new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                                 self.services, True)
        self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
        self.assertEqual(cond.field_defs, new_cond.field_defs)
        self.assertEqual([111], new_cond.int_values)
        self.assertEqual([], new_cond.str_values)

        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [fd],
                                ['*****@*****.**'], [])
        new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                                 self.services, True)
        self.assertEqual(cond, new_cond)
Exemplo n.º 8
0
def MakeFieldDef(field_id, project_id, field_name, field_type_int, applic_type,
                 applic_pred, is_required, is_niche, is_multivalued, min_value,
                 max_value, regex, needs_member, needs_perm, grants_perm,
                 notify_on, date_action, docstring, is_deleted):
    """Make a FieldDef PB for the given FieldDef table row tuple."""
    if isinstance(date_action, basestring):
        date_action = date_action.upper()
    fd = tracker_pb2.FieldDef(field_id=field_id,
                              project_id=project_id,
                              field_name=field_name,
                              field_type=field_type_int,
                              is_required=bool(is_required),
                              is_niche=bool(is_niche),
                              is_multivalued=bool(is_multivalued),
                              docstring=docstring,
                              is_deleted=bool(is_deleted),
                              applicable_type=applic_type or '',
                              applicable_predicate=applic_pred or '',
                              needs_member=bool(needs_member),
                              grants_perm=grants_perm or '',
                              notify_on=tracker_pb2.NotifyTriggers(notify_on
                                                                   or 0),
                              date_action=tracker_pb2.DateAction(date_action
                                                                 or 0))
    if min_value is not None:
        fd.min_value = min_value
    if max_value is not None:
        fd.max_value = max_value
    if regex is not None:
        fd.regex = regex
    if needs_perm is not None:
        fd.needs_perm = needs_perm
    return fd
 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))
Exemplo n.º 10
0
 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))
Exemplo n.º 11
0
 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))
Exemplo n.º 12
0
 def testCond(self):
     fd = tracker_pb2.FieldDef(field_id=1, field_name='Size')
     cond = ast_pb2.MakeCond(ast_pb2.QueryOp.EQ, [fd], ['XL'], [],
                             key_suffix='-approver')
     self.assertEqual(ast_pb2.QueryOp.EQ, cond.op)
     self.assertEqual([fd], cond.field_defs)
     self.assertEqual(['XL'], cond.str_values)
     self.assertEqual([], cond.int_values)
     self.assertEqual(cond.key_suffix, '-approver')
Exemplo n.º 13
0
    def setUp(self):
        self.services = service_manager.Services(user=fake.UserService(),
                                                 config=fake.ConfigService(),
                                                 project=fake.ProjectService())
        self.servlet = fielddetail.FieldDetail('req',
                                               'res',
                                               services=self.services)
        self.project = self.services.project.TestAddProject('proj')
        self.mr = testing_helpers.MakeMonorailRequest(
            project=self.project, perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
        self.config = self.services.config.GetProjectConfig(
            'fake cnxn', self.project.project_id)
        self.services.config.StoreConfig('fake cnxn', self.config)
        self.fd = tracker_bizobj.MakeFieldDef(123, 789, 'CPU',
                                              tracker_pb2.FieldTypes.INT_TYPE,
                                              None, '', False, False, False,
                                              None, None, '', False, '', '',
                                              tracker_pb2.NotifyTriggers.NEVER,
                                              'no_action', 'doc', False)
        self.config.field_defs.append(self.fd)
        self.services.user.TestAddUser('*****@*****.**', 111)
        self.services.user.TestAddUser('*****@*****.**', 222)
        self.mr.field_name = 'CPU'

        # Approvals
        self.approval_def = tracker_pb2.ApprovalDef(approval_id=234,
                                                    approver_ids=[111],
                                                    survey='Question 1?')
        self.sub_fd = tracker_pb2.FieldDef(field_name='UIMocks',
                                           approval_id=234,
                                           applicable_type='')
        self.sub_fd_deleted = tracker_pb2.FieldDef(field_name='UIMocksDeleted',
                                                   approval_id=234,
                                                   applicable_type='',
                                                   is_deleted=True)
        self.config.field_defs.extend([self.sub_fd, self.sub_fd_deleted])
        self.config.approval_defs.append(self.approval_def)
        self.approval_fd = tracker_bizobj.MakeFieldDef(
            234, 789, 'UIReview', tracker_pb2.FieldTypes.APPROVAL_TYPE, None,
            '', False, False, False, None, None, '', False, '', '',
            tracker_pb2.NotifyTriggers.NEVER, 'no_action', 'doc', False)
        self.config.field_defs.append(self.approval_fd)

        self.mox = mox.Mox()
 def testBuildFTSQuery_NoFullTextConditions(self):
     estimated_hours_fd = tracker_pb2.FieldDef(
         field_name='estimate',
         field_type=tracker_pb2.FieldTypes.INT_TYPE,
         field_id=124)
     query_ast_conj = ast_pb2.Conjunction(
         conds=[ast_pb2.MakeCond(TEXT_HAS, [estimated_hours_fd], [], [40])])
     fulltext_query = fulltext_helpers.BuildFTSQuery(
         query_ast_conj, self.fulltext_fields)
     self.assertEqual(None, fulltext_query)
 def testBuildFTSCondition_NonStringField(self):
     est_days_fd = tracker_pb2.FieldDef(
         field_name='EstDays',
         field_id=123,
         field_type=tracker_pb2.FieldTypes.INT_TYPE)
     query_cond = ast_pb2.MakeCond(TEXT_HAS, [est_days_fd], ['needle'], [])
     fulltext_query_clause = fulltext_helpers._BuildFTSCondition(
         query_cond, self.fulltext_fields)
     # Ignore in FTS, this search condition is done in SQL.
     self.assertEqual('', fulltext_query_clause)
Exemplo n.º 16
0
    def testSortGridHeadings(self):
        config = fake.MakeTestConfig(
            789,
            labels=('Priority-High Priority-Medium Priority-Low Hot Cold '
                    'Milestone-Near Milestone-Far '
                    'Day-Sun Day-Mon Day-Tue Day-Wed Day-Thu Day-Fri Day-Sat'),
            statuses=('New Accepted Started Fixed WontFix Invalid Duplicate'))
        config.field_defs = [
            tracker_pb2.FieldDef(field_id=1,
                                 project_id=789,
                                 field_name='Day',
                                 field_type=tracker_pb2.FieldTypes.ENUM_TYPE)
        ]
        asc_accessors = {
            'id': 'some function that is not called',
            'reporter': 'some function that is not called',
            'opened': 'some function that is not called',
            'modified': 'some function that is not called',
        }

        # Verify that status headings are sorted according to the status
        # values defined in the config.
        col_name = 'status'
        headings = ['Duplicate', 'Limbo', 'New', 'OnHold', 'Accepted', 'Fixed']
        sorted_headings = grid_view_helpers.SortGridHeadings(
            col_name, headings, self.users_by_id, config, asc_accessors)
        self.assertEqual(
            sorted_headings,
            ['New', 'Accepted', 'Fixed', 'Duplicate', 'Limbo', 'OnHold'])

        # Verify that special columns are sorted alphabetically or numerically.
        col_name = 'id'
        headings = [1, 2, 5, 3, 4]
        sorted_headings = grid_view_helpers.SortGridHeadings(
            col_name, headings, self.users_by_id, config, asc_accessors)
        self.assertEqual(sorted_headings, [1, 2, 3, 4, 5])

        # Verify that label value headings are sorted according to the labels
        # values defined in the config.
        col_name = 'priority'
        headings = ['Medium', 'High', 'Low', 'dont-care']
        sorted_headings = grid_view_helpers.SortGridHeadings(
            col_name, headings, self.users_by_id, config, asc_accessors)
        self.assertEqual(sorted_headings,
                         ['High', 'Medium', 'Low', 'dont-care'])

        # Verify that enum headings are sorted according to the labels
        # values defined in the config.
        col_name = 'day'
        headings = ['Tue', 'Fri', 'Sun', 'Dogday', 'Wed', 'Caturday', 'Low']
        sorted_headings = grid_view_helpers.SortGridHeadings(
            col_name, headings, self.users_by_id, config, asc_accessors)
        self.assertEqual(
            sorted_headings,
            ['Sun', 'Tue', 'Wed', 'Fri', 'Caturday', 'Dogday', 'Low'])
Exemplo n.º 17
0
  def testProcessCustomAndLabelSD_PhaseField(self):
    harmonized_labels = []
    bear_fd = tracker_pb2.FieldDef(
        field_id=1, field_name='DropBear', project_id=789,
        field_type=tracker_pb2.FieldTypes.INT_TYPE)
    bear2_fd = tracker_pb2.FieldDef(
        field_id=2, field_name='DropBear', project_id=788,
        field_type=tracker_pb2.FieldTypes.STR_TYPE)
    koala_fd = tracker_pb2.FieldDef(
        field_id=3, field_name='koala', project_id=789,
        field_type=tracker_pb2.FieldTypes.INT_TYPE)
    bear_app_fd = tracker_pb2.FieldDef(
        field_id=4, field_name='dropbear', project_id=789,
        field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE)
    harmonized_fields = [bear_fd, bear2_fd, koala_fd, bear_app_fd]
    phase_name = 'stable'
    alias = 'Sort0'
    sort_dir = 'DESC'
    sd = 'stable.dropbear'
    left_joins, order_by = ast2sort._ProcessCustomAndLabelSD(
        sd, harmonized_labels, harmonized_fields, alias, sort_dir,
        self.fmt)

    expected_joins = []
    expected_order = []
    int_left_joins, int_order_by = ast2sort._CustomFieldSortClauses(
        [bear_fd, bear2_fd], tracker_pb2.FieldTypes.INT_TYPE, 'int_value',
        alias, sort_dir, phase_name=phase_name)
    str_left_joins, str_order_by = ast2sort._CustomFieldSortClauses(
        [bear_fd, bear2_fd], tracker_pb2.FieldTypes.STR_TYPE, 'str_value',
        alias, sort_dir, phase_name=phase_name)
    user_left_joins, user_order_by = ast2sort._CustomFieldSortClauses(
        [bear_fd, bear2_fd], tracker_pb2.FieldTypes.USER_TYPE, 'user_id',
        alias, sort_dir, phase_name=phase_name)
    label_left_joinss, label_order_by = ast2sort._LabelSortClauses(
        sd, harmonized_labels, self.fmt)
    expected_joins.extend(
        int_left_joins + str_left_joins + user_left_joins + label_left_joinss)
    expected_order.extend(
        int_order_by + str_order_by + user_order_by + label_order_by)
    self.assertEqual(left_joins, expected_joins)
    self.assertEqual(order_by, expected_order)
Exemplo n.º 18
0
  def testApprovalFieldSortClauses_Status(self):
    approval_fd_list = [
        tracker_pb2.FieldDef(field_id=2, project_id=789,
                             field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE),
        tracker_pb2.FieldDef(field_id=4, project_id=788,
                             field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE)
    ]
    left_joins, order_by = ast2sort._ApprovalFieldSortClauses(
        approval_fd_list, '-status', self.fmt)

    self.assertEqual(
        [('{tbl_name} AS {alias}_approval '
          'ON Issue.id = {alias}_approval.issue_id '
          'AND {alias}_approval.approval_id IN ({approval_ids_ph})', [2, 4])],
        left_joins)

    self.assertEqual(
        [('FIELD({alias}_approval.status, {approval_status_ph}) {rev_sort_dir}',
          ast2sort.APPROVAL_STATUS_SORT_ORDER)],
        order_by)
Exemplo n.º 19
0
  def testCustomFieldSortClauses_Normal(self):
    fd_list = [
      tracker_pb2.FieldDef(field_id=1, project_id=789,
                           field_type=tracker_pb2.FieldTypes.INT_TYPE),
      tracker_pb2.FieldDef(field_id=2, project_id=788,
                           field_type=tracker_pb2.FieldTypes.STR_TYPE),
    ]
    left_joins, order_by = ast2sort._CustomFieldSortClauses(
        fd_list, tracker_pb2.FieldTypes.INT_TYPE, 'int_value', 'Sort0', 'DESC')

    self.assertEqual(
        left_joins, [
            ('Issue2FieldValue AS Sort0_int_value '
             'ON Issue.id = Sort0_int_value.issue_id '
             'AND Sort0_int_value.field_id IN (%s)', [1]),
        ])
    self.assertEqual(
        order_by, [
            ('ISNULL(Sort0_int_value.int_value) DESC', []),
            ('Sort0_int_value.int_value DESC', []),
        ])
Exemplo n.º 20
0
 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))
Exemplo n.º 21
0
 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']))
 def testBuildFTSCondition_CrossProjectWithMultipleFieldDescriptors(self):
     other_milestone_fd = tracker_pb2.FieldDef(
         field_name='milestone',
         field_type=tracker_pb2.FieldTypes.STR_TYPE,
         field_id=456)
     query_cond = ast_pb2.MakeCond(TEXT_HAS,
                                   [self.milestone_fd, other_milestone_fd],
                                   ['needle'], [])
     fulltext_query_clause = fulltext_helpers._BuildFTSCondition(
         query_cond, self.fulltext_fields)
     self.assertEqual('(custom_123:"needle" OR custom_456:"needle")',
                      fulltext_query_clause)
Exemplo n.º 23
0
 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']))
Exemplo n.º 24
0
    def testPreprocessCustomCond_NonUser(self):
        fd = tracker_pb2.FieldDef(field_id=1,
                                  field_name='TPM',
                                  field_type=tracker_pb2.FieldTypes.INT_TYPE)
        cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [fd], ['foo'], [123])
        new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                                 self.services, True)
        self.assertEqual(cond, new_cond)

        fd.field_type = tracker_pb2.FieldTypes.STR_TYPE
        new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                                 self.services, True)
        self.assertEqual(cond, new_cond)
Exemplo n.º 25
0
  def testMergeFields_MultiValued(self):
    fd = tracker_pb2.FieldDef(
        field_id=1, field_name='foo', is_multivalued=True)
    fv1 = tracker_bizobj.MakeFieldValue(1, 42, None, None, None, False)
    fv2 = tracker_bizobj.MakeFieldValue(1, 43, None, None, None, False)
    fv3 = tracker_bizobj.MakeFieldValue(1, 44, None, None, None, False)
    fv4 = tracker_bizobj.MakeFieldValue(1, 42, None, None, None, False)
    fv5 = tracker_bizobj.MakeFieldValue(1, 99, None, None, None, False)

    merged_fvs, fvs_added, fvs_removed = tracker_bizobj.MergeFields(
        [fv1, fv2], [fv2, fv3], [fv4, fv5], [fd])
    self.assertEqual([fv2, fv3], merged_fvs)
    self.assertEqual([fv3], fvs_added)
    self.assertEqual([fv4], fvs_removed)
Exemplo n.º 26
0
 def testProcessSubtabForm_Conflict(self, mock_pc):
     post_data = fake.PostData(
         predefinedlabels=['Multi-Part-One\nPri-4\npri-0'],
         excl_prefixes=['pri'])
     self.config.field_defs = [
         tracker_pb2.FieldDef(field_name='Multi-Part',
                              field_type=tracker_pb2.FieldTypes.ENUM_TYPE)
     ]
     next_url = self.servlet.ProcessSubtabForm(post_data, self.mr)
     self.assertIsNone(next_url)
     mock_pc.assert_called_once()
     self.assertEqual(
         'Label "Multi-Part-One" should be defined in enum "multi-part"',
         self.mr.errors.label_defs)
Exemplo n.º 27
0
  def testApprovalFieldSortClauses_Approver(self):
    approval_fd_list = [
        tracker_pb2.FieldDef(field_id=2, project_id=789,
                             field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE),
        tracker_pb2.FieldDef(field_id=4, project_id=788,
                             field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE)
    ]
    left_joins, order_by = ast2sort._ApprovalFieldSortClauses(
        approval_fd_list, '-approver', self.fmt)

    self.assertEqual(
        [('{tbl_name} AS {alias}_approval '
          'ON Issue.id = {alias}_approval.issue_id '
          'AND {alias}_approval.approval_id IN ({approval_ids_ph})', [2, 4]),
         ('User AS {alias}_approval_user '
          'ON {alias}_approval.approver_id = {alias}_approval_user.user_id',
          [])],
        left_joins)

    self.assertEqual(
        [('ISNULL({alias}_approval_user.email) {sort_dir}', []),
         ('{alias}_approval_user.email {sort_dir}', [])],
        order_by)
Exemplo n.º 28
0
 def testMakeFieldAmendment_SingleValuedUser(self):
   config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
   fd = tracker_pb2.FieldDef(
       field_id=1, field_name='Friend',
       field_type=tracker_pb2.FieldTypes.USER_TYPE)
   config.field_defs.append(fd)
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '', [111L], [], 'Friend'),
       tracker_bizobj.MakeFieldAmendment(1, config, [111L], [222L]))
   self.assertEqual(
       tracker_bizobj.MakeAmendment(
           tracker_pb2.FieldID.CUSTOM, '', [], [], 'Friend'),
       tracker_bizobj.MakeFieldAmendment(1, config, [], [222L]))
Exemplo n.º 29
0
 def testSearchIssueFullText_Normal(self):
     self.SetUpSearchIssueFullText()
     self.mox.ReplayAll()
     summary_fd = tracker_pb2.FieldDef(
         field_name='summary', field_type=tracker_pb2.FieldTypes.STR_TYPE)
     query_ast_conj = ast_pb2.Conjunction(conds=[
         ast_pb2.Condition(op=ast_pb2.QueryOp.TEXT_HAS,
                           field_defs=[summary_fd],
                           str_values=['test'])
     ])
     issue_ids, capped = tracker_fulltext.SearchIssueFullText(
         [789], query_ast_conj, 1)
     self.mox.VerifyAll()
     self.assertItemsEqual([123, 234], issue_ids)
     self.assertFalse(capped)
Exemplo n.º 30
0
 def testPreprocessCustomCond_ApprovalUser(self):
     fd = tracker_pb2.FieldDef(
         field_id=1,
         field_name='UXReview',
         field_type=tracker_pb2.FieldTypes.APPROVAL_TYPE)
     cond = ast_pb2.MakeCond(ast_pb2.QueryOp.TEXT_HAS, [fd],
                             ['*****@*****.**'], [],
                             key_suffix=query2ast.APPROVER_SUFFIX)
     new_cond = ast2ast._PreprocessCustomCond(self.cnxn, cond,
                                              self.services, True)
     self.assertEqual(ast_pb2.QueryOp.EQ, new_cond.op)
     self.assertEqual(cond.field_defs, new_cond.field_defs)
     self.assertEqual([111], new_cond.int_values)
     self.assertEqual([], new_cond.str_values)
     self.assertEqual(query2ast.APPROVER_SUFFIX, new_cond.key_suffix)