File: test_bts.py

package info (click to toggle)
bugwarrior 1.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 9,226; makefile: 147
file content (88 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from builtins import next
from builtins import str
from builtins import object
from unittest import mock

from bugwarrior.services import bts

from .base import ServiceTest, AbstractServiceTest


class FakeBTSBug(object):
    bug_num = 810629
    package = "wnpp"
    subject = ("ITP: bugwarrior -- Pull tickets from github, "
               "bitbucket, bugzilla, jira, trac, and others into "
               "taskwarrior")
    severity = "wishlist"
    source = ""
    forwarded = ""
    pending = "pending"


class FakeBTSLib(object):
    def get_bugs(self, *args, **kwargs):
        return [810629]

    def get_status(self, bug_num):
        if bug_num == [810629]:
            return [FakeBTSBug]


class TestBTSService(AbstractServiceTest, ServiceTest):

    maxDiff = None

    SERVICE_CONFIG = {
        'bts.email': 'irl@debian.org',
        'bts.packages': 'bugwarrior',
    }

    def setUp(self):
        super(TestBTSService, self).setUp()
        self.service = self.get_mock_service(bts.BTSService)

    def test_to_taskwarrior(self):
        issue = self.service.get_issue_for_record(
            self.service._record_for_bug(FakeBTSBug)
        )

        expected_output = {
            'priority': issue.PRIORITY_MAP[FakeBTSBug.severity],
            'annotations': [],

            issue.URL: "https://bugs.debian.org/" + str(FakeBTSBug.bug_num),
            issue.SUBJECT: FakeBTSBug.subject,
            issue.NUMBER: FakeBTSBug.bug_num,
            issue.PACKAGE: FakeBTSBug.package,
            issue.SOURCE: FakeBTSBug.source,
            issue.FORWARDED: FakeBTSBug.forwarded,
            issue.STATUS: FakeBTSBug.pending,
        }
        actual_output = issue.to_taskwarrior()

        self.assertEqual(actual_output, expected_output)

    def test_issues(self):
        with mock.patch('bugwarrior.services.bts.debianbts', FakeBTSLib()):
            issue = next(self.service.issues())

        expected = {
            'annotations': [],
            'btsnumber': 810629,
            'btsforwarded': '',
            'btspackage': 'wnpp',
            'btssubject': ('ITP: bugwarrior -- Pull tickets from github, '
                           'bitbucket, bugzilla, jira, trac, and others into '
                           'taskwarrior'),
            'btsurl': 'https://bugs.debian.org/810629',
            'btssource': '',
            'description': (u'(bw)Is#810629 - ITP: bugwarrior -- Pull tickets'
                            u' from github, bitbucket, bugzilla, jira, trac, '
                            u'and others into taskwa .. https://bugs.debian.o'
                            u'rg/810629'),
            'priority': 'L',
            'btsstatus': 'pending',
            u'tags': []}

        self.assertEqual(issue.get_taskwarrior_record(), expected)