Exemplo n.º 1
0
  def setUp(self):
    super(TestProcessIssue, self).setUp()
    now = datetime.datetime.utcnow()
    self.now = datetime.datetime(
        year=now.year, month=now.month, day=now.day, hour=10)
    self.today = self.now.date()
    self.messages = []

    self.owner = '*****@*****.**'
    self.owner_user = User(self.owner)
    self.owner_account = models.Account.get_account_for_user(self.owner_user)

    self.issue = models.Issue(owner=self.owner_user, subject='World domination')
    self.issue.put()

    self.reviewer = '*****@*****.**'
    self.reviewer_user = User(self.reviewer)
    self.reviewer_account = models.Account.get_account_for_user(
        self.reviewer_user)
    # Real users have created at least one issue.
    models.Issue(owner=self.reviewer_user, subject='Damned').put()

    self.slacker = '*****@*****.**'
    self.slacker_user = User(self.slacker)
    self.slacker_account = models.Account.get_account_for_user(
        self.slacker_user)
    # Real users have created at least one issue.
    models.Issue(owner=self.slacker_user, subject='I\'m slacking').put()

    # Sadly mailing lists have accounts too. BUT, these accounts have never
    # created an issue.
    self.ml = '*****@*****.**'
    self.ml_user = User(self.ml)
    self.ml_account = models.Account.get_account_for_user(self.ml_user)
Exemplo n.º 2
0
 def setUp(self):
     super(TestIncomingMail, self).setUp()
     self.login('*****@*****.**')
     self.issue = models.Issue(subject='test')
     self.issue.put()
     self.issue2 = models.Issue(subject='test2')
     self.issue2.put()
     self.logout()
Exemplo n.º 3
0
 def setUp(self):
   super(TestDailyStats, self).setUp()
   self.author = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.reviewer1 = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.reviewer2 = models.Account.get_account_for_user(
       User('*****@*****.**'))
   # Real users have created at least one issue.
   models.Issue(owner=self.author.user, subject='Damned').put()
   models.Issue(owner=self.reviewer1.user, subject='Damned').put()
   models.Issue(owner=self.reviewer2.user, subject='Damned').put()
Exemplo n.º 4
0
 def test_empty_patch(self):
     issue = models.Issue(subject="test with 0 lines")
     issue.local_base = False
     issue.put()
     added, removed = views._get_modified_counts(issue)
     self.assertEqual(0, added)
     self.assertEqual(0, removed)
Exemplo n.º 5
0
 def test_schedule(self):
   put_builds_response = {
     'results': [
       {
         'build': {'id': '1'},
       },
       {
         'build': {'id': '1'},
       },
     ]
   }
   self.fake_responses = [
     {'token': 'deltok', 'delegationSubtoken': {'validityDuration': 18000}},
     put_builds_response,
   ]
   issue = models.Issue(
       id='123',
       project='chromium',
       owner=users.User(email='*****@*****.**'),
   )
   builds = buildbucket.schedule(issue, '1', [
       {'bucket': 'master.tryserver.chromium.linux', 'builder': 'linux_rel'},
       {'bucket': 'master.tryserver.chromium.linux', 'builder': 'linux_debug'},
   ])
   self.assertEqual(
       builds, [r['build'] for r in put_builds_response['results']])
Exemplo n.º 6
0
def issue2(user2, issue_subject, patchset_revision):
    """Test issue, owned by user2."""
    issue = models.Issue(owner=user2,
                         subject=issue_subject,
                         latest_patch_rev=patchset_revision)
    issue.put()
    return issue
Exemplo n.º 7
0
 def setUp(self):
   super(TestMultiStats, self).setUp()
   self.assertEqual([], models.AccountStatsDay.query().fetch())
   self.assertEqual([], models.AccountStatsMulti.query().fetch())
   self.assertEqual(None, models.Issue.query().get())
   self.userA = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.userA_key = self.userA.key
   self.userB = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.userB_key = self.userB.key
   # Real users have created at least one issue.
   models.Issue(owner=self.userA.user, subject='Damned').put()
   models.Issue(owner=self.userB.user, subject='Damned').put()
   self.today = datetime.datetime(2012, 04, 30, 1, 0)
   self.yesterday = self.today - datetime.timedelta(days=1)
Exemplo n.º 8
0
 def setUp(self):
     """Create two test issues and users."""
     super(TestSearch, self).setUp()
     user = User('*****@*****.**')
     models.Account.get_account_for_user(user)
     user = User('*****@*****.**')
     models.Account.get_account_for_user(user)
     self.user = User('*****@*****.**')
     self.login('*****@*****.**')
     issue1 = models.Issue(subject='test')
     issue1.reviewers = ['*****@*****.**', '*****@*****.**']
     issue1.local_base = False
     issue1.put()
     issue2 = models.Issue(subject='test')
     issue2.reviewers = ['*****@*****.**', '*****@*****.**']
     issue2.local_base = False
     issue2.put()
Exemplo n.º 9
0
 def test_both_patch(self):
     issue = models.Issue(subject="test with changes")
     issue.local_base = False
     issue.put()
     ps = models.PatchSet(parent=issue.key, issue_key=issue.key)
     ps.data = self.makePatch(5, 7)
     ps.put()
     patches = engine.ParsePatchSet(ps)
     ndb.put_multi(patches)
     added, removed = views._get_modified_counts(issue)
     self.assertEqual(5, added)
     self.assertEqual(7, removed)
Exemplo n.º 10
0
 def setUp(self):
     super(TestPublish, self).setUp()
     self.user = User('*****@*****.**')
     self.login('*****@*****.**')
     self.issue = models.Issue(subject='test')
     self.issue.local_base = False
     self.issue.put()
     self.ps = models.PatchSet(parent=self.issue, issue=self.issue)
     self.ps.data = load_file('ps1.diff')
     self.ps.save()
     self.patches = engine.ParsePatchSet(self.ps)
     db.put(self.patches)
Exemplo n.º 11
0
 def test_remove_patch(self):
     issue = models.Issue(subject="test with 1 line removed")
     issue.local_base = False
     issue.put()
     ps = models.PatchSet(parent=issue, issue=issue)
     ps.data = self.makePatch(0, 1)
     ps.save()
     patches = engine.ParsePatchSet(ps)
     db.put(patches)
     added, removed = views._get_modified_counts(issue)
     self.assertEqual(0, added)
     self.assertEqual(1, removed)
Exemplo n.º 12
0
def get_issue(request, case_number, case_title):
    """Get/create codereview issue based on fogbugz case information.

    :param case_number: `str` Fogbugz case number
    :param case_title:  `str` Fogbugz case title

    :return: `Issue` object which corresponds to a given case_number.
    """
    log("process_codereview_from_fogbugz(): Querying issues")
    issue_desc_id = '(Case {0}) Review: '.format(case_number)
    issue_desc_complete = issue_desc_id + case_title
    try:
        issue = models.Issue.objects.raw(
            'select * from codereview_issue where subject like "{subject}%%" {options}'.format(
                subject=issue_desc_id,
                options='for update' if 'sqlite' not in django_db.connection.settings_dict['ENGINE'] else ''))[0]
    except IndexError:
        issue = None
    log("Querying users for admin")
    user = request.user or users.User.objects.filter(username='******')[0]
    if issue:
        if issue.closed:
            raise RuntimeError(
                'Issue already closed, cannot be edited anymore.')
        if issue.processing:
            raise RuntimeError('Cannot handle multiple submit requests for the same Fogbugz case.')

        if issue.subject != issue_desc_complete:
            issue.subject = issue_desc_complete

        if issue.description != issue_desc_complete:
            issue.description = issue_desc_complete
    else:
        log("Creating issue instance")
        issue = models.Issue(subject=issue_desc_complete,
                             description=issue_desc_complete,
                             private=False,
                             owner=user,
                             n_comments=0)
        log("Putting instance")

    issue.processing = True
    issue.save()

    return issue
Exemplo n.º 13
0
 def create_issue(self, date, reviewers=None, cc=None):
   """Creates an issue by self.author with self.reviewer1 as a reviewer."""
   date = datetime.datetime.strptime('2011-03-' + date, '%Y-%m-%d %H:%M')
   issue = models.Issue(
       subject='test',
       owner=self.author.user,
       reviewers=[r.email for r in reviewers or [self.reviewer1]],
       cc=[db.Email('*****@*****.**')] + [c.email for c in cc or []],
       created=date,
       modified=date)
   issue.put()
   # Verify that our auto_now hack works.
   self.assertEqual(issue.key.get().created, date)
   self.assertEqual(issue.key.get().modified, date)
   ps = models.PatchSet(
     parent=issue.key, issue_key=issue.key, created=date, modified=date)
   ps.data = utils.load_file('ps1.diff')
   ps.put()
   patches = engine.ParsePatchSet(ps)
   ndb.put_multi(patches)
   return issue
Exemplo n.º 14
0
    # Contents of the revert Issue.
    pending_commits = []

    subject = _get_revert_subject(original_issue.subject)
    revert_reason = request.POST['revert_reason']
    revert_cq = request.POST['revert_cq'] == '1'
    description = _get_revert_description(request, revert_reason, reviewers,
                                          original_issue, original_patch_num,
                                          original_patchset_id)
    issue = models.Issue(
        subject=subject,
        description=description,
        project=original_issue.project,
        base=original_issue.base,
        target_ref=original_issue.target_ref,
        repo_guid=original_issue.repo_guid,
        reviewers=reviewers,
        cc=original_issue.cc,
        private=original_issue.private,
        n_comments=0,
        commit=False,  # Do not check the commit box yet.
        key=issue_key)
    pending_commits.append(issue)

    # Create the new revert patchset to use as the key in the new patches.
    ps_id, _ = models.PatchSet.allocate_ids(1, parent=issue.key)
    ps_key = ndb.Key(models.PatchSet, ps_id, parent=issue.key)
    patchset = models.PatchSet(issue_key=issue.key, url=None, key=ps_key)
    patchset_data = []  # Will be populated with the diff texts of all patches.
    pending_commits.append(patchset)