-
Notifications
You must be signed in to change notification settings - Fork 713
Expand file tree
/
Copy pathtest_tempo_cloud.py
More file actions
458 lines (400 loc) · 20.5 KB
/
Copy pathtest_tempo_cloud.py
File metadata and controls
458 lines (400 loc) · 20.5 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# coding=utf-8
"""
Test cases for Tempo Cloud API client.
"""
import pytest
from unittest.mock import patch
from atlassian.tempo import TempoCloud
@pytest.fixture
def tempo_cloud():
"""Fixture for TempoCloud client."""
return TempoCloud(url="https://test.atlassian.net", token="test-token", cloud=True)
class TestTempoCloud:
"""Test cases for TempoCloud client."""
def test_init_defaults(self):
"""Test TempoCloud client initialization with default values."""
tempo = TempoCloud(url="https://test.atlassian.net", token="test-token")
assert tempo.api_version == "1"
assert tempo.api_root == "rest/tempo-timesheets/4"
def test_init_custom_values(self):
"""Test TempoCloud client initialization with custom values."""
tempo = TempoCloud(
url="https://test.atlassian.net", token="test-token", api_version="2", api_root="custom/api/root"
)
assert tempo.api_version == "2"
assert tempo.api_root == "custom/api/root"
# Account Management Tests
@patch.object(TempoCloud, "get")
def test_get_accounts(self, mock_get, tempo_cloud):
"""Test get_accounts method."""
mock_get.return_value = [{"id": 1, "name": "Test Account"}]
result = tempo_cloud.get_accounts()
mock_get.assert_called_once_with("accounts", **{})
assert result == [{"id": 1, "name": "Test Account"}]
@patch.object(TempoCloud, "get")
def test_get_account(self, mock_get, tempo_cloud):
"""Test get_account method."""
mock_get.return_value = {"id": 1, "name": "Test Account"}
result = tempo_cloud.get_account(1)
mock_get.assert_called_once_with("accounts/1", **{})
assert result == {"id": 1, "name": "Test Account"}
@patch.object(TempoCloud, "post")
def test_create_account(self, mock_post, tempo_cloud):
"""Test create_account method."""
account_data = {"name": "New Account", "key": "NEW"}
mock_post.return_value = {"id": 2, "name": "New Account", "key": "NEW"}
result = tempo_cloud.create_account(account_data)
mock_post.assert_called_once_with("accounts", data=account_data, **{})
assert result == {"id": 2, "name": "New Account", "key": "NEW"}
@patch.object(TempoCloud, "put")
def test_update_account(self, mock_put, tempo_cloud):
"""Test update_account method."""
account_data = {"name": "Updated Account"}
mock_put.return_value = {"id": 1, "name": "Updated Account"}
result = tempo_cloud.update_account(1, account_data)
mock_put.assert_called_once_with("accounts/1", data=account_data, **{})
assert result == {"id": 1, "name": "Updated Account"}
@patch.object(TempoCloud, "delete")
def test_delete_account(self, mock_delete, tempo_cloud):
"""Test delete_account method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_account(1)
mock_delete.assert_called_once_with("accounts/1", **{})
assert result == {"success": True}
# Worklog Management Tests
@patch.object(TempoCloud, "get")
def test_get_worklogs(self, mock_get, tempo_cloud):
"""Test get_worklogs method."""
mock_get.return_value = [{"id": 1, "timeSpentSeconds": 3600}]
result = tempo_cloud.get_worklogs()
mock_get.assert_called_once_with("worklogs", **{})
assert result == [{"id": 1, "timeSpentSeconds": 3600}]
@patch.object(TempoCloud, "get")
def test_get_worklog(self, mock_get, tempo_cloud):
"""Test get_worklog method."""
mock_get.return_value = {"id": 1, "timeSpentSeconds": 3600}
result = tempo_cloud.get_worklog(1)
mock_get.assert_called_once_with("worklogs/1", **{})
assert result == {"id": 1, "timeSpentSeconds": 3600}
@patch.object(TempoCloud, "post")
def test_create_worklog(self, mock_post, tempo_cloud):
"""Test create_worklog method."""
worklog_data = {"issueKey": "TEST-1", "timeSpentSeconds": 3600}
mock_post.return_value = {"id": 2, "issueKey": "TEST-1", "timeSpentSeconds": 3600}
result = tempo_cloud.create_worklog(worklog_data)
mock_post.assert_called_once_with("worklogs", data=worklog_data, **{})
assert result == {"id": 2, "issueKey": "TEST-1", "timeSpentSeconds": 3600}
@patch.object(TempoCloud, "put")
def test_update_worklog(self, mock_put, tempo_cloud):
"""Test update_worklog method."""
worklog_data = {"timeSpentSeconds": 7200}
mock_put.return_value = {"id": 1, "timeSpentSeconds": 7200}
result = tempo_cloud.update_worklog(1, worklog_data)
mock_put.assert_called_once_with("worklogs/1", data=worklog_data, **{})
assert result == {"id": 1, "timeSpentSeconds": 7200}
@patch.object(TempoCloud, "delete")
def test_delete_worklog(self, mock_delete, tempo_cloud):
"""Test delete_worklog method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_worklog(1)
mock_delete.assert_called_once_with("worklogs/1", **{})
assert result == {"success": True}
# Schedule Management Tests
@patch.object(TempoCloud, "get")
def test_get_schedules(self, mock_get, tempo_cloud):
"""Test get_schedules method."""
mock_get.return_value = [{"id": 1, "name": "Test Schedule"}]
result = tempo_cloud.get_schedules()
mock_get.assert_called_once_with("schedules", **{})
assert result == [{"id": 1, "name": "Test Schedule"}]
@patch.object(TempoCloud, "get")
def test_get_schedule(self, mock_get, tempo_cloud):
"""Test get_schedule method."""
mock_get.return_value = {"id": 1, "name": "Test Schedule"}
result = tempo_cloud.get_schedule(1)
mock_get.assert_called_once_with("schedules/1", **{})
assert result == {"id": 1, "name": "Test Schedule"}
@patch.object(TempoCloud, "post")
def test_create_schedule(self, mock_post, tempo_cloud):
"""Test create_schedule method."""
schedule_data = {"name": "New Schedule", "userId": 1}
mock_post.return_value = {"id": 2, "name": "New Schedule", "userId": 1}
result = tempo_cloud.create_schedule(schedule_data)
mock_post.assert_called_once_with("schedules", data=schedule_data, **{})
assert result == {"id": 2, "name": "New Schedule", "userId": 1}
@patch.object(TempoCloud, "put")
def test_update_schedule(self, mock_put, tempo_cloud):
"""Test update_schedule method."""
schedule_data = {"name": "Updated Schedule"}
mock_put.return_value = {"id": 1, "name": "Updated Schedule"}
result = tempo_cloud.update_schedule(1, schedule_data)
mock_put.assert_called_once_with("schedules/1", data=schedule_data, **{})
assert result == {"id": 1, "name": "Updated Schedule"}
@patch.object(TempoCloud, "delete")
def test_delete_schedule(self, mock_delete, tempo_cloud):
"""Test delete_schedule method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_schedule(1)
mock_delete.assert_called_once_with("schedules/1", **{})
assert result == {"success": True}
# User Management Tests
@patch.object(TempoCloud, "get")
def test_get_users(self, mock_get, tempo_cloud):
"""Test get_users method."""
mock_get.return_value = [{"id": 1, "name": "Test User"}]
result = tempo_cloud.get_users()
mock_get.assert_called_once_with("users", **{})
assert result == [{"id": 1, "name": "Test User"}]
@patch.object(TempoCloud, "get")
def test_get_user(self, mock_get, tempo_cloud):
"""Test get_user method."""
mock_get.return_value = {"id": 1, "name": "Test User"}
result = tempo_cloud.get_user(1)
mock_get.assert_called_once_with("users/1", **{})
assert result == {"id": 1, "name": "Test User"}
@patch.object(TempoCloud, "get")
def test_get_user_schedule(self, mock_get, tempo_cloud):
"""Test get_user_schedule method."""
mock_get.return_value = {"id": 1, "userId": 1}
result = tempo_cloud.get_user_schedule(1)
mock_get.assert_called_once_with("users/1/schedule", **{})
assert result == {"id": 1, "userId": 1}
@patch.object(TempoCloud, "get")
def test_get_user_worklogs(self, mock_get, tempo_cloud):
"""Test get_user_worklogs method."""
mock_get.return_value = [{"id": 1, "userId": 1}]
result = tempo_cloud.get_user_worklogs(1)
mock_get.assert_called_once_with("users/1/worklogs", **{})
assert result == [{"id": 1, "userId": 1}]
# Team Management Tests
@patch.object(TempoCloud, "get")
def test_get_teams(self, mock_get, tempo_cloud):
"""Test get_teams method."""
mock_get.return_value = [{"id": 1, "name": "Test Team"}]
result = tempo_cloud.get_teams()
mock_get.assert_called_once_with("teams", **{})
assert result == [{"id": 1, "name": "Test Team"}]
@patch.object(TempoCloud, "get")
def test_get_team(self, mock_get, tempo_cloud):
"""Test get_team method."""
mock_get.return_value = {"id": 1, "name": "Test Team"}
result = tempo_cloud.get_team(1)
mock_get.assert_called_once_with("teams/1", **{})
assert result == {"id": 1, "name": "Test Team"}
@patch.object(TempoCloud, "post")
def test_create_team(self, mock_post, tempo_cloud):
"""Test create_team method."""
team_data = {"name": "New Team"}
mock_post.return_value = {"id": 2, "name": "New Team"}
result = tempo_cloud.create_team(team_data)
mock_post.assert_called_once_with("teams", data=team_data, **{})
assert result == {"id": 2, "name": "New Team"}
@patch.object(TempoCloud, "put")
def test_update_team(self, mock_put, tempo_cloud):
"""Test update_team method."""
team_data = {"name": "Updated Team"}
mock_put.return_value = {"id": 1, "name": "Updated Team"}
result = tempo_cloud.update_team(1, team_data)
mock_put.assert_called_once_with("teams/1", data=team_data, **{})
assert result == {"id": 1, "name": "Updated Team"}
@patch.object(TempoCloud, "delete")
def test_delete_team(self, mock_delete, tempo_cloud):
"""Test delete_team method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_team(1)
mock_delete.assert_called_once_with("teams/1", **{})
assert result == {"success": True}
@patch.object(TempoCloud, "get")
def test_get_team_members(self, mock_get, tempo_cloud):
"""Test get_team_members method."""
mock_get.return_value = [{"id": 1, "name": "Member 1"}]
result = tempo_cloud.get_team_members(1)
mock_get.assert_called_once_with("teams/1/members", **{})
assert result == [{"id": 1, "name": "Member 1"}]
@patch.object(TempoCloud, "post")
def test_add_team_member(self, mock_post, tempo_cloud):
"""Test add_team_member method."""
mock_post.return_value = {"success": True}
result = tempo_cloud.add_team_member(1, 2)
mock_post.assert_called_once_with("teams/1/members", data={"userId": 2}, **{})
assert result == {"success": True}
@patch.object(TempoCloud, "delete")
def test_remove_team_member(self, mock_delete, tempo_cloud):
"""Test remove_team_member method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.remove_team_member(1, 2)
mock_delete.assert_called_once_with("teams/1/members/2", **{})
assert result == {"success": True}
# Project Management Tests
@patch.object(TempoCloud, "get")
def test_get_projects(self, mock_get, tempo_cloud):
"""Test get_projects method."""
mock_get.return_value = [{"id": 1, "name": "Test Project"}]
result = tempo_cloud.get_projects()
mock_get.assert_called_once_with("projects", **{})
assert result == [{"id": 1, "name": "Test Project"}]
@patch.object(TempoCloud, "get")
def test_get_project(self, mock_get, tempo_cloud):
"""Test get_project method."""
mock_get.return_value = {"id": 1, "name": "Test Project"}
result = tempo_cloud.get_project(1)
mock_get.assert_called_once_with("projects/1", **{})
assert result == {"id": 1, "name": "Test Project"}
@patch.object(TempoCloud, "get")
def test_get_project_worklogs(self, mock_get, tempo_cloud):
"""Test get_project_worklogs method."""
mock_get.return_value = [{"id": 1, "projectId": 1}]
result = tempo_cloud.get_project_worklogs(1)
mock_get.assert_called_once_with("projects/1/worklogs", **{})
assert result == [{"id": 1, "projectId": 1}]
# Activity Management Tests
@patch.object(TempoCloud, "get")
def test_get_activities(self, mock_get, tempo_cloud):
"""Test get_activities method."""
mock_get.return_value = [{"id": 1, "name": "Test Activity"}]
result = tempo_cloud.get_activities()
mock_get.assert_called_once_with("activities", **{})
assert result == [{"id": 1, "name": "Test Activity"}]
@patch.object(TempoCloud, "get")
def test_get_activity(self, mock_get, tempo_cloud):
"""Test get_activity method."""
mock_get.return_value = {"id": 1, "name": "Test Activity"}
result = tempo_cloud.get_activity(1)
mock_get.assert_called_once_with("activities/1", **{})
assert result == {"id": 1, "name": "Test Activity"}
@patch.object(TempoCloud, "post")
def test_create_activity(self, mock_post, tempo_cloud):
"""Test create_activity method."""
activity_data = {"name": "New Activity"}
mock_post.return_value = {"id": 2, "name": "New Activity"}
result = tempo_cloud.create_activity(activity_data)
mock_post.assert_called_once_with("activities", data=activity_data, **{})
assert result == {"id": 2, "name": "New Activity"}
@patch.object(TempoCloud, "put")
def test_update_activity(self, mock_put, tempo_cloud):
"""Test update_activity method."""
activity_data = {"name": "Updated Activity"}
mock_put.return_value = {"id": 1, "name": "Updated Activity"}
result = tempo_cloud.update_activity(1, activity_data)
mock_put.assert_called_once_with("activities/1", data=activity_data, **{})
assert result == {"id": 1, "name": "Updated Activity"}
@patch.object(TempoCloud, "delete")
def test_delete_activity(self, mock_delete, tempo_cloud):
"""Test delete_activity method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_activity(1)
mock_delete.assert_called_once_with("activities/1", **{})
assert result == {"success": True}
# Customer Management Tests
@patch.object(TempoCloud, "get")
def test_get_customers(self, mock_get, tempo_cloud):
"""Test get_customers method."""
mock_get.return_value = [{"id": 1, "name": "Test Customer"}]
result = tempo_cloud.get_customers()
mock_get.assert_called_once_with("customers", **{})
assert result == [{"id": 1, "name": "Test Customer"}]
@patch.object(TempoCloud, "get")
def test_get_customer(self, mock_get, tempo_cloud):
"""Test get_customer method."""
mock_get.return_value = {"id": 1, "name": "Test Customer"}
result = tempo_cloud.get_customer(1)
mock_get.assert_called_once_with("customers/1", **{})
assert result == {"id": 1, "name": "Test Customer"}
@patch.object(TempoCloud, "post")
def test_create_customer(self, mock_post, tempo_cloud):
"""Test create_customer method."""
customer_data = {"name": "New Customer"}
mock_post.return_value = {"id": 2, "name": "New Customer"}
result = tempo_cloud.create_customer(customer_data)
mock_post.assert_called_once_with("customers", data=customer_data, **{})
assert result == {"id": 2, "name": "New Customer"}
@patch.object(TempoCloud, "put")
def test_update_customer(self, mock_put, tempo_cloud):
"""Test update_customer method."""
customer_data = {"name": "Updated Customer"}
mock_put.return_value = {"id": 1, "name": "Updated Customer"}
result = tempo_cloud.update_customer(1, customer_data)
mock_put.assert_called_once_with("customers/1", data=customer_data, **{})
assert result == {"id": 1, "name": "Updated Customer"}
@patch.object(TempoCloud, "delete")
def test_delete_customer(self, mock_delete, tempo_cloud):
"""Test delete_customer method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_customer(1)
mock_delete.assert_called_once_with("customers/1", **{})
assert result == {"success": True}
# Holiday Management Tests
@patch.object(TempoCloud, "get")
def test_get_holidays(self, mock_get, tempo_cloud):
"""Test get_holidays method."""
mock_get.return_value = [{"id": 1, "name": "Test Holiday"}]
result = tempo_cloud.get_holidays()
mock_get.assert_called_once_with("holidays", **{})
assert result == [{"id": 1, "name": "Test Holiday"}]
@patch.object(TempoCloud, "get")
def test_get_holiday(self, mock_get, tempo_cloud):
"""Test get_holiday method."""
mock_get.return_value = {"id": 1, "name": "Test Holiday"}
result = tempo_cloud.get_holiday(1)
mock_get.assert_called_once_with("holidays/1", **{})
assert result == {"id": 1, "name": "Test Holiday"}
@patch.object(TempoCloud, "post")
def test_create_holiday(self, mock_post, tempo_cloud):
"""Test create_holiday method."""
holiday_data = {"name": "New Holiday", "date": "2024-01-01"}
mock_post.return_value = {"id": 2, "name": "New Holiday", "date": "2024-01-01"}
result = tempo_cloud.create_holiday(holiday_data)
mock_post.assert_called_once_with("holidays", data=holiday_data, **{})
assert result == {"id": 2, "name": "New Holiday", "date": "2024-01-01"}
@patch.object(TempoCloud, "put")
def test_update_holiday(self, mock_put, tempo_cloud):
"""Test update_holiday method."""
holiday_data = {"name": "Updated Holiday"}
mock_put.return_value = {"id": 1, "name": "Updated Holiday"}
result = tempo_cloud.update_holiday(1, holiday_data)
mock_put.assert_called_once_with("holidays/1", data=holiday_data, **{})
assert result == {"id": 1, "name": "Updated Holiday"}
@patch.object(TempoCloud, "delete")
def test_delete_holiday(self, mock_delete, tempo_cloud):
"""Test delete_holiday method."""
mock_delete.return_value = {"success": True}
result = tempo_cloud.delete_holiday(1)
mock_delete.assert_called_once_with("holidays/1", **{})
assert result == {"success": True}
# Report Generation Tests
@patch.object(TempoCloud, "post")
def test_generate_report(self, mock_post, tempo_cloud):
"""Test generate_report method."""
mock_post.return_value = {"reportId": "123"}
result = tempo_cloud.generate_report("timesheet", {"dateFrom": "2024-01-01"})
mock_post.assert_called_once_with("reports/timesheet", data={"dateFrom": "2024-01-01"}, **{})
assert result == {"reportId": "123"}
@patch.object(TempoCloud, "get")
def test_get_report_status(self, mock_get, tempo_cloud):
"""Test get_report_status method."""
mock_get.return_value = {"status": "completed"}
result = tempo_cloud.get_report_status("123")
mock_get.assert_called_once_with("reports/123/status", **{})
assert result == {"status": "completed"}
@patch.object(TempoCloud, "get")
def test_download_report(self, mock_get, tempo_cloud):
"""Test download_report method."""
mock_get.return_value = {"content": "report data"}
result = tempo_cloud.download_report("123")
mock_get.assert_called_once_with("reports/123/download", **{})
assert result == {"content": "report data"}
# Utility Methods Tests
@patch.object(TempoCloud, "get")
def test_get_metadata(self, mock_get, tempo_cloud):
"""Test get_metadata method."""
mock_get.return_value = {"version": "1.0.0"}
result = tempo_cloud.get_metadata()
mock_get.assert_called_once_with("metadata", **{})
assert result == {"version": "1.0.0"}
@patch.object(TempoCloud, "get")
def test_get_health(self, mock_get, tempo_cloud):
"""Test get_health method."""
mock_get.return_value = {"status": "healthy"}
result = tempo_cloud.get_health()
mock_get.assert_called_once_with("health", **{})
assert result == {"status": "healthy"}