File: test_teamwork_projects.py

package info (click to toggle)
bugwarrior 1.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 9,226; makefile: 147
file content (142 lines) | stat: -rw-r--r-- 5,740 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from .base import ServiceTest, AbstractServiceTest
from bugwarrior.services.teamwork_projects import TeamworkService, TeamworkClient

import responses
import datetime
from dateutil.tz import tzutc

class TestTeamworkIssue(AbstractServiceTest, ServiceTest):
    SERVICE_CONFIG = {
        'teamwork_projects.host': 'https://test.teamwork_projects.com',
        'teamwork_projects.token': 'arbitrary_token',
    }

    @responses.activate
    def setUp(self):
        super(TestTeamworkIssue, self).setUp()
        self.add_response(
            'https://test.teamwork_projects.com/authenticate.json',
            json={
                'account': {
                    'userId': 5,
                    'firstname': 'Greg',
                    'lastname': 'McCoy'
                }
            }
        )
        self.service = self.get_mock_service(TeamworkService)
        self.arbitrary_issue = { 
            "todo-items": [{
                "id": 5,
                "comments-count": 2,
                "description": "This issue is meant for testing",
                "content": "This is a test issue",
                "project-id": 1,
                "project-name": "Test Project",
                "status": "new",
                "company-name": "Test Company",
                "company-id": 1,
                "creator-id": 1,
                "creator-firstname": "Greg",
                "creator-lastname": "McCoy",
                "updater-id": 0,
                "updater-firstname": "",
                "updater-lastname": "",
                "completed": False,
                "start-date": "",
                "due-date": "2019-12-12T10:06:31Z",
                "created-on": "2018-12-12T10:06:31Z",
                "last-changed-on": "2019-01-16T11:00:44Z",
                "priority": "high",
                "parentTaskId": "",
                "userFollowingComments": True,
                "userFollowingChanges": True,
                "DLM": 0,
                "responsible-party-ids": ["5"]
            }]
        }
        self.arbitrary_extra = {
            "host": "https://test.teamwork_projects.com",
            "annotations": [("Greg McCoy", "Test comment"), ("Bob Test", "testing")]
        }
        self.arbitrary_comments = {
            "comments": [
                {
                  "project-id": "999",
                  "author-lastname": "User",
                  "datetime": "2014-03-31T13:03:29Z",
                  "author_id": "999",
                  "id": "999",
                  "company-name": "Test Company",
                  "last-changed-on": "",
                  "company-id": "999",
                  "project-name": "demo",
                  "body": "A test comment",
                  "commentNo": "1",
                  "author-firstname": "Demo",
                  "comment-link": "tasks/436523?c=93",
                  "author-id": "999"
                }
            ]
        }



    @responses.activate
    def test_to_taskwarrior(self):
        issue = self.service.get_issue_for_record(self.arbitrary_issue["todo-items"][0], self.arbitrary_extra)
        data = self.arbitrary_issue["todo-items"][0]
        expected_data = {
            'project': data["project-name"],
            'priority': "H",
            'due': datetime.datetime(2019, 12, 12, 10, 6, 31, tzinfo=tzutc()),
            'entry': datetime.datetime(2018, 12, 12, 10, 6, 31, tzinfo=tzutc()),
            'end': "",
            'modified': datetime.datetime(2019, 1, 16, 11, 0, 44, tzinfo=tzutc()),
            'annotations': self.arbitrary_extra.get("annotations", ""),
            issue.URL: "https://test.teamwork_projects.com/#/tasks/5",
            issue.TITLE: data["content"],
            issue.DESCRIPTION_LONG: data["description"],
            issue.PROJECT_ID: int(data["project-id"]),
            issue.STATUS: "Open",
            issue.ID: int(data["id"]),
            "annotations": [('Greg McCoy', 'Test comment'), ('Bob Test', 'testing')],
        }
        actual_output = issue.to_taskwarrior()
        self.assertEqual(actual_output, expected_data)

    @responses.activate
    def test_issues(self):
        self.add_response(
            'https://test.teamwork_projects.com/tasks/5/comments.json',
            json=self.arbitrary_comments
        )
        self.add_response(
            'https://test.teamwork_projects.com/tasks.json',
            json=self.arbitrary_issue
        )
        issue = next(self.service.issues())
        data = self.arbitrary_issue["todo-items"][0]
        expected_data = {
            'project': data["project-name"],
            'priority': "H",
            'due': datetime.datetime(2019, 12, 12, 10, 6, 31, tzinfo=tzutc()),
            'entry': datetime.datetime(2018, 12, 12, 10, 6, 31, tzinfo=tzutc()),
            'end': "",
            'modified': datetime.datetime(2019, 1, 16, 11, 0, 44, tzinfo=tzutc()),
            'annotations': self.arbitrary_extra.get("annotations", ""),
            'description': '(bw)Is#5 - This is a test issue .. https://test.teamwork_projects.com/#/tasks/5', 
            issue.URL: "https://test.teamwork_projects.com/#/tasks/5",
            issue.TITLE: data["content"],
            issue.DESCRIPTION_LONG: data["description"],
            issue.PROJECT_ID: int(data["project-id"]),
            issue.STATUS: "Open",
            issue.ID: int(data["id"]),
            "annotations": ['@Demo User - A test comment'],
            "tags": [],
        }
        issue.user_id = "5"
        issue.name = "Greg McCoy"
        self.assertEqual(issue.get_taskwarrior_record(), expected_data)
        self.assertEqual(issue.get_owner(issue), "Greg McCoy")
        self.assertEqual(issue.get_author(issue), "Greg McCoy")