示例#1
0
 def test_load_fields_null(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({
         "id": "234",
         "key": "key2",
         "fields": None,
     })
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
     self.assertEqual(ji_1.assignee_name, "")
示例#2
0
 def test_load_description(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({
         "id": "234",
         "key": "key2",
         "fields": {
             "description": "my description",
         }
     })
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
     self.assertEqual(ji_1.description, "my description")
示例#3
0
 def test_load_assignee_displayname(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({
         "id": "234",
         "key": "key2",
         "fields": {
             "assignee": {
                 "displayName": "marvin",
             }
         }
     })
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
     self.assertEqual(ji_1.assignee_name, "marvin")
示例#4
0
def get_jira_issue_info(base_url, ticket_number):
    issue_url = "%s/rest/api/latest/issue/%s" % (base_url, ticket_number)
    response = yield from http_get_request(issue_url)
    if not response:
        return None
    try:
        json_response = json.loads(response)
        jira_issue = JiraIssue()
        jira_issue.load(json_response)
    except (ValueError, KeyError, TypeError):
        log.error("Error parsing json response from jira")
        log.error(traceback.format_exc())
        return None
    return jira_issue
示例#5
0
 def test_send_issue(self):
     issue = JiraIssue(key="JIRA-9",
                       summary="this is the problem",
                       description="detailed description here")
     expected_attachment = SlackAttachment(
         color="#A4ADAD",
         fallback="JIRA-9: this is the problem",
         text="detailed description here",
         mrkdwn_in=['text'],
         thumb_url=
         "https://slack.global.ssl.fastly.net/12d4/img/services/jira_48.png",  # NOQA
         title="JIRA-9: this is the problem",
         title_link="https://jira.atlassian.com/browse/JIRA-9")
     yield from self.send_response(self.slack_connection, "#work",
                                   "https://jira.atlassian.com", issue)
     expected_call = call(
         'chat.postMessage',
         channel="#work",
         attachments=expected_attachment,
         as_user=False,
         username="******",
         icon_url=
         "https://avatars.slack-edge.com/2015-07-31/8502215814_6662f69db3bed43d32e6_48.jpg"  # NOQA
     )
     self.assertEqual(self.mock_api_call.mock_calls, [expected_call])
示例#6
0
class TestJiraIssue(unittest.TestCase):
    def setUp(self):
        self.ji = JiraIssue()
        self.default_gravatar = "https://slack.global.ssl.fastly.net/12d4/img/services/jira_48.png"  # NOQA

    def test_status_color_invalid_id(self):
        color = self.ji.get_status_color(5)
        self.assertEqual(color, "#A4ADAD")

    def test_status_color_valid_id_one(self):
        color = self.ji.get_status_color(2)
        self.assertEqual(color, "#19689C")

    def test_status_color_valid_id_two(self):
        color = self.ji.get_status_color(1)
        self.assertEqual(color, "#A4ADAD")

    def test_gravatar_none(self):
        gravatar = self.ji.parse_jira_base_gravatar_url(None)
        self.assertEqual(gravatar, self.default_gravatar)

    def test_gravatar_empty(self):
        gravatar = self.ji.parse_jira_base_gravatar_url("")
        self.assertEqual(gravatar, self.default_gravatar)

    def test_gravatar_valid_one(self):
        gravatar = self.ji.parse_jira_base_gravatar_url("boocom")
        self.assertEqual(gravatar, "boocom")

    def test_gravatar_valid_two(self):
        g = "https://secure.gravatar.com/avatar/6e80e9c01e8e48e374648e8dadcffa15?d=mm&s=48"  # NOQA
        r = "https://secure.gravatar.com/avatar/6e80e9c01e8e48e374648e8dadcffa15"  # NOQA
        gravatar = self.ji.parse_jira_base_gravatar_url(g)
        self.assertEqual(gravatar, r)
示例#7
0
 def test_invalid_response(self):
     response = {
         "id": "234",
         "key": "key2",
         "fields": {
             "status": {
                 "statusCategory": {
                     "id": 3,
                 }
             }
         }
     }
     expected_issue = JiraIssue(id="234", key="key2")
     expected_issue.status = "#6AC36A"
     self.mock_http.side_effect = [json.dumps(response)]
     issue = yield from self.get_issue(self.base_url, self.ticket_number)
     self.assertEqual(self.mock_http.mock_calls, self.expected_http_calls)
     self.assertEqual(issue, expected_issue)
示例#8
0
 def test_load_status_invalid(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({
         "id": "234",
         "key": "key2",
         "fields": {
             "status": {
                 "statusCategory": {
                     "id": 5,
                 }
             }
         }
     })
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
     self.assertEqual(ji_1.description, "")
     self.assertEqual(ji_1.summary, "")
     self.assertEqual(ji_1.status, "#A4ADAD")
示例#9
0
 def test_load_assignee_avatarurl(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({
         "id": "234",
         "key": "key2",
         "fields": {
             "assignee": {
                 "displayName": "marvin",
                 "avatarUrls": {
                     "48x48": "google.com",
                 }
             }
         }
     })
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
     self.assertEqual(ji_1.assignee_name, "marvin")
     self.assertEqual(ji_1.assignee_gravatar, "google.com")
示例#10
0
 def setUp(self):
     self.ji = JiraIssue()
     self.default_gravatar = "https://slack.global.ssl.fastly.net/12d4/img/services/jira_48.png"  # NOQA
示例#11
0
 def test_load_empty_dict(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({})
     self.assertEqual(ji_1.id, "123")
     self.assertEqual(ji_1.key, "key")
示例#12
0
 def test_load_id_key_present(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({"id": "234", "key": "key2"})
     self.assertEqual(ji_1.id, "234")
     self.assertEqual(ji_1.key, "key2")
示例#13
0
 def test_load_non_present_keys(self):
     ji_1 = JiraIssue(id="123", key="key")
     ji_1.load({"boo": "urns"})
     self.assertEqual(ji_1.id, "123")
     self.assertEqual(ji_1.key, "key")