webhooks/gci: Support 'needswork' event_type.

This commit adds support for payloads that are generated when a
mentor submits a task for more work.
This commit is contained in:
Eeshan Garg 2017-11-02 16:46:11 -02:30
parent 9969a3a40b
commit 20f3e9b779
3 changed files with 32 additions and 3 deletions

View File

@ -0,0 +1,12 @@
{
"task_definition_url":"http://localhost:8080/dashboard/tasks/6051711999279104/",
"task_claimed_by":"student-yqqtag",
"event_type":"needswork",
"author":"eeshangarg",
"task_instance_url":"http://localhost:8080/dashboard/task-instances/6051711999279104/",
"task_definition_name":"Sails unspread it stopped at kearney",
"time":1509576007.257213,
"id":"19f30988c86045bfbc6aacd789cd3a92",
"task_instance":5136918324969472,
"author_is_student":false
}

View File

@ -43,3 +43,10 @@ class GoogleCodeInTests(WebhookTestCase):
expected_message = u'**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
self.send_and_test_stream_message('task_approved_by_mentor',
expected_subject, expected_message)
def test_needswork_event_message(self):
# type: () -> None
expected_subject = u'Task: Sails unspread it stopped at kearney'
expected_message = u'**eeshangarg** submitted the task [Sails unspread it stopped at kearney](http://localhost:8080/dashboard/tasks/6051711999279104/) for more work.'
self.send_and_test_stream_message('task_submitted_by_mentor_for_more_work',
expected_subject, expected_message)

View File

@ -59,6 +59,15 @@ def get_approve_event_body(payload):
task_url=payload['task_definition_url'],
)
def get_needswork_event_body(payload):
# type: (Dict[Text, Any]) -> Text
template = "{} for more work.".format(GCI_MESSAGE_TEMPLATE.rstrip('.'))
return template.format(
actor=payload['author'],
action='submitted',
task_name=payload['task_definition_name'],
task_url=payload['task_definition_url'],
)
@api_key_only_webhook_view("Google-Code-In")
@has_request_variables
@ -78,10 +87,11 @@ def api_gci_webhook(request, user_profile, stream=REQ(default='gci'),
EVENTS_FUNCTION_MAPPER = {
'abandon': get_abandon_event_body,
'comment': get_comment_event_body,
'submit': get_submit_event_body,
'claim': get_claim_event_body,
'approve': get_approve_event_body,
'claim': get_claim_event_body,
'comment': get_comment_event_body,
'needswork': get_needswork_event_body,
'submit': get_submit_event_body,
}
def get_event(payload):