Example #1
0
    def clean(self):
        """
        try and build a JIRAClient and make a random call to make sure the
        configuration is right.
        """
        cd = self.cleaned_data

        missing_fields = False
        if not cd.get("instance_url"):
            self.errors["instance_url"] = ["Instance URL is required"]
            missing_fields = True
        if not cd.get("username"):
            self.errors["username"] = ["Username is required"]
            missing_fields = True
        if missing_fields:
            raise ValidationError("Missing Fields")

        jira = JIRAClient(cd["instance_url"], cd["username"], cd["password"])
        sut_response = jira.get_priorities()
        if sut_response.status_code == 403 or sut_response.status_code == 401:
            self.errors["username"] = ["Username might be incorrect"]
            self.errors["password"] = ["Password might be incorrect"]
            raise ValidationError("Unable to connect to JIRA: %s, if you have "
                                  "tried and failed multiple times you may have"
                                  " to enter a CAPTCHA in JIRA to re-enable API"
                                  " logins." % sut_response.status_code)
        elif sut_response.status_code == 500 or sut_response.json is None:
            raise ValidationError("Unable to connect to JIRA: Bad Response")
        elif sut_response.status_code > 200:
            raise ValidationError("Unable to connect to JIRA: %s" % sut_response.status_code)

        return cd
Example #2
0
    def clean(self):
        """
        try and build a JIRAClient and make a random call to make sure the
        configuration is right.
        """
        cd = self.cleaned_data

        missing_fields = False
        if not cd.get("instance_url"):
            self.errors["instance_url"] = ["Instance URL is required"]
            missing_fields = True
        if not cd.get("username"):
            self.errors["username"] = ["Username is required"]
            missing_fields = True
        if missing_fields:
            raise ValidationError("Missing Fields")

        jira = JIRAClient(cd["instance_url"], cd["username"], cd["password"])
        sut_response = jira.get_priorities()
        if sut_response.status_code == 403 or sut_response.status_code == 401:
            self.errors["username"] = ["Username might be incorrect"]
            self.errors["password"] = ["Password might be incorrect"]
            raise ValidationError(
                "Unable to connect to JIRA: %s, if you have "
                "tried and failed multiple times you may have"
                " to enter a CAPTCHA in JIRA to re-enable API"
                " logins." % sut_response.status_code)
        elif sut_response.status_code == 500 or sut_response.json is None:
            raise ValidationError("Unable to connect to JIRA: Bad Response")
        elif sut_response.status_code > 200:
            raise ValidationError("Unable to connect to JIRA: %s" %
                                  sut_response.status_code)

        return cd
Example #3
0
    def __init__(self, *args, **kwargs):
        super(JIRAOptionsForm, self).__init__(*args, **kwargs)

        initial = kwargs.get("initial")
        if initial:
            # make a connection to JIRA to fetch a default project.
            jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password"))
            projects = jira.get_projects_list()
            if projects:
                project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects]
                self.fields["default_project"].choices = project_choices
            else:
                del self.fields["default_project"]
        else:
            del self.fields["default_project"]
Example #4
0
    def __init__(self, *args, **kwargs):
        super(JIRAOptionsForm, self).__init__(*args, **kwargs)

        initial = kwargs.get("initial")
        project_safe = False
        if initial:
            # make a connection to JIRA to fetch a default project.
            jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password"))
            projects_response = jira.get_projects_list()
            if projects_response.status_code == 200:
                projects = projects_response.json
                if projects:
                    project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects]
                    project_safe = True
                    self.fields["default_project"].choices = project_choices

        if not project_safe:
            del self.fields["default_project"]
            del self.fields["ignored_fields"]
Example #5
0
    def __init__(self, *args, **kwargs):
        super(JIRAOptionsForm, self).__init__(*args, **kwargs)

        initial = kwargs.get("initial")
        project_safe = False
        if initial:
            # make a connection to JIRA to fetch a default project.
            jira = JIRAClient(initial.get("instance_url"),
                              initial.get("username"), initial.get("password"))
            projects_response = jira.get_projects_list()
            if projects_response.status_code == 200:
                projects = projects_response.json
                if projects:
                    project_choices = [
                        (p.get('key'),
                         "%s (%s)" % (p.get('name'), p.get('key')))
                        for p in projects
                    ]
                    project_safe = True
                    self.fields["default_project"].choices = project_choices

        if not project_safe:
            del self.fields["default_project"]
            del self.fields["ignored_fields"]