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