예제 #1
0
class IssueTestCaseBase(object):
    def setUpProject(self):
        self.user = User.objects.create_user("testuser", "", "password")
        self.another_user = User.objects.create_user("another_user", "", "password")

        self.client.login(username="******", password="******")

        self.project = Project(name="Test Project", issue_key="TESTPROJECT")
        self.project.save()

        self.component_one = Component(name="Component One", project=self.project)
        self.component_one.save()

        self.component_two = Component(name="Component Two", project=self.project)
        self.component_two.save()

        self.version_one = Version(name="Version 1", project=self.project)
        self.version_one.save()

        self.version_two = Version(name="Version 2", project=self.project)
        self.version_two.save()

        self.milestone = Milestone(name="New Milestone")
        self.milestone.save()

    def assertAllEqual(self, cmp, *args):
        for arg in args:
            self.assertEqual(cmp, arg)

    def generate_issue(self, **kwds):
        issue = Issue()
        issue.project = kwds.get("project", self.project)
        issue.summary = kwds.get("summary", random_string(32))
        issue.description = kwds.get("description", random_string())
        issue.steps_to_reproduce = kwds.get("steps_to_reproduce", random_string())
        issue.priority = Priority.objects.get(short_name=kwds.get("priority", random_priority()))
        issue.issue_type = IssueType.objects.get(short_name=kwds.get("issue_type", random_issue_type()))
        issue.status = kwds.get("status", random_status())
        issue.resolution = kwds.get("resolution", random_resolution())
        if issue.status == "OPEN" and not "resolution" in kwds:
            issue.resolution = Issue.RESOLUTION_CHOICES[0][0]
        issue.milestone = kwds.get("milestone", self.milestone)
        issue.reporter = kwds.get("reporter", self.user)
        issue.assignee = kwds.get("assignee", self.user)
        issue.save()

        issue.components = kwds.get("components", [self.component_two])
        issue.affects_versions = kwds.get("affects_versions", [self.version_one])
        issue.fix_versions = kwds.get("fix_versions", [self.version_one])

        return issue

    def generate_comment(self, issue, **kwds):
        comment = Comment()
        comment.content = issue
        comment.text = kwds.get("text", random_string())
        comment.author = kwds.get("author", self.user)
        comment.save()

        return comment
예제 #2
0
    def setUpProject(self):
        self.user = User.objects.create_user("testuser", "", "password")
        self.another_user = User.objects.create_user("another_user", "", "password")

        self.client.login(username="******", password="******")

        self.project = Project(name="Test Project", issue_key="TESTPROJECT")
        self.project.save()

        self.component_one = Component(name="Component One", project=self.project)
        self.component_one.save()

        self.component_two = Component(name="Component Two", project=self.project)
        self.component_two.save()

        self.version_one = Version(name="Version 1", project=self.project)
        self.version_one.save()

        self.version_two = Version(name="Version 2", project=self.project)
        self.version_two.save()

        self.milestone = Milestone(name="New Milestone")
        self.milestone.save()
예제 #3
0
    def setUpSecondProject(self):
        project_two = Project(name="Project Two", issue_key="TWO")
        project_two.save()

        c1 = Component(name="Component One", project=project_two)
        c1.save()
        c2 = Component(name="Component Two", project=project_two)
        c2.save()
        v1 = Version(name="Version Two One.0", project=project_two)
        v1.save()
        v2 = Version(name="Version Two Two.0", project=project_two)
        v2.save()

        self.project_two = project_two
        self.project_two_component_one = c1
        self.project_two_component_two = c2
        self.project_two_version_one = v1
        self.project_two_component_two = v2
예제 #4
0
    def setUpSecondProject(self):
        project_two = Project(name="Project Two", issue_key="TWO")
        project_two.save()

        component_one = Component(name="Component One", project=project_two)
        component_one.save()
        component_two = Component(name="Component Two", project=project_two)
        component_two.save()

        version_one = Version(name="Version Two One.0", project=project_two)
        version_one.save()
        version_two = Version(name="Version Two Two.0", project=project_two)
        version_two.save()

        self.project_two = project_two
        self.project_two_component_one = component_one
        self.project_two_component_two = component_two
        self.project_two_version_one = version_one
        self.project_two_component_two = version_two
예제 #5
0
    def handle(self, *args, **options):
        def log(msg):
            sys.stdout.write(msg)
            sys.stdout.flush()

        print(args, options)

        print("Setting up project key maps.")
        project_key_map_args = options.get("project_key_map") or []
        project_key_map = self.split_key_value_pairs(project_key_map_args)
        print(project_key_map)

        print("Initializing username mappings")
        user_name_map = self.split_key_value_pairs(options.get("user_map") or [])
        user_map = {}

        print("Initializing priority mappings.")
        priority_name_map = self.default_priority_map
        priority_map = {k: Priority.objects.get(short_name=v) for k, v in priority_name_map.items()}

        print("Initializing resolution mappings.")
        resolution_map = self.default_resolution_map
        status_map = self.default_status_map

        print("Initializing issue type mappings.")
        issue_type_name_map = self.default_issue_type_map
        issue_type_map = {k: IssueType.objects.get(short_name=v) for k, v in issue_type_name_map.items()}
        default_issue_type = issue_type_map[self.default_issue_type]

        log_dot = DotLogger()

        cur = None
        try:
            self.create_temporary_tables()

            print("Acquiring connection.")
            conn = connections[options.get("database")]
            cur = conn.cursor()


            print("Importing users.")
            cur.execute("SELECT userid, login_name FROM profiles")
            for row in cur:
                username = user_name_map.get(row[1]) or row[1]

                try:
                    user = User.objects.get(username=username)
                except User.DoesNotExist:
                    try:
                        user = User.objects.get(email=username)
                    except User.DoesNotExist:
                        user = User(username=username, email=row[1], password=username)
                        user.save()

                user_map[row[0]] = user.pk

            print("Importing products as projects.")
            cur.execute("SELECT id, name, description FROM products")
            all_projects = {row[0]: Project(name=row[1], description=row[2]) for row in cur}

            import_projects(all_projects.values(), project_key_map)

            print("Importing versions.")
            cur.execute("SELECT id, value, product_id from versions")
            for row in cur:
                project = all_projects.get(row[2])
                version = Version(name=row[1], description="Autoimport from bugzilla.", project=project)
                version.save()

            print("Importing components.")
            cur.execute("SELECT id, name, description, product_id from components")
            for row in cur:
                project = all_projects.get(row[-1])
                component = Component(name=row[1], description=row[2], project=project)
                component.save()

            print("Importing issues.")
            print("starting query")
            issue_type_field_clause = ", cf_issue_type AS issue_type"
            cur.execute("""
                SELECT bug.bug_id AS id,
                       assignee.login_name AS assignee,
                       bug.product_id AS product_id,
                       bug.bug_severity AS priority,
                       bug.bug_status AS status,
                       bug.creation_ts AS creation_time,
                       bug.delta_ts AS delta_time,
                       bug.short_desc AS summary,
                       reporter.login_name AS reporter,
                       bug.version AS version_name,
                       c.name AS component_name,
                       bug.lastdiffed AS last_changed,
                       bug.resolution AS resolution
                       {0}
                FROM bugs bug
                JOIN profiles assignee ON bug.assigned_to = assignee.userid
                JOIN profiles reporter ON bug.reporter = reporter.userid
                LEFT JOIN components c ON bug.component_id = c.id
            """.format(issue_type_field_clause))
            print("query done")

            for row in rowdict_cursor(cur):
                assignee = User.objects.get(email=row["assignee"])
                project = all_projects[row["product_id"]]
                priority = priority_map[row["priority"]]
                status = status_map[row["status"]]
                creation_time = row["creation_time"]
                delta_time = row["delta_time"]
                summary = row["summary"]
                reporter = User.objects.get(email=row["reporter"])
                version = project.version_set.get(name=row["version_name"])
                component = project.component_set.get(name=row["component_name"])
                last_changed = row["last_changed"]
                resolution = resolution_map[row["resolution"]]
                issue_type = issue_type_map.get(row["issue_type"], default_issue_type)

                issue = Issue()
                issue.project = project
                issue.issue_type = issue_type
                issue.assignee = assignee
                issue.reporter = reporter
                issue.priority = priority
                issue.summary = summary
                issue.status = status
                issue.resolution = resolution
                issue.reported = creation_time
                issue.last_updated = last_changed
                issue.save(update_timestamps=False)

                issue.affects_versions = [version]
                issue.fix_versions = [version]
                issue.components = [component]

                bugzilla_map = BugzillaIssueMap()
                bugzilla_map.issue = issue
                bugzilla_map.bugzilla_id = row["id"]
                bugzilla_map.save()

                log_dot()

            print("")
            print("Importing comments.")
            cur.execute("""
                SELECT d.bug_id AS bug,
                       p.login_name AS user_email,
                       d.bug_when AS timestamp,
                       d.thetext AS description
                FROM longdescs d
                JOIN profiles p ON d.who = p.userid
                ORDER BY bug
            """)
            for row in rowdict_cursor(cur):
                bugzilla_map = BugzillaIssueMap.objects.get(bugzilla_id=row["bug"])
                author = User.objects.get(email=row["user_email"])
                timestamp = row["timestamp"]
                text = row["description"]

                if text:
                    if timestamp == bugzilla_map.issue.reported:
                        bugzilla_map.issue.description += text
                        bugzilla_map.issue.save(update_timestamps=False)
                    else:
                        comment = Comment()
                        comment.content = bugzilla_map.issue
                        comment.text = text
                        comment.author = author
                        comment.created = timestamp
                        comment.updated = timestamp
                        comment.save(update_timestamps=False)

                log_dot()

        finally:
            if cur is not None:
                cur.close()