Skip to content

Commit

Permalink
Test jira issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryneeverett committed Apr 30, 2016
1 parent 399597c commit ff6b060
Showing 1 changed file with 55 additions and 18 deletions.
73 changes: 55 additions & 18 deletions tests/test_jira.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,78 @@
from collections import namedtuple

import mock

from bugwarrior.services.jira import JiraService

from .base import ServiceTest


class FakeJiraClient(object):
def __init__(self, arbitrary_record):
self.arbitrary_record = arbitrary_record

def search_issues(self, *args, **kwargs):
Case = namedtuple('Case', ['raw', 'key'])
return [Case(self.arbitrary_record, self.arbitrary_record['key'])]

def comments(self, *args, **kwargs):
return None


class TestJiraIssue(ServiceTest):
SERVICE_CONFIG = {
'jira.username': 'one',
'jira.base_uri': 'two',
'jira.password': 'three',
}

arbitrary_estimation = 3600
arbitrary_id = '10'
arbitrary_project = 'DONUT'
arbitrary_summary = 'lkjaldsfjaldf'

arbitrary_record = {
'fields': {
'priority': 'Blocker',
'summary': arbitrary_summary,
'timeestimate': arbitrary_estimation,
},
'key': '%s-%s' % (arbitrary_project, arbitrary_id, ),
}

def setUp(self):
with mock.patch('jira.client.JIRA._get_json'):
self.service = self.get_mock_service(JiraService)

def get_mock_service(self, *args, **kwargs):
service = super(TestJiraIssue, self).get_mock_service(*args, **kwargs)
service.jira = FakeJiraClient(self.arbitrary_record)
return service

def test_to_taskwarrior(self):
arbitrary_project = 'DONUT'
arbitrary_id = '10'
arbitrary_url = 'http://one'
arbitrary_summary = 'lkjaldsfjaldf'
arbitrary_estimation = 3600
arbitrary_record = {
'fields': {
'priority': 'Blocker',
'summary': arbitrary_summary,
'timeestimate': arbitrary_estimation,
},
'key': '%s-%s' % (arbitrary_project, arbitrary_id, ),
}
arbitrary_extra = {
'jira_version': 5,
'annotations': ['an annotation'],
}

issue = self.service.get_issue_for_record(
arbitrary_record, arbitrary_extra
self.arbitrary_record, arbitrary_extra
)

expected_output = {
'project': arbitrary_project,
'project': self.arbitrary_project,
'priority': (
issue.PRIORITY_MAP[arbitrary_record['fields']['priority']]
issue.PRIORITY_MAP[self.arbitrary_record['fields']['priority']]
),
'annotations': arbitrary_extra['annotations'],
'tags': [],

issue.URL: arbitrary_url,
issue.FOREIGN_ID: arbitrary_record['key'],
issue.SUMMARY: arbitrary_summary,
issue.FOREIGN_ID: self.arbitrary_record['key'],
issue.SUMMARY: self.arbitrary_summary,
issue.DESCRIPTION: None,
issue.ESTIMATE: arbitrary_estimation / 60 / 60,
issue.ESTIMATE: self.arbitrary_estimation / 60 / 60,
}

def get_url(*args):
Expand All @@ -61,3 +82,19 @@ def get_url(*args):
actual_output = issue.to_taskwarrior()

self.assertEqual(actual_output, expected_output)

def test_issues(self):
issue = next(self.service.issues())

self.assertEqual(issue['jiraurl'], 'two/browse/DONUT-10')
self.assertEqual(issue['priority'], 'H')
self.assertEqual(
issue['description'],
'(bw)Is#10 - lkjaldsfjaldf .. two/browse/DONUT-10')
self.assertEqual(issue['tags'], [])
self.assertEqual(issue['jiradescription'], None)
self.assertEqual(issue['jiraid'], 'DONUT-10')
self.assertEqual(issue['project'], 'DONUT')
self.assertEqual(issue['jiraestimate'], 1)
self.assertEqual(issue['jirasummary'], 'lkjaldsfjaldf')
self.assertEqual(issue['annotations'], [])

0 comments on commit ff6b060

Please sign in to comment.