| 1 |
from .base import ServiceTest, AbstractServiceTest |
| 2 |
from bugwarrior.services.teamwork_projects import TeamworkService, TeamworkClient |
| 3 |
|
| 4 |
import responses |
| 5 |
import datetime |
| 6 |
from dateutil.tz import tzutc |
| 7 |
|
| 8 |
class TestTeamworkIssue(AbstractServiceTest, ServiceTest): |
| 9 |
SERVICE_CONFIG = { |
| 10 |
'teamwork_projects.host': 'https://test.teamwork_projects.com', |
| 11 |
'teamwork_projects.token': 'arbitrary_token', |
| 12 |
} |
| 13 |
|
| 14 |
@responses.activate |
| 15 |
def setUp(self): |
| 16 |
super(TestTeamworkIssue, self).setUp() |
| 17 |
self.add_response( |
| 18 |
'https://test.teamwork_projects.com/authenticate.json', |
| 19 |
json={ |
| 20 |
'account': { |
| 21 |
'userId': 5, |
| 22 |
'firstname': 'Greg', |
| 23 |
'lastname': 'McCoy' |
| 24 |
} |
| 25 |
} |
| 26 |
) |
| 27 |
self.service = self.get_mock_service(TeamworkService) |
| 28 |
self.arbitrary_issue = { |
| 29 |
"todo-items": [{ |
| 30 |
"id": 5, |
| 31 |
"comments-count": 2, |
| 32 |
"description": "This issue is meant for testing", |
| 33 |
"content": "This is a test issue", |
| 34 |
"project-id": 1, |
| 35 |
"project-name": "Test Project", |
| 36 |
"status": "new", |
| 37 |
"company-name": "Test Company", |
| 38 |
"company-id": 1, |
| 39 |
"creator-id": 1, |
| 40 |
"creator-firstname": "Greg", |
| 41 |
"creator-lastname": "McCoy", |
| 42 |
"updater-id": 0, |
| 43 |
"updater-firstname": "", |
| 44 |
"updater-lastname": "", |
| 45 |
"completed": False, |
| 46 |
"start-date": "", |
| 47 |
"due-date": "2019-12-12T10:06:31Z", |
| 48 |
"created-on": "2018-12-12T10:06:31Z", |
| 49 |
"last-changed-on": "2019-01-16T11:00:44Z", |
| 50 |
"priority": "high", |
| 51 |
"parentTaskId": "", |
| 52 |
"userFollowingComments": True, |
| 53 |
"userFollowingChanges": True, |
| 54 |
"DLM": 0, |
| 55 |
"responsible-party-ids": ["5"] |
| 56 |
}] |
| 57 |
} |
| 58 |
self.arbitrary_extra = { |
| 59 |
"host": "https://test.teamwork_projects.com", |
| 60 |
"annotations": [("Greg McCoy", "Test comment"), ("Bob Test", "testing")] |
| 61 |
} |
| 62 |
self.arbitrary_comments = { |
| 63 |
"comments": [ |
| 64 |
{ |
| 65 |
"project-id": "999", |
| 66 |
"author-lastname": "User", |
| 67 |
"datetime": "2014-03-31T13:03:29Z", |
| 68 |
"author_id": "999", |
| 69 |
"id": "999", |
| 70 |
"company-name": "Test Company", |
| 71 |
"last-changed-on": "", |
| 72 |
"company-id": "999", |
| 73 |
"project-name": "demo", |
| 74 |
"body": "A test comment", |
| 75 |
"commentNo": "1", |
| 76 |
"author-firstname": "Demo", |
| 77 |
"comment-link": "tasks/436523?c=93", |
| 78 |
"author-id": "999" |
| 79 |
} |
| 80 |
] |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@responses.activate |
| 86 |
def test_to_taskwarrior(self): |
| 87 |
issue = self.service.get_issue_for_record(self.arbitrary_issue["todo-items"][0], self.arbitrary_extra) |
| 88 |
data = self.arbitrary_issue["todo-items"][0] |
| 89 |
expected_data = { |
| 90 |
'project': data["project-name"], |
| 91 |
'priority': "H", |
| 92 |
'due': datetime.datetime(2019, 12, 12, 10, 6, 31, tzinfo=tzutc()), |
| 93 |
'entry': datetime.datetime(2018, 12, 12, 10, 6, 31, tzinfo=tzutc()), |
| 94 |
'end': "", |
| 95 |
'modified': datetime.datetime(2019, 1, 16, 11, 0, 44, tzinfo=tzutc()), |
| 96 |
'annotations': self.arbitrary_extra.get("annotations", ""), |
| 97 |
issue.URL: "https://test.teamwork_projects.com/#/tasks/5", |
| 98 |
issue.TITLE: data["content"], |
| 99 |
issue.DESCRIPTION_LONG: data["description"], |
| 100 |
issue.PROJECT_ID: int(data["project-id"]), |
| 101 |
issue.STATUS: "Open", |
| 102 |
issue.ID: int(data["id"]), |
| 103 |
"annotations": [('Greg McCoy', 'Test comment'), ('Bob Test', 'testing')], |
| 104 |
} |
| 105 |
actual_output = issue.to_taskwarrior() |
| 106 |
self.assertEqual(actual_output, expected_data) |
| 107 |
|
| 108 |
@responses.activate |
| 109 |
def test_issues(self): |
| 110 |
self.add_response( |
| 111 |
'https://test.teamwork_projects.com/tasks/5/comments.json', |
| 112 |
json=self.arbitrary_comments |
| 113 |
) |
| 114 |
self.add_response( |
| 115 |
'https://test.teamwork_projects.com/tasks.json', |
| 116 |
json=self.arbitrary_issue |
| 117 |
) |
| 118 |
issue = next(self.service.issues()) |
| 119 |
data = self.arbitrary_issue["todo-items"][0] |
| 120 |
expected_data = { |
| 121 |
'project': data["project-name"], |
| 122 |
'priority': "H", |
| 123 |
'due': datetime.datetime(2019, 12, 12, 10, 6, 31, tzinfo=tzutc()), |
| 124 |
'entry': datetime.datetime(2018, 12, 12, 10, 6, 31, tzinfo=tzutc()), |
| 125 |
'end': "", |
| 126 |
'modified': datetime.datetime(2019, 1, 16, 11, 0, 44, tzinfo=tzutc()), |
| 127 |
'annotations': self.arbitrary_extra.get("annotations", ""), |
| 128 |
'description': '(bw)Is#5 - This is a test issue .. https://test.teamwork_projects.com/#/tasks/5', |
| 129 |
issue.URL: "https://test.teamwork_projects.com/#/tasks/5", |
| 130 |
issue.TITLE: data["content"], |
| 131 |
issue.DESCRIPTION_LONG: data["description"], |
| 132 |
issue.PROJECT_ID: int(data["project-id"]), |
| 133 |
issue.STATUS: "Open", |
| 134 |
issue.ID: int(data["id"]), |
| 135 |
"annotations": ['@Demo User - A test comment'], |
| 136 |
"tags": [], |
| 137 |
} |
| 138 |
issue.user_id = "5" |
| 139 |
issue.name = "Greg McCoy" |
| 140 |
self.assertEqual(issue.get_taskwarrior_record(), expected_data) |
| 141 |
self.assertEqual(issue.get_owner(issue), "Greg McCoy") |
| 142 |
self.assertEqual(issue.get_author(issue), "Greg McCoy") |