| 1 |
from builtins import next |
| 2 |
from unittest import mock |
| 3 |
|
| 4 |
import responses |
| 5 |
|
| 6 |
from bugwarrior.services.teamlab import TeamLabService |
| 7 |
|
| 8 |
from .base import ServiceTest, AbstractServiceTest |
| 9 |
|
| 10 |
|
| 11 |
class TestTeamlabIssue(AbstractServiceTest, ServiceTest): |
| 12 |
SERVICE_CONFIG = { |
| 13 |
'teamlab.hostname': 'something', |
| 14 |
'teamlab.login': 'alkjdsf', |
| 15 |
'teamlab.password': 'lkjklj', |
| 16 |
'teamlab.project_name': 'abcdef', |
| 17 |
} |
| 18 |
arbitrary_issue = { |
| 19 |
'title': 'Hello', |
| 20 |
'id': 10, |
| 21 |
'projectOwner': { |
| 22 |
'id': 140, |
| 23 |
}, |
| 24 |
'status': 1, |
| 25 |
} |
| 26 |
|
| 27 |
def setUp(self): |
| 28 |
super(TestTeamlabIssue, self).setUp() |
| 29 |
with mock.patch( |
| 30 |
'bugwarrior.services.teamlab.TeamLabClient.authenticate' |
| 31 |
): |
| 32 |
self.service = self.get_mock_service(TeamLabService) |
| 33 |
|
| 34 |
def test_to_taskwarrior(self): |
| 35 |
arbitrary_url = 'http://galkjsdflkj.com/' |
| 36 |
|
| 37 |
issue = self.service.get_issue_for_record(self.arbitrary_issue) |
| 38 |
|
| 39 |
expected_output = { |
| 40 |
'project': self.SERVICE_CONFIG['teamlab.project_name'], |
| 41 |
'priority': self.service.default_priority, |
| 42 |
issue.TITLE: self.arbitrary_issue['title'], |
| 43 |
issue.FOREIGN_ID: self.arbitrary_issue['id'], |
| 44 |
issue.URL: arbitrary_url, |
| 45 |
issue.PROJECTOWNER_ID: self.arbitrary_issue['projectOwner']['id'] |
| 46 |
} |
| 47 |
|
| 48 |
def get_url(*args): |
| 49 |
return arbitrary_url |
| 50 |
|
| 51 |
with mock.patch.object(issue, 'get_issue_url', side_effect=get_url): |
| 52 |
actual_output = issue.to_taskwarrior() |
| 53 |
|
| 54 |
self.assertEqual(actual_output, expected_output) |
| 55 |
|
| 56 |
@responses.activate |
| 57 |
def test_issues(self): |
| 58 |
self.add_response( |
| 59 |
'http://something/api/1.0/project/task/@self.json', |
| 60 |
json=[self.arbitrary_issue]) |
| 61 |
|
| 62 |
issue = next(self.service.issues()) |
| 63 |
|
| 64 |
expected = { |
| 65 |
'description': |
| 66 |
u'(bw)Is#10 - Hello .. http://something/products/projects/tasks.aspx?prjID=140&id=10', |
| 67 |
'priority': 'M', |
| 68 |
'project': 'abcdef', |
| 69 |
'tags': [], |
| 70 |
'teamlabid': 10, |
| 71 |
'teamlabprojectownerid': 140, |
| 72 |
'teamlabtitle': u'Hello', |
| 73 |
'teamlaburl': |
| 74 |
'http://something/products/projects/tasks.aspx?prjID=140&id=10'} |
| 75 |
|
| 76 |
self.assertEqual(issue.get_taskwarrior_record(), expected) |