def _transform_issue(self, bz_issue, bz_comments): """ Transforms the issue from an bugzilla issue to our issue model :param bz_issue: bugzilla issue (returned by the API) :param bz_comments: comments to the bugzilla issue (as the first comment is the description of the issue) :return: """ try: mongo_issue = Issue.objects(issue_system_id=self.issue_system_id, external_id=str(bz_issue['id'])).get() except DoesNotExist: mongo_issue = Issue(issue_system_id=self.issue_system_id, external_id=str(bz_issue['id'])) # Set fields that can be directly mapped for at_name_bz, at_name_mongo in self.at_mapping.items(): if isinstance(getattr(mongo_issue, at_name_mongo), list): # Get the result and the current value and merge it together result = self._parse_bz_field(bz_issue, at_name_bz) current_value = getattr(mongo_issue, at_name_mongo, list()) if not isinstance(result, list): result = [result] # Extend current_value.extend(result) if len(current_value) > 0 and at_name_mongo == 'issue_links': current_value = list( {v['issue_id']: v for v in current_value}.values()) else: current_value = list(set(current_value)) # Set the attribute setattr(mongo_issue, at_name_mongo, copy.deepcopy(current_value)) else: setattr(mongo_issue, at_name_mongo, self._parse_bz_field(bz_issue, at_name_bz)) # The first comment is the description! Bugzilla does not have a separate description field. The comment # with the count == 0 is the description for comment in bz_comments: if comment['count'] == 0: mongo_issue.desc = comment['text'] break # If we have a creator, its also the repoerter in bugzilla terminology if bz_issue['creator_detail'] is not None: mongo_issue.reporter_id = mongo_issue.creator_id # moved to its own function, can be deleted later # Bugzilla does not have a separate field for the type. Therefore, we distinguish between bug an enhancement # based on the severity information # if bz_issue['severity'] == 'enhancement': # mongo_issue.issue_type = 'Enhancement' # else: # mongo_issue.issue_type = 'Bug' return mongo_issue.save()
def test_process_comments(self, get_user_mock): bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id, self.project_id) bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf) issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() get_user_mock.side_effect = [self.dev_tomcat_file, self.conor_user] bugzilla_backend._process_comments(issue.id, self.issue_95_comments) all_comments = IssueComment.objects(issue_id=issue.id).all() self.assertEqual(2, len(all_comments)) # comment 1 commenter = People.objects(email="*****@*****.**").get() comment = all_comments[0] self.assertEqual(comment.created_at, datetime.datetime(2001, 2, 4, 6, 20, 32)) self.assertEqual(comment.author_id, commenter.id) self.assertEqual( comment.comment, "I have tested this on NT (JDK 1.1, 1.2.2, 1.3) and Linux " "(Redhat 6.2, JDK \n1.1.2) and could not reproduce this problem. ") # comment 2 commenter = People.objects(email="*****@*****.**").get() comment = all_comments[1] self.assertEqual(comment.created_at, datetime.datetime(2001, 2, 6, 19, 35, 1)) self.assertEqual(comment.author_id, commenter.id) self.assertEqual( comment.comment, "For query purposes, mark as fixed for Tomcat 3.3:\nFixed in Tomcat 3.3\n" )
def test_store_comments(self): issue = jira.resources.Issue(options=None, session=None, raw=self.issue_drill_38) mongo_issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() new_jira_backend = JiraBackend(self.conf, self.issues_system_id, self.project_id) new_jira_backend._store_comments(issue, mongo_issue.id) all_comments = IssueComment.objects(issue_id=mongo_issue.id).all() self.assertEqual(len(all_comments), 4) chris_merrick = People.objects(email="*****@*****.**", username="******").get() chris_merrick2 = People.objects(email="*****@*****.**", username="******").get() timothy_chen = People.objects(email="*****@*****.**").get() jacques_nadeau = People.objects(email="*****@*****.**").get() # comment 1 comment = all_comments[0] self.assertEqual(comment.created_at, datetime.datetime(2013, 2, 24, 2, 13, 0, 18000)) self.assertEqual(comment.author_id, chris_merrick.id) self.assertEqual( comment.comment, "I can't figure out how to assign this to myself " "(not seeing a button anywhere). Can someone either give me permission to do" " that or teach me how to use JIRA? Thanks.") # comment 2 comment = all_comments[1] self.assertEqual(comment.created_at, datetime.datetime(2013, 2, 24, 17, 1, 36, 848000)) self.assertEqual(comment.author_id, timothy_chen.id) self.assertEqual( comment.comment, "You most likely don't have permissions. I don't have permissions to assign " "permissions, so probably either Ted or Jacques can do this. " "I've assigned this task to you.") # comment 3 comment = all_comments[2] self.assertEqual(comment.created_at, datetime.datetime(2013, 2, 24, 17, 43, 36, 857000)) self.assertEqual(comment.author_id, chris_merrick2.id) self.assertEqual( comment.comment, "Submitted pull request: https://github.com/apache/incubator-drill/pull/9" ) # comment 4 comment = all_comments[3] self.assertEqual(comment.created_at, datetime.datetime(2013, 2, 25, 4, 2, 43, 710000)) self.assertEqual(comment.author_id, jacques_nadeau.id) self.assertEqual(comment.comment, "merged")
def test_query_with_issue_available(self): new_jira_backend = JiraBackend(self.conf, self.issues_system_id, self.project_id) current_date = datetime.datetime.now() Issue(issue_system_id=self.issues_system_id, updated_at=current_date).save() self.assertEqual( 'project=BLA and updatedDate > \'%s\' ORDER BY updatedDate ASC' % current_date.strftime('%Y/%m/%d %H:%M'), new_jira_backend._create_issue_query())
def _get_issue_id_by_system_id(self, system_id): """ Gets the issue by their id that was assigned by the bugzilla ITS :param system_id: id of the issue in the bugzilla ITS """ try: issue_id = Issue.objects(issue_system_id=self.issue_system_id, external_id=str(system_id)).only('id').get().id except DoesNotExist: issue_id = Issue(issue_system_id=self.issue_system_id, external_id=str(system_id)).save().id return issue_id
def test_process_comments_two_times(self, get_user_mock): bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id, self.project_id) bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf) issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() get_user_mock.side_effect = [self.dev_tomcat_file, self.conor_user] bugzilla_backend._process_comments(issue.id, self.issue_95_comments) bugzilla_backend._process_comments(issue.id, self.issue_95_comments) self.assertEqual(2, len(IssueComment.objects.all()))
def test_store_comments_two_times(self): issue = jira.resources.Issue(options=None, session=None, raw=self.issue_drill_38) mongo_issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() new_jira_backend = JiraBackend(self.conf, self.issues_system_id, self.project_id) new_jira_backend._store_comments(issue, mongo_issue.id) new_jira_backend._store_comments(issue, mongo_issue.id) all_comments = IssueComment.objects(issue_id=mongo_issue.id).all() self.assertEqual(len(all_comments), 4)
def test_store_events_two_times(self, get_user_mock): bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id, self.project_id) bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf) issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() get_user_mock.side_effect = [ self.craig_user, self.conor_user, self.craig_user, self.conor_user, self.conor_user ] bugzilla_backend._store_events(self.issue_95_history, self.issue_95, issue) bugzilla_backend._store_events(self.issue_95_history, self.issue_95, issue) all_events = Event.objects.all() self.assertEqual(16, len(all_events))
def test_store_events(self, get_user_mock): user1_obj = jira.resources.User(options=None, session=None, raw=self.user1) user2_obj = jira.resources.User(options=None, session=None, raw=self.user2) get_user_mock.side_effect = [user1_obj, user2_obj] new_jira_backend = JiraBackend(self.conf, self.issues_system_id, self.project_id) issue = jira.resources.Issue(options=None, session=None, raw=self.issue_drill_138) mongo_issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() new_jira_backend._store_events(issue, mongo_issue.id) stored_events = Event.objects(issue_id=mongo_issue.id).all() self.assertEqual(24, len(stored_events)) jacques_user = People.objects(email="*****@*****.**", username="******").get() timothy_user = People.objects(email="*****@*****.**", username="******").get() cmerrick_user = People.objects(email="*****@*****.**", username="******").get() # Check each event # Custom event event = stored_events[0] self.assertEqual(event.status, "Target Version/s") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "0.1") self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) # Status event = stored_events[1] self.assertEqual(event.status, "status") self.assertEqual(event.old_value, "Reopened") self.assertEqual(event.new_value, "Resolved") self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) # Resolution event = stored_events[2] self.assertEqual(event.status, "resolution") self.assertEqual(event.old_value, "Test") self.assertEqual(event.new_value, "Fixed") self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) # Attachment event = stored_events[3] self.assertEqual(event.status, "Attachment") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "testfails_ZOOKEEPER-136.patch") self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) event = stored_events[4] self.assertEqual(event.status, "Attachment") self.assertEqual(event.old_value, "testfails_ZOOKEEPER-137.patch") self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) # Link related_issue_1 = Issue.objects(external_id="ZOOKEEPER-232").get() related_issue_2 = Issue.objects(external_id="ZOOKEEPER-231").get() event = stored_events[5] self.assertEqual(event.status, "issue_links") self.assertEqual(event.old_value, None) self.assertEqual( event.new_value, { 'effect': 'relates to', 'issue_id': related_issue_1.id, 'type': 'Reference' }) self.assertEqual(event.created_at, datetime.datetime(2016, 8, 13, 17, 29, 13, 718000)) self.assertEqual(event.author_id, jacques_user.id) event = stored_events[6] self.assertEqual(event.status, "issue_links") self.assertEqual( event.old_value, { 'effect': 'relates to', 'issue_id': related_issue_2.id, 'type': 'Reference' }) self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # assignee assignee_old = People.objects(username="******").get() assignee_new = People.objects(username="******").get() event = stored_events[7] self.assertEqual(event.status, "assignee_id") self.assertEqual(event.old_value, assignee_old.id) self.assertEqual(event.new_value, assignee_new.id) self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # fix version event = stored_events[8] self.assertEqual(event.status, "fix_versions") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "3.6.0") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) event = stored_events[9] self.assertEqual(event.status, "fix_versions") self.assertEqual(event.old_value, "3.5.0") self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # priority event = stored_events[10] self.assertEqual(event.status, "priority") self.assertEqual(event.old_value, "Major") self.assertEqual(event.new_value, "Blocker") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # issue type event = stored_events[11] self.assertEqual(event.status, "issue_type") self.assertEqual(event.old_value, "New Feature") self.assertEqual(event.new_value, "Improvement") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # affects version event = stored_events[12] self.assertEqual(event.status, "affects_versions") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "3.0.0") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) event = stored_events[13] self.assertEqual(event.status, "affects_versions") self.assertEqual(event.old_value, "3.0.1") self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # title event = stored_events[14] self.assertEqual(event.status, "title") self.assertEqual(event.old_value, "Dump of ZooKeeper SVN repository") self.assertEqual(event.new_value, "Initial ZooKeeper code contribution from Yahoo!") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # desc event = stored_events[15] self.assertEqual(event.status, "desc") self.assertEqual( event.old_value, "There are a couple of cases of member variables that need to be marked " "volatile or surrounded in a synchronization block. A couple of examples " "are:\n\n* QuorumPeer state should be synchronous\n* currentVote in " "QuorumPeer is marked volatile, but when it's members are often accessed " "individually as if they were in an atomic unit. Such code should be changed" " to get a reference to the currentVote and they access members through that" " reference.\n") self.assertEqual( event.new_value, "There are a couple of cases of member variables that need to be marked " "volatile or surrounded in a synchronization block. A couple of examples " "are:\n\n* QuorumPeer state should be synchronous\n* currentVote in " "QuorumPeer is marked volatile, but when it's members are often accessed " "individually as if they were in an atomic unit. Such code should be " "changed to get a reference to the currentVote and they access members " "through that reference.\n* It looks like logicalClock in FastLeaderElection" " should be volatile. It should either be fixed or commented to explain why " "it doesn't need to be.") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # labels event = stored_events[16] self.assertEqual(event.status, "labels") self.assertEqual(event.old_value, "newbie") self.assertEqual(event.new_value, "docuentation newbie") self.assertEqual(event.created_at, datetime.datetime(2015, 2, 24, 17, 0, 58, 268000)) self.assertEqual(event.author_id, timothy_user.id) # parent issue id event = stored_events[17] self.assertEqual(event.status, "parent_issue_id") self.assertEqual(event.old_value, related_issue_1.id) self.assertEqual(event.new_value, related_issue_2.id) self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) # environment event = stored_events[18] self.assertEqual(event.status, "environment") self.assertEqual( event.old_value, "Sparc Solaris 10\r\nJava 6u17 64 bits\r\n5 nodes ensemble") self.assertEqual( event.new_value, "Sparc Solaris 10 and 11\r\nJava 6u17 64 bits\r\n5 nodes ensemble") self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) # Custom labels event = stored_events[19] self.assertEqual(event.status, "labels") self.assertEqual(event.old_value, "") self.assertEqual(event.new_value, "zookeeper") self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) event = stored_events[20] self.assertEqual(event.status, "labels") self.assertEqual(event.old_value, "zookeeper1") self.assertEqual(event.new_value, "") self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) # original_time_estimate event = stored_events[21] self.assertEqual(event.status, "original_time_estimate") self.assertEqual(event.old_value, 480) self.assertEqual(event.new_value, 28800) self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) # component event = stored_events[22] self.assertEqual(event.status, "components") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "c client") self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id) event = stored_events[23] self.assertEqual(event.status, "components") self.assertEqual(event.old_value, "python client") self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2014, 2, 24, 17, 43, 46, 87000)) self.assertEqual(event.author_id, cmerrick_user.id)
def test_store_events(self, get_user_mock): bugzilla_backend = BugzillaBackend(self.conf, self.issues_system_id, self.project_id) bugzilla_backend.bugzilla_agent = BugzillaAgent(None, self.conf) issue = Issue(external_id="TEST", issue_system_id=self.issues_system_id).save() get_user_mock.side_effect = [ self.craig_user, self.conor_user, self.craig_user, self.conor_user, self.conor_user ] bugzilla_backend._store_events(self.issue_95_history, self.issue_95, issue) craig_user = People.objects(email="*****@*****.**").get() conor_user = People.objects(email="*****@*****.**").get() all_events = Event.objects.all() self.assertEqual(16, len(all_events)) # assignee_id event = all_events[0] self.assertEqual(event.status, "assignee_id") self.assertEqual(event.old_value, craig_user.id) self.assertEqual(event.new_value, conor_user.id) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # status event = all_events[1] self.assertEqual(event.status, "status") self.assertEqual(event.old_value, "NEW") self.assertEqual(event.new_value, "UNCONFIRMED") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # component event = all_events[2] self.assertEqual(event.status, "components") self.assertEqual(event.old_value, "Other") self.assertEqual(event.new_value, "Core tasks") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # labels event = all_events[3] self.assertEqual(event.status, "labels") self.assertEqual(event.old_value, "85") self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # labels event = all_events[4] self.assertEqual(event.status, "labels") self.assertEqual(event.old_value, None) self.assertEqual(event.new_value, "PatchAvailable") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # environment event = all_events[5] self.assertEqual(event.status, "environment") self.assertEqual(event.old_value, "Windows") self.assertEqual(event.new_value, "All") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # platform event = all_events[6] self.assertEqual(event.status, "platform") self.assertEqual(event.old_value, "OSX") self.assertEqual(event.new_value, "All") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # affects versions event = all_events[7] self.assertEqual(event.status, "affects_versions") self.assertEqual(event.old_value, "3.1") self.assertEqual(event.new_value, "1.2") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # resolution event = all_events[8] self.assertEqual(event.status, "resolution") self.assertEqual(event.old_value, "NOTHING") self.assertEqual(event.new_value, "WORKSFORME") self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # depends_on / issue_links related_issue_41817 = Issue.objects(external_id="41817").get() event = all_events[9] self.assertEqual(event.status, "issue_links") self.assertEqual(event.old_value, None) self.assertEqual( event.new_value, { 'issue_id': related_issue_41817.id, 'type': 'Dependent', 'effect': 'depends on' }) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # depends_on / issue_links related_issue_41818 = Issue.objects(external_id="41818").get() event = all_events[10] self.assertEqual(event.status, "issue_links") self.assertEqual( event.old_value, { 'issue_id': related_issue_41818.id, 'type': 'Dependent', 'effect': 'depends on' }) self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) # blocks / issue_links event = all_events[11] self.assertEqual(event.status, "issue_links") self.assertEqual(event.old_value, None) self.assertEqual( event.new_value, { 'issue_id': related_issue_41817.id, 'type': 'Blocker', 'effect': 'blocks' }) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 3, 17, 48, 45)) self.assertEqual(event.author_id, craig_user.id) ############ # blocks / issue_links event = all_events[12] self.assertEqual(event.status, "issue_links") self.assertEqual( event.old_value, { 'issue_id': related_issue_41818.id, 'type': 'Blocker', 'effect': 'blocks' }) self.assertEqual(event.new_value, None) self.assertEqual(event.created_at, datetime.datetime(2001, 2, 4, 6, 20, 32)) self.assertEqual(event.author_id, conor_user.id) ############# # title event = all_events[13] self.assertEqual(event.status, "title") self.assertEqual( event.old_value, "cvschangelog task: CVS log date output format changed on CVS 1.12.9 " ) self.assertEqual( event.new_value, "cvschangelog task: CVS log date output format changed on CVS 1.12.9" ) self.assertEqual(event.created_at, datetime.datetime(2001, 3, 2, 5, 0, 52)) self.assertEqual(event.author_id, conor_user.id) # fix_versions event = all_events[14] self.assertEqual(event.status, "fix_versions") self.assertEqual(event.old_value, "---") self.assertEqual(event.new_value, "1.7") self.assertEqual(event.created_at, datetime.datetime(2001, 3, 2, 5, 0, 52)) self.assertEqual(event.author_id, conor_user.id) # priority event = all_events[15] self.assertEqual(event.status, "priority") self.assertEqual(event.old_value, "major") self.assertEqual(event.new_value, "enhancement") self.assertEqual(event.created_at, datetime.datetime(2001, 3, 2, 5, 0, 52)) self.assertEqual(event.author_id, conor_user.id)