Exemplo n.º 1
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue1.json", 'r', encoding='utf-8') as \
                issue_1_file:
            self.issue_1 = json.load(issue_1_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95.json", 'r', encoding='utf-8') as \
                issue_95_file:
            self.issue_95 = json.load(issue_95_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95_comments.json", 'r', encoding='utf-8') as \
                issue_95_comments_file:
            self.issue_95_comments = json.load(issue_95_comments_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/issue95_history.json", 'r', encoding='utf-8') as \
                issue_95_history_file:
            self.issue_95_history = json.load(issue_95_history_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/conor_apache_org_user.json", 'r', encoding='utf-8') as \
                conor_user_file:
            self.conor_user = json.load(conor_user_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/dev_tomcat_apache_org_user.json", 'r', encoding='utf-8') as \
                dev_tomcat_file:
            self.dev_tomcat_file = json.load(dev_tomcat_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/bugzilla/craig_mcclanahan_user.json", 'r', encoding='utf-8') as \
                craig_user_file:
            self.craig_user = json.load(craig_user_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(
            os.path.dirname(os.path.realpath(__file__)) +
            "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'],
                username=config['Database']['db_user'],
                password=config['Database']['db_password'],
                host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Bla').save().id
        self.issues_system_id = IssueSystem(
            project_id=self.project_id,
            url="https://issues.apache.org/search?jql=project=BLA",
            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(None, None, None, None, None, None, 'Bla',
                               'Nonsense?product=Blub', 'bugzilla', None, None,
                               None, None, None, None, 'DEBUG', '123')
Exemplo n.º 2
0
    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"
        )
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/people.json", 'r', encoding='utf-8') as people_file:
            self.person = json.load(people_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131.json", 'r', encoding='utf-8') as issues_file:
            self.issue_6131 = json.load(issues_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131_events.json", 'r', encoding='utf-8') as event_file:
            self.events_issue_6131 = json.load(event_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6131_comments.json", 'r', encoding='utf-8') as cmt_file:
            self.comments_issue_6131 = json.load(cmt_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050.json", 'r', encoding='utf-8') as issues_file:
            self.issue_6050 = json.load(issues_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050_events.json", 'r', encoding='utf-8') as event_file:
            self.events_issue_6050 = json.load(event_file)

        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/github/issue_6050_comments.json", 'r', encoding='utf-8') as cmt_file:
            self.comments_issue_6050 = json.load(cmt_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(os.path.dirname(os.path.realpath(__file__)) + "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'], username=config['Database']['db_user'],
                password=config['Database']['db_password'], host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Composer').save().id
        self.issues_system_id = IssueSystem(project_id=self.project_id, url="http://blub.de",
                                            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(None, None, None, None, None, None, 'Ant', 'http://blub.de', 'github', None, None, None,
                               None, None, None, 'DEBUG', '123')
Exemplo n.º 5
0
    def _process_comments(self, mongo_issue_id, comments):
        """
        Processes the comments for an issue

        :param mongo_issue_id: Object of class :class:`bson.objectid.ObjectId`. Identifier of the document that holds \
        the issue information
        :param comments: comments that were received from the bugzilla API
        """
        # Go through all comments of the issue
        comments_to_insert = []
        logger.info('Processing %d comments...' % (len(comments) - 1))
        i = -1
        for comment in comments:
            # Comment with count 0 is the description of the bug
            if comment['count'] == 0:
                continue

            i += 1
            logger.debug('Processing comment: %s' % comment)
            unique_comment_id = "%s%%%s" % (mongo_issue_id, i)
            try:
                IssueComment.objects(external_id=unique_comment_id,
                                     issue_id=mongo_issue_id).get()
                continue
            except DoesNotExist:
                mongo_comment = IssueComment(
                    external_id=unique_comment_id,
                    issue_id=mongo_issue_id,
                    created_at=dateutil.parser.parse(comment['creation_time']),
                    author_id=self._get_people(comment['creator']),
                    comment=comment['text'],
                )
                logger.debug('Resulting comment: %s' % mongo_comment)
                comments_to_insert.append(mongo_comment)

        # If comments need to be inserted -> bulk insert
        if comments_to_insert:
            IssueComment.objects.insert(comments_to_insert, load_bulk=False)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def setUp(self):
        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_1_issue.json",
                  'r',
                  encoding='utf-8') as drill_1:
            self.issue_drill_1 = json.load(drill_1)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_138_issue.json",
                  'r',
                  encoding='utf-8') as drill_138:
            self.issue_drill_138 = json.load(drill_138)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/drill_38_issue.json",
                  'r',
                  encoding='utf-8') as drill_38:
            self.issue_drill_38 = json.load(drill_38)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/get_user1.json",
                  'r',
                  encoding='utf-8') as user1_file:
            self.user1 = json.load(user1_file)

        with open(os.path.dirname(os.path.realpath(__file__)) +
                  "/data/jira/get_user2.json",
                  'r',
                  encoding='utf-8') as user2_file:
            self.user2 = json.load(user2_file)

        # Create testconfig
        config = configparser.ConfigParser()
        config.read(
            os.path.dirname(os.path.realpath(__file__)) +
            "/data/used_test_config.cfg")

        # Setting up database with data that is normally put into it via vcs program
        connect(config['Database']['db_database'],
                username=config['Database']['db_user'],
                password=config['Database']['db_password'],
                host=config['Database']['db_hostname'],
                port=int(config['Database']['db_port']),
                authentication_source=config['Database']['db_authentication'],
                connect=False)

        Project.drop_collection()
        IssueSystem.drop_collection()
        Issue.drop_collection()
        IssueComment.drop_collection()
        Event.drop_collection()

        self.project_id = Project(name='Bla').save().id
        self.issues_system_id = IssueSystem(
            project_id=self.project_id,
            url="https://issues.apache.org/search?jql=project=BLA",
            last_updated=datetime.datetime.now()).save().id

        self.conf = ConfigMock(
            None, None, None, None, None, None, 'Bla',
            'https://issues.apache.org/search?jql=project=BLA', 'jira', None,
            None, None, None, None, None, 'DEBUG', '123')