forked from aarose/togglwrapper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
773 lines (679 loc) · 26.3 KB
/
tests.py
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
# -*- coding: utf-8 -*-
"""
tests
-----
Ensures that certain actions in the togglwrapper library result in certain
behaviours.
Uses the responses library to mock out the requests library, and loads fixtures
from ``fixtures/`` for the mock JSON response output.
"""
import json
import os
import unittest
import responses
from requests.exceptions import HTTPError
from togglwrapper import api
from togglwrapper.exceptions import AuthError
FAKE_TOKEN = 'fake_token_1'
FIXTURES_PATH = '%s/fixtures' % os.path.dirname(os.path.abspath(__file__))
class TestTogglBase(unittest.TestCase):
"""Class to establish utility methods for Test classes."""
api_token = FAKE_TOKEN
organization_id = 9876
workspace_id = 1234
focus_class = None
def compile_full_url(self, id=None, ids=None, child_uri=None, parent_uri=None):
"""Compile a full URL from the base url."""
focus_class_instance = self.focus_class(self.toggl)
uri = focus_class_instance._compile_uri(
id=id, ids=ids, child_uri=child_uri, parent_uri=parent_uri
)
return self.toggl.api_url + uri
def setUp(self):
self.toggl = api.Toggl(self.api_token, self.organization_id, self.workspace_id)
def get_json(self, filename):
"""Return the JSON data in the .json file with the given filename."""
file_path = '{path}/{filename}.json'.format(
path=FIXTURES_PATH, filename=filename
)
with open(file_path) as json_file:
json_dict = json.load(json_file)
json_file.close()
raw_json = json.dumps(json_dict)
return raw_json
def responses_add(
self,
method,
filename=None,
id=None,
ids=None,
child_uri=None,
parent_uri=None,
status_code=200,
content_type='',
):
"""Adds a mock response for requests to a certain url."""
body = None
if filename is not None:
body = self.get_json(filename)
content_type = 'application/json'
responses.add(
getattr(responses, method),
self.compile_full_url(
id=id, ids=ids, child_uri=child_uri, parent_uri=parent_uri
),
body=body,
status=status_code,
content_type=content_type,
)
class TestToggl(TestTogglBase):
"""Tests the main Toggl client Class."""
@responses.activate
def test_wrong_token(self):
"""Should raise exception when wrong API token is provided."""
full_url = self.toggl.api_url + self.toggl.User.uri
responses.add(responses.GET, full_url, status=403)
self.assertRaises(AuthError, self.toggl.User.get)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_failed_request(self):
"""Should raise an HTTPError with status code 404."""
full_url = (
self.toggl.api_url
+ '/workspaces/{}'.format(self.toggl.workspace_id)
+ self.toggl.TimeEntries.uri
)
responses.add(
responses.POST,
full_url,
body=self.get_json('failed_request'),
status=404,
)
wrong_data = {
'description': 'New time entry',
'created_with': 'API example code',
}
self.assertRaises(HTTPError, self.toggl.TimeEntries.create, data=wrong_data)
# Ensure that the error message in the response is the exception reason
reason = json.loads(self.get_json('failed_request'))
try:
self.toggl.TimeEntries.create(data=wrong_data)
except HTTPError as e:
self.assertEqual(e.response.reason, reason)
else:
raise Exception('Reason was not correct.')
# Ensure that the mocked response was triggered twice
self.assertEqual(len(responses.calls), 2)
@responses.activate
def test_invite(self):
"""Should invite users to the given organization."""
full_uri = (
self.toggl.api_url
+ '/organizations/{}'.format(self.organization_id)
+ '/invite'
)
responses.add(
responses.POST,
full_uri,
body=self.get_json('workspace_invite'),
content_type='application/json',
status=200,
)
data = {'emails': ['john.doe@toggl.com', 'Jane.Swift@toggl.com']}
response = self.toggl.invite(data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestClients(TestTogglBase):
focus_class = api.Clients
@responses.activate
def test_create(self):
"""Should create a new Client."""
self.responses_add('POST', filename='client_create')
create_data = {'name': 'Very Big Company', 'wid': 777}
response = self.toggl.Clients.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
"""Should get a specific Client by ID."""
inst_id = 1239455
self.responses_add('GET', filename='client_get', id=inst_id)
response = self.toggl.Clients.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get(self):
"""Should get all Clients."""
self.responses_add('GET', filename='clients_get')
response = self.toggl.Clients.get()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a Client."""
inst_id = 1239455
self.responses_add('PUT', filename='client_update', id=inst_id)
update_data = {
'client': {
'name': 'Very Big Company',
'notes': 'something about the client',
}
}
response = self.toggl.Clients.update(
id=inst_id,
data=update_data,
parent_uri='/workspaces/{}'.format(self.workspace_id),
)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a Client."""
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Clients.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestDashboard(TestTogglBase):
focus_class = api.Dashboard
@responses.activate
def test_get(self):
"""Should get the dashboard info for a given Workspace."""
self.responses_add('GET', filename='dashboard')
response = self.toggl.Dashboard.get()
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestProjects(TestTogglBase):
focus_class = api.Projects
@responses.activate
def test_create(self):
"""Should create a new Project."""
self.responses_add('POST', filename='project_create')
project_data = {
'project': {
'name': 'An awesome project',
'wid': 777,
'template_id': 10237,
'is_private': True,
'cid': 123397,
}
}
response = self.toggl.Projects.create(project_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
"""Should get a specific Project by ID."""
inst_id = 193838628
self.responses_add('GET', filename='project_get', id=inst_id)
response = self.toggl.Projects.get(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a Project."""
inst_id = 193838628
self.responses_add('PUT', filename='project_update', id=inst_id)
update_data = {
'project': {
'name': 'Changed the name',
'is_private': False,
'cid': 123398,
'color': '6',
}
}
response = self.toggl.Projects.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a Project."""
inst_id = 4692190
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Projects.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_project_users_get(self):
"""Should get Project Users under the Project."""
inst_id = 193838628
fixture_name = 'project_projectusers_get'
self.focus_class = api.ProjectUsers
self.responses_add('GET', filename=fixture_name)
response = self.toggl.Projects.get_project_users([inst_id])
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tasks_get(self):
"""Should get Tasks under the Project."""
inst_id = 777
self.responses_add(
'GET', filename='project_tasks_get', id=inst_id, child_uri='/tasks'
)
response = self.toggl.Projects.get_tasks(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
class TestProjectUsers(TestTogglBase):
focus_class = api.ProjectUsers
@responses.activate
def test_create(self):
"""Should create a new ProjectUser."""
self.responses_add('POST', filename='projectuser_create')
create_data = {
'project_user': {'pid': 777, 'uid': 123, 'rate': 4.0, 'manager': True}
}
response = self.toggl.ProjectUsers.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a ProjectUser."""
inst_id = 4692190
self.responses_add('PUT', filename='projectuser_update', id=inst_id)
update_data = {
'project_user': {'manager': False, 'rate': 15, 'fields': 'fullname'}
}
response = self.toggl.ProjectUsers.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a ProjectUser."""
inst_id = 4692190
self.responses_add('DELETE', id=inst_id)
response = self.toggl.ProjectUsers.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_patch(self):
"""Should update multiple ProjectUsers."""
ids = (4692190, 4692192, 4692191)
self.responses_add('PATCH', 'projectusers_update_multiple', ids=ids)
update_data = {'manager': False, 'rate': 15, 'fields': 'fullname'}
response = self.toggl.ProjectUsers.patch(ids=ids, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestTags(TestTogglBase):
focus_class = api.Tags
@responses.activate
def test_create(self):
"""Should create a new Tag."""
self.responses_add('POST', filename='tag_create')
create_data = {'name': 'billed', 'wid': 777}
response = self.toggl.Tags.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a Tag."""
inst_id = 1239455
self.responses_add('PUT', filename='tag_update', id=inst_id)
update_data = {'name': 'not billed'}
response = self.toggl.Tags.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a Tag."""
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Tags.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestTasks(TestTogglBase):
focus_class = api.Tasks
@responses.activate
def test_create(self):
"""Should create a new Task."""
self.responses_add(
'POST',
parent_uri='/workspaces/{workspace_id}/projects/{project_id}'.format(
workspace_id=self.workspace_id, project_id=777
),
filename='task_create',
)
create_data = {'name': 'A new task', 'pid': 777}
response = self.toggl.Tasks.create(777, create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_all(self):
"""Should get all Tasks."""
project_id = 777
self.focus_class = api.Projects
self.responses_add(
'GET', filename='task_get', id=project_id, child_uri='/tasks'
)
response = self.toggl.Tasks.get(project_id=project_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
"""Should get a Task."""
task_id = 1335076912
project_id = 777
self.focus_class = api.Projects
self.responses_add(
'GET',
filename='task_get',
id=project_id,
child_uri='/tasks/{}'.format(task_id),
)
response = self.toggl.Tasks.get(task_id=task_id, project_id=project_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a Task."""
task_id = 1335076912
project_id = 777
self.focus_class = api.Projects
self.responses_add(
'PUT',
filename='task_update',
id=project_id,
child_uri='/tasks/{}'.format(task_id),
)
update_data = {
'active': False,
'estimated_seconds': 3600,
'fields': 'done_seconds,uname',
}
response = self.toggl.Tasks.update(project_id, task_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_patch(self):
"""Should patch multiple Tasks."""
task_ids = (1335076912, 1335076911)
project_id = 777
self.focus_class = api.Projects
self.responses_add(
'PATCH',
'tasks_update_multiple',
id=project_id,
child_uri='/tasks/{}'.format(",".join([str(id) for id in task_ids])),
)
update_data = {"task": {
"active": False,
"fields": "done_seconds,uname"
}}
response = self.toggl.Tasks.patch(project_id, task_ids, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a Task."""
task_id = 1335076912
project_id = 777
self.focus_class = api.Projects
self.responses_add(
'DELETE', id=project_id, child_uri='/tasks/{}'.format(task_id)
)
response = self.toggl.Tasks.delete(project_id, task_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestTimeEntries(TestTogglBase):
focus_class = api.TimeEntries
@responses.activate
def test_create(self):
"""Should create a new TimeEntry."""
self.responses_add('POST', filename='time_entry_create')
create_data = {
'description': 'Meeting with possible clients',
'tags': ['billed'],
'duration': 1200,
'start': '2013-03-05T07:58:58.000Z',
'pid': 123,
'created_with': 'togglwrapper',
}
response = self.toggl.TimeEntries.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_start(self):
"""Should start a TimeEntry."""
self.responses_add('POST', 'time_entry_start')
start_data = {
'description': 'Meeting with possible clients',
'tags': ['billed'],
'pid': 123,
'created_with': 'togglwrapper',
}
response = self.toggl.TimeEntries.start(start_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_stop(self):
"""Should stop a TimeEntry."""
inst_id = 436694100
self.responses_add(
'PATCH', filename='time_entry_stop', id=inst_id, child_uri='/stop'
)
response = self.toggl.TimeEntries.stop(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
"""Should get a TimeEntry."""
inst_id = 436694100
self.responses_add(
'GET', filename='time_entry_get', id=inst_id, parent_uri='/me'
)
response = self.toggl.TimeEntries.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_current(self):
"""Should get the current running TimeEntry."""
self.responses_add(
'GET', 'time_entry_current', parent_uri='/me', child_uri='/current'
)
response = self.toggl.TimeEntries.get_current()
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_in_time_range(self):
"""Should get the TimeEntries started in a specific time range."""
self.responses_add(
'GET', filename='time_entries_get_in_range', parent_uri='/me'
)
response = self.toggl.TimeEntries.get(
start_date='2013-03-10T15:42:46+02:00', end_date='2013-03-12T15:42:46+02:00'
)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a TimeEntry."""
inst_id = 436694100
self.responses_add('PATCH', filename='time_entry_update', id=inst_id)
update_data = {
'description': 'Meeting with possible clients',
'tags': [''],
'duration': 1240,
'start': '2013-03-05T07:58:58.000Z',
'stop': '2013-03-05T08:58:58.000Z',
'duronly': True,
'pid': 123,
'billable': True,
}
response = self.toggl.TimeEntries.patch(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a TimeEntry."""
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.TimeEntries.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestUser(TestTogglBase):
focus_class = api.User
@responses.activate
def test_get(self):
"""Should successfully get the User associated with the token."""
self.responses_add('GET', filename='user_get')
response = self.toggl.User.get()
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_with_related_data(self):
"""Should get the User associated with the token and related data."""
self.responses_add('GET', filename='user_get_with_related_data')
response = self.toggl.User.get(related_data=True)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update the User associated with the api token."""
self.responses_add('PUT', filename='user_update')
update_data = {'user': {'fullname': 'John Smith'}}
response = self.toggl.User.update(update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestWorkspaces(TestTogglBase):
focus_class = api.Workspaces
@responses.activate
def test_get(self):
"""Should successfully get an iterable of Workspaces."""
self.responses_add('GET', filename='workspaces_get')
response = self.toggl.Workspaces.get()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
"""Should successfully get a specific Workspace."""
inst_id = 3134975
self.responses_add('GET', filename='workspace_get', id=inst_id)
response = self.toggl.Workspaces.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a specific Workspace."""
inst_id = 3134975
self.responses_add('PUT', filename='workspace_update', id=inst_id)
update_data = {
'default_currency': 'EUR',
'default_hourly_rate': 50,
'name': "John's ws",
'only_admins_may_create_projects': False,
'only_admins_see_billable_rates': True,
'rounding': 1,
'rounding_minutes': 60,
}
response = self.toggl.Workspaces.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_users_get(self):
"""Should get Users under the Workspace."""
self.responses_add(
'GET',
filename='workspace_users',
id=self.workspace_id,
child_uri='/users',
parent_uri='/organizations/{organization_id}'.format(
organization_id=self.toggl.organization_id
),
)
response = self.toggl.Workspaces.get_users()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_projects_get(self):
"""Should get Projects under the Workspace."""
self.responses_add(
'GET', 'workspace_projects', id=self.workspace_id, child_uri='/projects'
)
response = self.toggl.Workspaces.get_projects()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tasks_get(self):
"""Should get Tasks under the Workspace."""
self.responses_add(
'GET', 'workspace_tasks', id=self.workspace_id, child_uri='/tasks'
)
response = self.toggl.Workspaces.get_tasks()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tags_get(self):
"""Should get Tags under the Workspace."""
self.responses_add(
'GET', 'workspace_tags', id=self.workspace_id, child_uri='/tags'
)
response = self.toggl.Workspaces.get_tags()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_workspace_users_get(self):
"""Should get WorkspaceUsers under the Workspace."""
self.responses_add(
'GET',
'workspace_workspaceusers',
id=self.workspace_id,
child_uri='/workspace_users',
parent_uri='/organizations/{organization_id}'.format(
organization_id=self.toggl.organization_id
),
)
response = self.toggl.Workspaces.get_workspace_users()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
class TestWorkspaceUsers(TestTogglBase):
focus_class = api.WorkspaceUsers
@responses.activate
def test_get(self):
"""Should update a specific WorkspaceUser."""
inst_id = 19012628
self.responses_add(
'GET',
filename='workspaceuser_update',
id=inst_id,
parent_uri='/organizations/{organization_id}/workspaces/{workspace_id}'.format(
organization_id=self.toggl.organization_id,
workspace_id=self.toggl.workspace_id,
),
)
response = self.toggl.WorkspaceUsers.get(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
"""Should update a specific WorkspaceUser."""
inst_id = 19012628
self.responses_add('PUT', filename='workspaceuser_update', id=inst_id)
update_data = {'admin': False}
response = self.toggl.WorkspaceUsers.update(inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_patch(self):
"""Should update a specific WorkspaceUser."""
inst_ids = [19012628]
self.responses_add(
'PATCH',
filename='workspaceuser_update',
parent_uri='/organizations/{organization_id}/workspaces/{workspace_id}'.format(
organization_id=self.toggl.organization_id,
workspace_id=self.toggl.workspace_id,
),
)
response = self.toggl.WorkspaceUsers.patch(ids=inst_ids)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
"""Should delete a specific WorkspaceUser."""
inst_id = 19012628
self.responses_add('DELETE', id=inst_id)
response = self.toggl.WorkspaceUsers.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
if __name__ == '__main__' and __package__ is None:
__package__ = 'toggl'
unittest.main()