webhooks/gci: Support "unassign" event type.

This commit adds support for the "unassign" event type, the
payloads for which are generated when a mentor unassigns a student
from a task.
This commit is contained in:
Eeshan Garg 2018-01-02 17:49:34 -03:30 committed by showell
parent 2c7f4d2187
commit 18c3bec667
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{
"author_is_student": false,
"task_definition_name": "Sails unspread it stopped at kearney",
"event_type": "unassign",
"task_instance": 6296903092273152,
"task_claimed_by": "student-yqqtag",
"time": 1506475323.256627,
"id": "1f4bab4d1820400f9b50ed8bf2bb03b3",
"author": "eeshangarg",
"task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",
"task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"
}

View File

@ -55,3 +55,9 @@ class GoogleCodeInTests(WebhookTestCase):
expected_message = u'**eeshangarg** extended the deadline for the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/) by 1.0 day(s).'
self.send_and_test_stream_message('task_deadline_extended_by_mentor',
expected_subject, expected_message)
def test_unassign_event_message(self) -> None:
expected_subject = u'student-yqqtag'
expected_message = u'**eeshangarg** unassigned **student-yqqtag** from the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
self.send_and_test_stream_message('student_unassigned_by_mentor',
expected_subject, expected_message)

View File

@ -86,6 +86,14 @@ def get_extend_event_body(payload: Dict[Text, Any]) -> Text:
task_url=build_instance_url(payload['task_instance']),
)
def get_unassign_event_body(payload: Dict[Text, Any]) -> Text:
return GCI_MESSAGE_TEMPLATE.format(
actor=payload['author'],
action='unassigned **{student}** from'.format(student=payload['task_claimed_by']),
task_name=payload['task_definition_name'],
task_url=build_instance_url(payload['task_instance']),
)
@api_key_only_webhook_view("Google-Code-In")
@has_request_variables
def api_gci_webhook(request: HttpRequest, user_profile: UserProfile, stream: Text=REQ(default='gci'),
@ -110,6 +118,7 @@ EVENTS_FUNCTION_MAPPER = {
'extend': get_extend_event_body,
'needswork': get_needswork_event_body,
'submit': get_submit_event_body,
'unassign': get_unassign_event_body,
}
def get_event(payload: Dict[Text, Any]) -> Optional[Text]: