2016-09-20 22:51:11 +02:00
# -*- coding: utf-8 -*-
2016-12-04 18:38:56 +01:00
from typing import Text
2017-11-16 00:43:10 +01:00
2016-11-10 19:30:09 +01:00
from zerver . lib . test_classes import WebhookTestCase
2016-09-20 22:51:11 +02:00
class JiraHookTests ( WebhookTestCase ) :
STREAM_NAME = ' jira '
2018-03-16 22:53:50 +01:00
URL_TEMPLATE = u " /api/v1/external/jira?api_key= {api_key} &stream= {stream} "
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_unknown ( self ) - > None :
2016-09-20 22:51:11 +02:00
url = self . build_webhook_url ( )
result = self . client_post ( url ,
2017-01-30 19:26:48 +01:00
self . get_body ( ' unknown_v1 ' ) ,
stream_name = " jira " ,
content_type = " application/json " )
2017-03-21 20:34:19 +01:00
self . assert_json_success ( result )
2017-01-30 19:26:48 +01:00
result = self . client_post ( url ,
self . get_body ( ' unknown_v2 ' ) ,
2016-09-20 22:51:11 +02:00
stream_name = " jira " ,
content_type = " application/json " )
2017-03-21 20:34:19 +01:00
self . assert_json_success ( result )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_custom_stream ( self ) - > None :
2017-08-25 08:23:13 +02:00
api_key = self . test_user . api_key
2016-09-20 22:51:11 +02:00
url = " /api/v1/external/jira?api_key= %s &stream=jira_custom " % ( api_key , )
2017-08-25 06:37:47 +02:00
msg = self . send_json_payload ( self . test_user ,
2016-09-20 22:51:11 +02:00
url ,
2017-01-30 19:26:48 +01:00
self . get_body ( ' created_v2 ' ) ,
2016-09-20 22:51:11 +02:00
stream_name = " jira_custom " ,
content_type = " application/json " )
self . assertEqual ( msg . topic_name ( ) , " BUG-15: New bug with hook " )
2016-10-19 13:21:07 +02:00
self . assertEqual ( msg . content , """ Leo Franchi **created** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) priority Major, assigned to **no one**:
2016-09-20 22:51:11 +02:00
> New bug with hook """ )
2017-11-04 07:47:46 +01:00
def test_created ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " BUG-15: New bug with hook "
2016-10-19 13:21:07 +02:00
expected_message = """ Leo Franchi **created** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) priority Major, assigned to **no one**:
2016-09-20 22:51:11 +02:00
> New bug with hook """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' created_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' created_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_created_with_unicode ( self ) - > None :
2017-03-15 21:23:51 +01:00
expected_subject = u " BUG-15: New bug with à hook "
expected_message = u """ Leo Franchià **created** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) priority Major, assigned to **no one**:
> New bug with à hook """
self . send_and_test_stream_message ( ' created_with_unicode_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' created_with_unicode_v2 ' , expected_subject , expected_message )
2017-11-04 07:47:46 +01:00
def test_created_assignee ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " TEST-4: Test Created Assignee "
2016-10-19 13:21:07 +02:00
expected_message = """ Leonardo Franchi [Administrator] **created** [TEST-4](https://zulipp.atlassian.net/browse/TEST-4) priority Major, assigned to **Leonardo Franchi [Administrator]**:
2016-09-20 22:51:11 +02:00
> Test Created Assignee """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' created_assignee_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' created_assignee_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_commented ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " BUG-15: New bug with hook "
2017-01-03 18:44:13 +01:00
expected_message = """ Leo Franchi **added comment to** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
2016-09-20 22:51:11 +02:00
2017-02-12 04:22:13 +01:00
Adding a comment . Oh , what a comment it is ! """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' commented_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' commented_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_comment_edited ( self ) - > None :
2017-01-03 18:44:13 +01:00
expected_subject = " BUG-15: New bug with hook "
expected_message = """ Leo Franchi **edited comment on** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
2017-02-12 04:22:13 +01:00
Adding a comment . Oh , what a comment it is ! """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' comment_edited_v2 ' , expected_subject , expected_message )
2017-01-03 18:44:13 +01:00
2017-11-04 07:47:46 +01:00
def test_comment_deleted ( self ) - > None :
2017-01-03 18:44:13 +01:00
expected_subject = " TOM-1: New Issue "
expected_message = " Tomasz Kolek **deleted comment from** [TOM-1](https://zuliptomek.atlassian.net/browse/TOM-1) (assigned to **kolaszek@go2.pl**) "
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' comment_deleted_v2 ' , expected_subject , expected_message )
2017-01-03 18:44:13 +01:00
2017-11-04 07:47:46 +01:00
def test_commented_markup ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " TEST-7: Testing of rich text "
2017-02-12 04:22:13 +01:00
expected_message = """ Leonardo Franchi [Administrator] **added comment to** [TEST-7](https://zulipp.atlassian.net/browse/TEST-7): \n \n \n This is a comment that likes to **exercise** a lot of _different_ `conventions` that `jira uses`. \r \n \r \n ~~~ \n \r \n this code is not highlighted, but monospaced \r \n \n ~~~ \r \n \r \n ~~~ \n \r \n def python(): \r \n print " likes to be formatted " \r \n \n ~~~ \r \n \r \n [http://www.google.com](http://www.google.com) is a bare link, and [Google](http://www.google.com) is given a title. \r \n \r \n Thanks! \r \n \r \n ~~~ quote \n \r \n Someone said somewhere \r \n \n ~~~ """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' commented_markup_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' commented_markup_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_deleted ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " BUG-15: New bug with hook "
expected_message = " Leo Franchi **deleted** [BUG-15](http://lfranchi.com:8080/browse/BUG-15)! "
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' deleted_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' deleted_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_reassigned ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " BUG-15: New bug with hook "
2016-10-19 13:21:07 +02:00
expected_message = """ Leo Franchi **updated** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
2016-09-20 22:51:11 +02:00
2017-02-12 04:22:13 +01:00
* Changed assignee to * * Othello , the Moor of Venice * * """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' reassigned_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' reassigned_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_priority_updated ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = " TEST-1: Fix That "
expected_message = """ Leonardo Franchi [Administrator] **updated** [TEST-1](https://zulipp.atlassian.net/browse/TEST-1) (assigned to **leo@zulip.com**):
2017-02-12 04:22:13 +01:00
* Changed priority from * * Critical * * to * * Major * * """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' updated_priority_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' updated_priority_v2 ' , expected_subject , expected_message )
2017-11-04 07:47:46 +01:00
def test_status_changed ( self ) - > None :
2017-01-30 19:26:48 +01:00
expected_subject = " TEST-1: Fix That "
expected_message = """ Leonardo Franchi [Administrator] **updated** [TEST-1](https://zulipp.atlassian.net/browse/TEST-1):
2017-02-12 04:22:13 +01:00
* Changed status from * * To Do * * to * * In Progress * * """
2017-01-30 19:26:48 +01:00
self . send_and_test_stream_message ( ' change_status_v1 ' , expected_subject , expected_message )
self . send_and_test_stream_message ( ' change_status_v2 ' , expected_subject , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def get_body ( self , fixture_name : Text ) - > Text :
2018-04-20 03:57:21 +02:00
return self . webhook_fixture_data ( ' jira ' , fixture_name )