| 1 |
from builtins import next |
| 2 |
import re |
| 3 |
import datetime |
| 4 |
|
| 5 |
import pytz |
| 6 |
import responses |
| 7 |
|
| 8 |
from bugwarrior.services.activecollab2 import ActiveCollab2Service |
| 9 |
|
| 10 |
from .base import ServiceTest, AbstractServiceTest |
| 11 |
|
| 12 |
|
| 13 |
class TestActiveCollab2Issue(AbstractServiceTest, ServiceTest): |
| 14 |
SERVICE_CONFIG = { |
| 15 |
'activecollab2.url': 'http://hello', |
| 16 |
'activecollab2.key': 'howdy', |
| 17 |
'activecollab2.user_id': 0, |
| 18 |
'activecollab2.projects': '1:one, 2:two' |
| 19 |
} |
| 20 |
|
| 21 |
arbitrary_due_on = ( |
| 22 |
datetime.datetime.now() - datetime.timedelta(hours=1) |
| 23 |
).replace(tzinfo=pytz.UTC) |
| 24 |
arbitrary_created_on = ( |
| 25 |
datetime.datetime.now() - datetime.timedelta(hours=2) |
| 26 |
).replace(tzinfo=pytz.UTC) |
| 27 |
arbitrary_issue = { |
| 28 |
'project': 'something', |
| 29 |
'priority': 2, |
| 30 |
'due_on': arbitrary_due_on.isoformat(), |
| 31 |
'permalink': 'http://wherever/', |
| 32 |
'ticket_id': 10, |
| 33 |
'project_id': 20, |
| 34 |
'type': 'Ticket', |
| 35 |
'created_on': arbitrary_created_on.isoformat(), |
| 36 |
'created_by_id': '10', |
| 37 |
'body': 'Ticket Body', |
| 38 |
'name': 'Anonymous', |
| 39 |
'assignees': [ |
| 40 |
{'user_id': SERVICE_CONFIG['activecollab2.user_id'], |
| 41 |
'is_owner': True} |
| 42 |
], |
| 43 |
'description': 'Further detail.', |
| 44 |
} |
| 45 |
|
| 46 |
def setUp(self): |
| 47 |
super(TestActiveCollab2Issue, self).setUp() |
| 48 |
self.service = self.get_mock_service(ActiveCollab2Service) |
| 49 |
|
| 50 |
def test_to_taskwarrior(self): |
| 51 |
|
| 52 |
issue = self.service.get_issue_for_record(self.arbitrary_issue) |
| 53 |
|
| 54 |
expected_output = { |
| 55 |
'project': self.arbitrary_issue['project'], |
| 56 |
'priority': issue.PRIORITY_MAP[self.arbitrary_issue['priority']], |
| 57 |
'due': self.arbitrary_due_on, |
| 58 |
|
| 59 |
issue.PERMALINK: self.arbitrary_issue['permalink'], |
| 60 |
issue.TICKET_ID: self.arbitrary_issue['ticket_id'], |
| 61 |
issue.PROJECT_ID: self.arbitrary_issue['project_id'], |
| 62 |
issue.TYPE: self.arbitrary_issue['type'], |
| 63 |
issue.CREATED_ON: self.arbitrary_created_on, |
| 64 |
issue.CREATED_BY_ID: self.arbitrary_issue['created_by_id'], |
| 65 |
issue.BODY: self.arbitrary_issue['body'], |
| 66 |
issue.NAME: self.arbitrary_issue['name'], |
| 67 |
} |
| 68 |
actual_output = issue.to_taskwarrior() |
| 69 |
|
| 70 |
self.assertEqual(actual_output, expected_output) |
| 71 |
|
| 72 |
@responses.activate |
| 73 |
def test_issues(self): |
| 74 |
self.add_response( |
| 75 |
re.compile( |
| 76 |
'http://hello/\?(?=.*token=howdy)(?=.*path_info=\%2Fprojects\%2F[1-2]\%2Fuser-tasks)(?=.*format=json)'), |
| 77 |
json=[self.arbitrary_issue]) |
| 78 |
self.add_response( |
| 79 |
re.compile( |
| 80 |
'http://hello/\?(?=.*token=howdy)(?=.*path_info=\%2Fprojects\%2F20\%2Ftickets\%2F10)(?=.*format=json)'), |
| 81 |
json=self.arbitrary_issue) |
| 82 |
|
| 83 |
issue = next(self.service.issues()) |
| 84 |
|
| 85 |
expected = { |
| 86 |
'ac2body': u'Ticket Body', |
| 87 |
'ac2createdbyid': u'10', |
| 88 |
'ac2createdon': self.arbitrary_created_on, |
| 89 |
'ac2name': u'Anonymous', |
| 90 |
'ac2permalink': u'http://wherever/', |
| 91 |
'ac2projectid': 20, |
| 92 |
'ac2ticketid': 10, |
| 93 |
'ac2type': u'Ticket', |
| 94 |
'description': u'(bw)Is#10 - Anonymous .. http://wherever/', |
| 95 |
'due': self.arbitrary_due_on, |
| 96 |
'priority': 'H', |
| 97 |
'project': u'something', |
| 98 |
'tags': []} |
| 99 |
|
| 100 |
self.assertEqual(issue.get_taskwarrior_record(), expected) |