Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #83 from getsentry/expand-tests
Browse files Browse the repository at this point in the history
Fixes + Tests
  • Loading branch information
dcramer committed Feb 17, 2016
2 parents 8ed61df + 60754a1 commit 1caaedb
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 24 deletions.
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
pytest_plugins = [
'sentry.utils.pytest'
]


def pytest_configure(config):
from django.conf import settings
settings.INSTALLED_APPS += ('sentry_jira',)
10 changes: 7 additions & 3 deletions sentry_jira/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import absolute_import

import logging

from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django import forms
Expand Down Expand Up @@ -175,6 +178,7 @@ def clean(self):
" to enter a CAPTCHA in JIRA to re-enable API"
" logins." % e.status_code)
else:
logging.exception(e)
raise ValidationError("Unable to connect to JIRA: Bad Response")
if not sut_response.json:
raise ValidationError("Unable to connect to JIRA: Bad Response")
Expand Down Expand Up @@ -206,7 +210,7 @@ class JIRAIssueForm(forms.Form):
)

def __init__(self, *args, **kwargs):
self.ignored_fields = kwargs.pop("ignored_fields")
self.ignored_fields = set((kwargs.pop("ignored_fields") or '').split(","))
initial = kwargs.get("initial")
jira_client = kwargs.pop("jira_client")
project_key = kwargs.pop("project_key")
Expand All @@ -228,7 +232,7 @@ def __init__(self, *args, **kwargs):
return

# Early exit #2, no projects available.
if len(meta["projects"]) is 0:
if len(meta["projects"]) == 0:
super(JIRAIssueForm, self).__init__(*args, **kwargs)
self.errors["__all__"] = [
"Error in JIRA configuration, no projects found for user %s.".format(jira_client.username)
Expand Down Expand Up @@ -270,7 +274,7 @@ def __init__(self, *args, **kwargs):
dynamic_fields.sort(key=lambda f: anti_gravity.get(f) or 0)
# build up some dynamic fields based on required shit.
for field in dynamic_fields:
if field in self.fields.keys() or field in [x.strip() for x in self.ignored_fields.split(",")]:
if field in self.fields.keys() or field in [x.strip() for x in self.ignored_fields]:
# don't overwrite the fixed fields for the form.
continue
mb_field = self.build_dynamic_field(self.issue_type["fields"][field])
Expand Down
6 changes: 5 additions & 1 deletion sentry_jira/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from requests.exceptions import RequestException
from requests.exceptions import ConnectionError, RequestException
from sentry.http import build_session
from sentry.utils import json
from sentry.utils.cache import cache
Expand Down Expand Up @@ -140,8 +140,12 @@ def make_request(self, method, url, payload=None):
r = session.post(
url, json=payload, auth=auth,
verify=False, timeout=self.HTTP_TIMEOUT)
except ConnectionError as e:
raise JIRAError(unicode(e))
except RequestException as e:
resp = e.response
if not resp:
raise JIRAError('Internal Error')
if resp.status_code == 401:
raise JIRAUnauthorized.from_response(resp)
raise JIRAError.from_response(resp)
Expand Down
8 changes: 7 additions & 1 deletion sentry_jira/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,14 @@ def post_process(self, group, event, is_new, is_sample, **kwargs):
if not (default_priority and default_issue_type and default_project):
return

jira_client = self.get_jira_client(group.project)
meta = jira_client.get_create_meta(default_project).json
if not meta or len(meta["projects"]) == 0:
return
project = meta["projects"][0]

post_data = {
'project': {'id': default_project},
'project': {'id': project},
'summary': initial['summary'],
'description': initial['description'],
}
Expand Down

0 comments on commit 1caaedb

Please sign in to comment.