| 1 |
from builtins import next |
| 2 |
from builtins import object |
| 3 |
import unittest |
| 4 |
from unittest import mock |
| •5 |
raise unittest.SkipTest('python-megaplan not packaged in Debian') |
| 6 |
|
| 7 |
try: |
| 8 |
from bugwarrior.services.mplan import MegaplanService |
| 9 |
except SyntaxError: |
| 10 |
raise unittest.SkipTest( |
| 11 |
'Upstream python-megaplan does not support python3 yet.') |
| 12 |
|
| 13 |
from .base import ServiceTest, AbstractServiceTest |
| 14 |
|
| 15 |
|
| 16 |
class FakeMegaplanClient(object): |
| 17 |
def __init__(self, record): |
| 18 |
self.record = record |
| 19 |
def get_actual_tasks(self): |
| 20 |
return [self.record] |
| 21 |
|
| 22 |
|
| 23 |
class TestMegaplanIssue(AbstractServiceTest, ServiceTest): |
| 24 |
SERVICE_CONFIG = { |
| 25 |
'megaplan.hostname': 'something', |
| 26 |
'megaplan.login': 'something_else', |
| 27 |
'megaplan.password': 'aljlkj', |
| 28 |
} |
| 29 |
name_parts = ['one', 'two', 'three'] |
| 30 |
arbitrary_issue = { |
| 31 |
'Id': 10, |
| 32 |
'Name': '|'.join(name_parts) |
| 33 |
} |
| 34 |
|
| 35 |
def setUp(self): |
| 36 |
super(TestMegaplanIssue, self).setUp() |
| 37 |
with mock.patch('megaplan.Client'): |
| 38 |
self.service = self.get_mock_service(MegaplanService) |
| 39 |
|
| 40 |
def get_mock_service(self, *args, **kwargs): |
| 41 |
service = super(TestMegaplanIssue, self).get_mock_service( |
| 42 |
*args, **kwargs) |
| 43 |
service.client = FakeMegaplanClient(self.arbitrary_issue) |
| 44 |
return service |
| 45 |
|
| 46 |
def test_to_taskwarrior(self): |
| 47 |
arbitrary_project = 'one' |
| 48 |
arbitrary_url = 'http://one.com/' |
| 49 |
|
| 50 |
issue = self.service.get_issue_for_record(self.arbitrary_issue) |
| 51 |
|
| 52 |
expected_output = { |
| 53 |
'project': arbitrary_project, |
| 54 |
'priority': self.service.default_priority, |
| 55 |
|
| 56 |
issue.FOREIGN_ID: self.arbitrary_issue['Id'], |
| 57 |
issue.URL: arbitrary_url, |
| 58 |
issue.TITLE: self.name_parts[-1] |
| 59 |
} |
| 60 |
|
| 61 |
def get_url(*args): |
| 62 |
return arbitrary_url |
| 63 |
|
| 64 |
def get_project(*args): |
| 65 |
return arbitrary_project |
| 66 |
|
| 67 |
with mock.patch.multiple( |
| 68 |
issue, get_project=mock.DEFAULT, get_issue_url=mock.DEFAULT |
| 69 |
) as mocked: |
| 70 |
mocked['get_project'].side_effect = get_project |
| 71 |
mocked['get_issue_url'].side_effect = get_url |
| 72 |
actual_output = issue.to_taskwarrior() |
| 73 |
|
| 74 |
self.assertEqual(actual_output, expected_output) |
| 75 |
|
| 76 |
def test_issues(self): |
| 77 |
issue = next(self.service.issues()) |
| 78 |
|
| 79 |
expected = { |
| 80 |
'description': |
| 81 |
'(bw)Is#10 - three .. https://something/task/10/card/', |
| 82 |
'megaplanid': 10, |
| 83 |
'megaplantitle': 'three', |
| 84 |
'megaplanurl': 'https://something/task/10/card/', |
| 85 |
'priority': 'M', |
| 86 |
'project': 'something', |
| 87 |
'tags': []} |
| 88 |
|
| 89 |
self.assertEqual(issue.get_taskwarrior_record(), expected) |