File: test_bitbucket.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 (166 lines) | stat: -rw-r--r-- 5,569 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from __future__ import unicode_literals
import unittest

import responses

from bugwarrior.services.bitbucket import BitbucketService

from .base import ServiceTest, AbstractServiceTest


class TestBitbucketIssue(AbstractServiceTest, ServiceTest):
    SERVICE_CONFIG = {
        'bitbucket.login': 'something',
        'bitbucket.username': 'somename',
        'bitbucket.password': 'something else',
    }

    def setUp(self):
        super(TestBitbucketIssue, self).setUp()
        self.service = self.get_mock_service(BitbucketService)

    def test_to_taskwarrior(self):
        arbitrary_issue = {
            'priority': 'trivial',
            'id': '100',
            'title': 'Some Title',
        }
        arbitrary_extra = {
            'url': 'http://hello-there.com/',
            'project': 'Something',
            'annotations': [
                'One',
            ]
        }

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

        expected_output = {
            'project': arbitrary_extra['project'],
            'priority': issue.PRIORITY_MAP[arbitrary_issue['priority']],
            'annotations': arbitrary_extra['annotations'],

            issue.URL: arbitrary_extra['url'],
            issue.FOREIGN_ID: arbitrary_issue['id'],
            issue.TITLE: arbitrary_issue['title'],
        }
        actual_output = issue.to_taskwarrior()

        self.assertEqual(actual_output, expected_output)

    @responses.activate
    def test_issues(self):
        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/',
            json={'values': [{
                'full_name': 'somename/somerepo',
                'has_issues': True
            }]})

        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/',
            json={'values': [{
                'title': 'Some Bug',
                'status': 'open',
                'links': {'html': {'href': 'example.com'}},
                'id': 1
            }]})

        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/somerepo/pullrequests/',
            json={'values': [{
                'title': 'Some Feature',
                'state': 'open',
                'links': {'html': {'href': 'example.com'}},
                'id': 1
            }]})

        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/somerepo/pullrequests/1/comments',
            json={'values': [{
                'user': {'username': 'nobody'},
                'content': {'raw': 'Some comment.'}
            }]})

        issue, pr = [i for i in self.service.issues()]

        expected_issue = {
            'annotations': [u'@nobody - Some comment.'],
            'bitbucketid': 1,
            'bitbuckettitle': u'Some Bug',
            'bitbucketurl': u'example.com',
            'description': u'(bw)Is#1 - Some Bug .. example.com',
            'priority': 'M',
            'project': u'somerepo',
            'tags': []}

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

        expected_pr = {
            'annotations': [u'@nobody - Some comment.'],
            'bitbucketid': 1,
            'bitbuckettitle': u'Some Feature',
            'bitbucketurl': 'https://bitbucket.org/',
            'description': u'(bw)Is#1 - Some Feature .. https://bitbucket.org/',
            'priority': 'M',
            'project': u'somerepo',
            'tags': []}

        self.assertEqual(pr.get_taskwarrior_record(), expected_pr)

    def test_get_owner(self):
        issue = {
            'title': 'Foobar',
            'assignee': {'username': 'tintin'},
        }
        self.assertEqual(self.service.get_owner(('foo', issue)), 'tintin')

    def test_get_owner_none(self):
        issue = {
            'title': 'Foobar',
            'assignee': None,
        }
        self.assertIsNone(self.service.get_owner(('foo', issue)))

    @unittest.skip('https://github.com/getsentry/responses/issues/156')
    @responses.activate
    def test_fetch_issues_pagination(self):
        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/',
            json={
                'values': [{
                    'title': 'Some Bug',
                    'status': 'open',
                    'links': {'html': {'href': 'example.com'}},
                    'id': 1
                }],
                'next': 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/?page=2',
            })
        self.add_response(
            'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/?page=2',
            json={
                'values': [{
                    'title': 'Some Other Bug',
                    'status': 'open',
                    'links': {'html': {'href': 'example.com'}},
                    'id': 2
                }],
            })
        issues = list(self.service.fetch_issues('somename/somerepo'))
        expected = [
            ('somename/somerepo', {
                'title': 'Some Bug',
                'status': 'open',
                'links': {'html': {'href': 'example.com'}},
                'id': 1
            }),
            ('somename/somerepo', {
                'title': 'Some Other Bug',
                'status': 'open',
                'links': {'html': {'href': 'example.com'}},
                'id': 2
            }),
        ]
        self.assertEqual(issues, expected)