Debian Codegraph @

tests/test_gerrit.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 from builtins import next
2 import json
3
4 import responses
5
6 from bugwarrior.services.gerrit import GerritService
7 from .base import ServiceTest, AbstractServiceTest
8
9
10 class TestGerritIssue(AbstractServiceTest, ServiceTest):
11 SERVICE_CONFIG = {
12 'gerrit.base_uri': 'https://one.com',
13 'gerrit.username': 'two',
14 'gerrit.password': 'three',
15 }
16
17 record = {
18 'project': 'nova',
19 '_number': 1,
20 'branch': 'master',
21 'topic': 'test-topic',
22 'subject': 'this is a title',
23 'messages': [{'author': {'username': 'Iam Author'},
24 'message': 'this is a message',
25 '_revision_number': 1}],
26 }
27
28 def setUp(self):
29 super(TestGerritIssue, self).setUp()
30
31 responses.add(
32 responses.HEAD,
33 self.SERVICE_CONFIG['gerrit.base_uri'] + '/a/',
34 headers={'www-authenticate': 'digest'})
35 with responses.mock:
36 self.service = self.get_mock_service(GerritService)
37
38 def test_to_taskwarrior(self):
39 extra = {
40 'annotations': [
41 # TODO - test annotations?
42 ],
43 'url': 'this is a url',
44 }
45
46 issue = self.service.get_issue_for_record(self.record, extra)
47 actual = issue.to_taskwarrior()
48 expected = {
49 'annotations': [],
50 'priority': 'M',
51 'project': 'nova',
52 'gerritid': 1,
53 'gerritsummary': 'this is a title',
54 'gerriturl': 'this is a url',
55 'gerritbranch': 'master',
56 'gerrittopic': 'test-topic',
57 'tags': [],
58 }
59
60 self.assertEqual(actual, expected)
61
62 @responses.activate
63 def test_issues(self):
64 self.add_response(
65 'https://one.com/a/changes/?q=is:open+is:reviewer&o=MESSAGES&o=DETAILED_ACCOUNTS',
66 # The response has some ")]}'" garbage prefixed.
67 body=")]}'" + json.dumps([self.record]))
68
69 issue = next(self.service.issues())
70
71 expected = {
72 'annotations': [u'@Iam Author - is is a message'],
73 'description': u'(bw)PR#1 - this is a title .. https://one.com/#/c/1/',
74 'gerritid': 1,
75 'gerritsummary': u'this is a title',
76 'gerriturl': 'https://one.com/#/c/1/',
77 'gerritbranch': 'master',
78 'gerrittopic': 'test-topic',
79 'priority': 'M',
80 'project': u'nova',
81 'tags': []}
82
83 self.assertEqual(issue.get_taskwarrior_record(), expected)