示例#1
0
    def testGatherPageData_CanCreateProject(self):
        mr = testing_helpers.MakeMonorailRequest()
        mr.perms = permissions.PermissionSet([permissions.CREATE_PROJECT])
        page_data = self.servlet.GatherPageData(mr)
        self.assertEqual(
            ezt.boolean(settings.project_creation_restriction ==
                        site_pb2.UserTypeRestriction.ANYONE),
            page_data['can_create_project'])

        mr.perms = permissions.PermissionSet([])
        page_data = self.servlet.GatherPageData(mr)
        self.assertEqual(ezt.boolean(False), page_data['can_create_project'])
 def testConvertApprovalComment(self):
   """Test convert_approval_comment."""
   mar = mock.Mock()
   mar.cnxn = None
   mar.perms = permissions.PermissionSet([])
   issue = fake.MakeTestIssue(project_id=12345, local_id=1, summary='sum',
                              status='New', owner_id=1001)
   comment = tracker_pb2.IssueComment(
       user_id=111,
       content='test content',
       sequence=1,
       deleted_by=111,
       timestamp=1437700000,
   )
   result = api_pb2_v1_helpers.convert_approval_comment(
       issue, comment, mar, self.services, None)
   self.assertEquals('*****@*****.**', result.author.name)
   self.assertEquals(comment.content, result.content)
   self.assertEquals('*****@*****.**', result.deletedBy.name)
   self.assertEquals(1, result.id)
   # Ensure that the published timestamp falls in a timestamp range to account
   # for the test being run in different timezones.
   # Using "Fri, 23 Jul 2015 00:00:00" and "Fri, 25 Jul 2015 00:00:00".
   self.assertTrue(
       datetime.datetime(2015, 7, 23, 0, 0, 0) <= result.published <=
       datetime.datetime(2015, 7, 25, 0, 0, 0))
   self.assertEqual(result.kind, 'monorail#approvalComment')
示例#3
0
    def testQueryIssueSnapshots_Labels(self):
        """Test a burndown query from a regular user grouping by label."""
        project = fake.Project(project_id=789)
        perms = permissions.PermissionSet(['BarPerm'])
        search_helpers.GetPersonalAtRiskLabelIDs(self.cnxn, None,
                                                 self.config_service, [10, 20],
                                                 project,
                                                 perms).AndReturn([91, 81])

        cols = [
            'Lab.label',
            'IssueSnapshot.issue_id',
        ]
        left_joins = self.defaultLeftJoins + [
            ('IssueSnapshot2Label AS Is2l'
             ' ON Is2l.issuesnapshot_id = IssueSnapshot.id', []),
            ('LabelDef AS Lab ON Lab.id = Is2l.label_id', [])
        ]
        where = self.defaultWheres + [
            ('LOWER(Lab.label) LIKE %s', ['foo-%']),
        ]
        group_by = ['Lab.label']
        stmt, stmt_args = self.services.chart._BuildSnapshotQuery(cols,
                                                                  where,
                                                                  left_joins,
                                                                  group_by,
                                                                  shard_id=0)

        self.services.chart._QueryToWhere(mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(),
                                          mox.IgnoreArg()).AndReturn(
                                              ([], [], []))
        self.cnxn.Execute(stmt, stmt_args, shard_id=0).AndReturn([])

        self._verifySQL(cols, left_joins, where, group_by)

        self.mox.ReplayAll()
        self.services.chart.QueryIssueSnapshots(self.cnxn,
                                                self.services,
                                                unixtime=1514764800,
                                                effective_ids=[10, 20],
                                                project=project,
                                                perms=perms,
                                                group_by='label',
                                                label_prefix='Foo')
        self.mox.VerifyAll()
示例#4
0
    def testQueryIssueSnapshots_Status(self):
        """Test a burndown query from a regular user grouping by open status."""
        project = fake.Project(project_id=789)
        perms = permissions.PermissionSet(['BarPerm'])
        search_helpers.GetPersonalAtRiskLabelIDs(self.cnxn, None,
                                                 self.config_service,
                                                 [10L, 20L], project,
                                                 perms).AndReturn([91, 81])

        cols = [
            'Stats.status',
            'IssueSnapshot.issue_id',
        ]
        left_joins = self.defaultLeftJoins + [
            ('StatusDef AS Stats ON ' \
            'Stats.id = IssueSnapshot.status_id', [])
        ]
        where = self.defaultWheres
        group_by = ['Stats.status']
        stmt, stmt_args = self.services.chart._BuildSnapshotQuery(cols,
                                                                  where,
                                                                  left_joins,
                                                                  group_by,
                                                                  shard_id=0)

        self.services.chart._QueryToWhere(mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(),
                                          mox.IgnoreArg()).AndReturn(
                                              ([], [], []))
        self.cnxn.Execute(stmt, stmt_args, shard_id=0).AndReturn([])

        self._verifySQL(cols, left_joins, where, group_by)

        self.mox.ReplayAll()
        self.services.chart.QueryIssueSnapshots(self.cnxn,
                                                self.services,
                                                unixtime=1514764800,
                                                effective_ids=[10L, 20L],
                                                project=project,
                                                perms=perms,
                                                group_by='status')
        self.mox.VerifyAll()
示例#5
0
    def testQueryIssueSnapshots_Components(self):
        """Test a burndown query from a regular user grouping by component."""
        project = fake.Project(project_id=789)
        perms = permissions.PermissionSet(['BarPerm'])
        search_helpers.GetPersonalAtRiskLabelIDs(self.cnxn, None,
                                                 self.config_service, [10, 20],
                                                 project,
                                                 perms).AndReturn([91, 81])

        cols = ['Comp.path', 'IssueSnapshot.issue_id']
        left_joins = self.defaultLeftJoins + [
            ('IssueSnapshot2Component AS Is2c'
             ' ON Is2c.issuesnapshot_id = IssueSnapshot.id', []),
            ('ComponentDef AS Comp ON Comp.id = Is2c.component_id', [])
        ]
        where = self.defaultWheres
        group_by = ['Comp.path']
        stmt, stmt_args = self.services.chart._BuildSnapshotQuery(cols,
                                                                  where,
                                                                  left_joins,
                                                                  group_by,
                                                                  shard_id=0)

        self.services.chart._QueryToWhere(mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(),
                                          mox.IgnoreArg()).AndReturn(
                                              ([], [], []))
        self.cnxn.Execute(stmt, stmt_args, shard_id=0).AndReturn([])

        self._verifySQL(cols, left_joins, where, group_by)

        self.mox.ReplayAll()
        self.services.chart.QueryIssueSnapshots(self.cnxn,
                                                self.services,
                                                unixtime=1514764800,
                                                effective_ids=[10, 20],
                                                project=project,
                                                perms=perms,
                                                group_by='component')
        self.mox.VerifyAll()
示例#6
0
    def testQueryIssueSnapshots_NoGroupBy(self):
        """Test a burndown query from a regular user with no grouping."""
        project = fake.Project(project_id=789)
        perms = permissions.PermissionSet(['BarPerm'])
        search_helpers.GetPersonalAtRiskLabelIDs(self.cnxn, None,
                                                 self.config_service,
                                                 [10L, 20L], project,
                                                 perms).AndReturn([91, 81])

        cols = [
            'IssueSnapshot.issue_id',
        ]
        left_joins = self.defaultLeftJoins
        where = self.defaultWheres
        group_by = None
        stmt, stmt_args = self.services.chart._BuildSnapshotQuery(cols,
                                                                  where,
                                                                  left_joins,
                                                                  group_by,
                                                                  shard_id=0)

        self.services.chart._QueryToWhere(mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(), mox.IgnoreArg(),
                                          mox.IgnoreArg(),
                                          mox.IgnoreArg()).AndReturn(
                                              ([], [], []))
        self.cnxn.Execute(stmt, stmt_args, shard_id=0).AndReturn([])

        self._verifySQL(cols, left_joins, where)

        self.mox.ReplayAll()
        self.services.chart.QueryIssueSnapshots(self.cnxn,
                                                self.services,
                                                unixtime=1514764800,
                                                effective_ids=[10, 20],
                                                project=project,
                                                perms=perms,
                                                group_by=None,
                                                label_prefix='Foo')
        self.mox.VerifyAll()
示例#7
0
  def testGetPersonalAtRiskLabelIDs_UserWithRVG(self):
    """Test returns restricted label IDs a logged in user cannot access."""
    self.mox.StubOutWithMock(self.config_service, 'GetLabelDefRowsAnyProject')
    self.config_service.GetLabelDefRowsAnyProject(
      self.cnxn, where=[('LOWER(label) LIKE %s', ['restrict-view-%'])]
    ).AndReturn([
      (123, 789, 0, 'Restrict-View-Google', 'docstring', 0),
      (124, 789, 0, 'Restrict-View-SecurityTeam', 'docstring', 0),
    ])

    self.mox.ReplayAll()
    perms = permissions.PermissionSet(['Google'])
    ids = search_helpers.GetPersonalAtRiskLabelIDs(
      self.cnxn,
      self.user,
      self.config_service,
      effective_ids=[10, 20],
      project=fake.Project(project_id=789),
      perms=perms)
    self.mox.VerifyAll()

    self.assertEqual(ids, [124])