Skip to content

Commit 65febeb

Browse files
authored
Allow creating task with action and completion_rule. (#544)
1 parent 3e11538 commit 65febeb

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ used to interact with the Box API. This is a list of contributors.
1212
- `@capk1rk <https://github.com/capk1rk>`_
1313
- `@aculler <https://github.com/aculler>`_
1414
- `@ben-reilly <https://github.com/ben-reilly>`_
15+
- `@ab <https://github.com/ab>`_

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Next Release
77
++++++++
88
- Allow ints to be passed in as item IDs
99
- Fix bug with updating a collaboration role to owner
10+
- Allow creating tasks with the `action` and `completion_rule` parameters.
1011
- Add support for `copyInstanceOnItemCopy` field for metadata templates
1112

1213
2.9.0 (2020-06-23)

boxsdk/object/file.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ def add_comment(self, message):
531531
)
532532

533533
@api_call
534-
def create_task(self, message=None, due_at=None):
534+
def create_task(self, message=None, due_at=None, action='review',
535+
completion_rule=None):
535536
"""
536537
Create a task on the given file.
537538
@@ -543,6 +544,17 @@ def create_task(self, message=None, due_at=None):
543544
When this task is due.
544545
:type due_at:
545546
`unicode` or None
547+
:param action:
548+
The type of task the task assignee will be prompted to perform.
549+
Value is one of review,complete
550+
:type action:
551+
`unicode`
552+
:param completion_rule:
553+
Defines which assignees need to complete this task before the task
554+
is considered completed.
555+
Value is one of all_assignees,any_assignee
556+
:type completion_rule:
557+
`unicode` or None
546558
:return:
547559
The newly created task
548560
:rtype:
@@ -554,12 +566,14 @@ def create_task(self, message=None, due_at=None):
554566
'type': 'file',
555567
'id': self.object_id
556568
},
557-
'action': 'review',
569+
'action': action,
558570
}
559571
if message is not None:
560572
task_attributes['message'] = message
561573
if due_at is not None:
562574
task_attributes['due_at'] = due_at
575+
if completion_rule is not None:
576+
task_attributes['completion_rule'] = completion_rule
563577
box_response = self._session.post(url, data=json.dumps(task_attributes))
564578
response = box_response.json()
565579
return self.translator.translate(

test/unit/object/test_file.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,48 @@ def test_create_task(test_file, test_task, mock_box_session):
150150
assert new_task.due_at == due_at
151151

152152

153+
def test_create_task_with_review(test_file, test_task, mock_box_session):
154+
# pylint:disable=redefined-outer-name
155+
expected_url = "{0}/tasks".format(API.BASE_API_URL)
156+
due_at = '2020-09-18T12:09:43-00:00'
157+
action = 'complete'
158+
message = 'Test Message'
159+
completion_rule = 'any_assignee'
160+
expected_body = {
161+
'item': {
162+
'type': 'file',
163+
'id': '42',
164+
},
165+
'action': action,
166+
'message': message,
167+
'due_at': due_at,
168+
'completion_rule': completion_rule,
169+
}
170+
mock_box_session.post.return_value.json.return_value = {
171+
'type': test_task.object_type,
172+
'id': test_task.object_id,
173+
'due_at': due_at,
174+
'action': action,
175+
'message': message,
176+
'completion_rule': completion_rule,
177+
}
178+
value = json.dumps(expected_body)
179+
new_task = test_file.create_task(
180+
message=message,
181+
due_at=due_at,
182+
action=action,
183+
completion_rule=completion_rule,
184+
)
185+
mock_box_session.post.assert_called_once_with(expected_url, data=value)
186+
assert isinstance(new_task, Task)
187+
assert new_task.object_type == test_task.object_type
188+
assert new_task.object_id == test_task.object_id
189+
assert new_task.action == action
190+
assert new_task.message == message
191+
assert new_task.due_at == due_at
192+
assert new_task.completion_rule == completion_rule
193+
194+
153195
def test_get_tasks(test_file, mock_box_session):
154196
expected_url = test_file.get_url('tasks')
155197
task_body = {

0 commit comments

Comments
 (0)