| 1 |
from builtins import next |
| 2 |
from builtins import str |
| 3 |
from builtins import object |
| 4 |
from unittest import mock |
| 5 |
|
| 6 |
from bugwarrior.services import bts |
| 7 |
|
| 8 |
from .base import ServiceTest, AbstractServiceTest |
| 9 |
|
| 10 |
|
| 11 |
class FakeBTSBug(object): |
| 12 |
bug_num = 810629 |
| 13 |
package = "wnpp" |
| 14 |
subject = ("ITP: bugwarrior -- Pull tickets from github, " |
| 15 |
"bitbucket, bugzilla, jira, trac, and others into " |
| 16 |
"taskwarrior") |
| 17 |
severity = "wishlist" |
| 18 |
source = "" |
| 19 |
forwarded = "" |
| 20 |
pending = "pending" |
| 21 |
|
| 22 |
|
| 23 |
class FakeBTSLib(object): |
| 24 |
def get_bugs(self, *args, **kwargs): |
| 25 |
return [810629] |
| 26 |
|
| 27 |
def get_status(self, bug_num): |
| 28 |
if bug_num == [810629]: |
| 29 |
return [FakeBTSBug] |
| 30 |
|
| 31 |
|
| 32 |
class TestBTSService(AbstractServiceTest, ServiceTest): |
| 33 |
|
| 34 |
maxDiff = None |
| 35 |
|
| 36 |
SERVICE_CONFIG = { |
| 37 |
'bts.email': '[email protected]', |
| 38 |
'bts.packages': 'bugwarrior', |
| 39 |
} |
| 40 |
|
| 41 |
def setUp(self): |
| 42 |
super(TestBTSService, self).setUp() |
| 43 |
self.service = self.get_mock_service(bts.BTSService) |
| 44 |
|
| 45 |
def test_to_taskwarrior(self): |
| 46 |
issue = self.service.get_issue_for_record( |
| 47 |
self.service._record_for_bug(FakeBTSBug) |
| 48 |
) |
| 49 |
|
| 50 |
expected_output = { |
| 51 |
'priority': issue.PRIORITY_MAP[FakeBTSBug.severity], |
| 52 |
'annotations': [], |
| 53 |
|
| 54 |
issue.URL: "https://bugs.debian.org/" + str(FakeBTSBug.bug_num), |
| 55 |
issue.SUBJECT: FakeBTSBug.subject, |
| 56 |
issue.NUMBER: FakeBTSBug.bug_num, |
| 57 |
issue.PACKAGE: FakeBTSBug.package, |
| 58 |
issue.SOURCE: FakeBTSBug.source, |
| 59 |
issue.FORWARDED: FakeBTSBug.forwarded, |
| 60 |
issue.STATUS: FakeBTSBug.pending, |
| 61 |
} |
| 62 |
actual_output = issue.to_taskwarrior() |
| 63 |
|
| 64 |
self.assertEqual(actual_output, expected_output) |
| 65 |
|
| 66 |
def test_issues(self): |
| 67 |
with mock.patch('bugwarrior.services.bts.debianbts', FakeBTSLib()): |
| 68 |
issue = next(self.service.issues()) |
| 69 |
|
| 70 |
expected = { |
| 71 |
'annotations': [], |
| 72 |
'btsnumber': 810629, |
| 73 |
'btsforwarded': '', |
| 74 |
'btspackage': 'wnpp', |
| 75 |
'btssubject': ('ITP: bugwarrior -- Pull tickets from github, ' |
| 76 |
'bitbucket, bugzilla, jira, trac, and others into ' |
| 77 |
'taskwarrior'), |
| 78 |
'btsurl': 'https://bugs.debian.org/810629', |
| 79 |
'btssource': '', |
| 80 |
'description': (u'(bw)Is#810629 - ITP: bugwarrior -- Pull tickets' |
| 81 |
u' from github, bitbucket, bugzilla, jira, trac, ' |
| 82 |
u'and others into taskwa .. https://bugs.debian.o' |
| 83 |
u'rg/810629'), |
| 84 |
'priority': 'L', |
| 85 |
'btsstatus': 'pending', |
| 86 |
u'tags': []} |
| 87 |
|
| 88 |
self.assertEqual(issue.get_taskwarrior_record(), expected) |