Debian Codegraph @

tests/test_bitbucket.py

raw
1 from __future__ import unicode_literals
2 import unittest
3
4 import responses
5
6 from bugwarrior.services.bitbucket import BitbucketService
7
8 from .base import ServiceTest, AbstractServiceTest
9
10
11 class TestBitbucketIssue(AbstractServiceTest, ServiceTest):
12 SERVICE_CONFIG = {
13 'bitbucket.login': 'something',
14 'bitbucket.username': 'somename',
15 'bitbucket.password': 'something else',
16 }
17
18 def setUp(self):
19 super(TestBitbucketIssue, self).setUp()
20 self.service = self.get_mock_service(BitbucketService)
21
22 def test_to_taskwarrior(self):
23 arbitrary_issue = {
24 'priority': 'trivial',
25 'id': '100',
26 'title': 'Some Title',
27 }
28 arbitrary_extra = {
29 'url': 'http://hello-there.com/',
30 'project': 'Something',
31 'annotations': [
32 'One',
33 ]
34 }
35
36 issue = self.service.get_issue_for_record(
37 arbitrary_issue, arbitrary_extra
38 )
39
40 expected_output = {
41 'project': arbitrary_extra['project'],
42 'priority': issue.PRIORITY_MAP[arbitrary_issue['priority']],
43 'annotations': arbitrary_extra['annotations'],
44
45 issue.URL: arbitrary_extra['url'],
46 issue.FOREIGN_ID: arbitrary_issue['id'],
47 issue.TITLE: arbitrary_issue['title'],
48 }
49 actual_output = issue.to_taskwarrior()
50
51 self.assertEqual(actual_output, expected_output)
52
53 @responses.activate
54 def test_issues(self):
55 self.add_response(
56 'https://api.bitbucket.org/2.0/repositories/somename/',
57 json={'values': [{
58 'full_name': 'somename/somerepo',
59 'has_issues': True
60 }]})
61
62 self.add_response(
63 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/',
64 json={'values': [{
65 'title': 'Some Bug',
66 'status': 'open',
67 'links': {'html': {'href': 'example.com'}},
68 'id': 1
69 }]})
70
71 self.add_response(
72 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/pullrequests/',
73 json={'values': [{
74 'title': 'Some Feature',
75 'state': 'open',
76 'links': {'html': {'href': 'example.com'}},
77 'id': 1
78 }]})
79
80 self.add_response(
81 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/pullrequests/1/comments',
82 json={'values': [{
83 'user': {'username': 'nobody'},
84 'content': {'raw': 'Some comment.'}
85 }]})
86
87 issue, pr = [i for i in self.service.issues()]
88
89 expected_issue = {
90 'annotations': [u'@nobody - Some comment.'],
91 'bitbucketid': 1,
92 'bitbuckettitle': u'Some Bug',
93 'bitbucketurl': u'example.com',
94 'description': u'(bw)Is#1 - Some Bug .. example.com',
95 'priority': 'M',
96 'project': u'somerepo',
97 'tags': []}
98
99 self.assertEqual(issue.get_taskwarrior_record(), expected_issue)
100
101 expected_pr = {
102 'annotations': [u'@nobody - Some comment.'],
103 'bitbucketid': 1,
104 'bitbuckettitle': u'Some Feature',
105 'bitbucketurl': 'https://bitbucket.org/',
106 'description': u'(bw)Is#1 - Some Feature .. https://bitbucket.org/',
107 'priority': 'M',
108 'project': u'somerepo',
109 'tags': []}
110
111 self.assertEqual(pr.get_taskwarrior_record(), expected_pr)
112
113 def test_get_owner(self):
114 issue = {
115 'title': 'Foobar',
116 'assignee': {'username': 'tintin'},
117 }
118 self.assertEqual(self.service.get_owner(('foo', issue)), 'tintin')
119
120 def test_get_owner_none(self):
121 issue = {
122 'title': 'Foobar',
123 'assignee': None,
124 }
125 self.assertIsNone(self.service.get_owner(('foo', issue)))
126
127 @unittest.skip('https://github.com/getsentry/responses/issues/156')
128 @responses.activate
129 def test_fetch_issues_pagination(self):
130 self.add_response(
131 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/',
132 json={
133 'values': [{
134 'title': 'Some Bug',
135 'status': 'open',
136 'links': {'html': {'href': 'example.com'}},
137 'id': 1
138 }],
139 'next': 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/?page=2',
140 })
141 self.add_response(
142 'https://api.bitbucket.org/2.0/repositories/somename/somerepo/issues/?page=2',
143 json={
144 'values': [{
145 'title': 'Some Other Bug',
146 'status': 'open',
147 'links': {'html': {'href': 'example.com'}},
148 'id': 2
149 }],
150 })
151 issues = list(self.service.fetch_issues('somename/somerepo'))
152 expected = [
153 ('somename/somerepo', {
154 'title': 'Some Bug',
155 'status': 'open',
156 'links': {'html': {'href': 'example.com'}},
157 'id': 1
158 }),
159 ('somename/somerepo', {
160 'title': 'Some Other Bug',
161 'status': 'open',
162 'links': {'html': {'href': 'example.com'}},
163 'id': 2
164 }),
165 ]
166 self.assertEqual(issues, expected)