2016-09-20 22:51:11 +02:00
# -*- coding: utf-8 -*-
2016-12-04 18:38:56 +01:00
from typing import Text
2016-11-10 19:30:09 +01:00
from zerver . lib . test_classes import WebhookTestCase
2016-09-20 22:51:11 +02:00
class PivotalV3HookTests ( WebhookTestCase ) :
STREAM_NAME = ' pivotal '
URL_TEMPLATE = u " /api/v1/external/pivotal?stream= {stream} &api_key= {api_key} "
2017-11-04 07:47:46 +01:00
def test_accepted ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' My new Feature story '
expected_message = ' Leo Franchi accepted " My new Feature story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48276573 ) '
self . send_and_test_stream_message ( ' accepted ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_commented ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Comment added '
expected_message = ' Leo Franchi added comment: " FIX THIS NOW " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48276573 ) '
self . send_and_test_stream_message ( ' commented ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_created ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' My new Feature story '
expected_message = ' Leo Franchi added " My new Feature story " \
( unscheduled feature ) : \n \n ~ ~ ~ quote \nThis is my long description \n ~ ~ ~ \n \n \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48276573 ) '
self . send_and_test_stream_message ( ' created ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_delivered ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Another new story '
expected_message = ' Leo Franchi delivered " Another new story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48278289 ) '
self . send_and_test_stream_message ( ' delivered ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_finished ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Another new story '
expected_message = ' Leo Franchi finished " Another new story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48278289 ) '
self . send_and_test_stream_message ( ' finished ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_moved ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' My new Feature story '
expected_message = ' Leo Franchi edited " My new Feature story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48276573 ) '
self . send_and_test_stream_message ( ' moved ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_rejected ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Another new story '
expected_message = ' Leo Franchi rejected " Another new story " with comments: \
" Not good enough, sorry " [ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48278289 ) '
self . send_and_test_stream_message ( ' rejected ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_started ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Another new story '
expected_message = ' Leo Franchi started " Another new story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48278289 ) '
self . send_and_test_stream_message ( ' started ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_created_estimate ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' Another new story '
expected_message = ' Leo Franchi added " Another new story " \
( unscheduled feature worth 2 story points ) : \n \n ~ ~ ~ quote \nSome loong description \n ~ ~ ~ \n \n \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48278289 ) '
self . send_and_test_stream_message ( ' created_estimate ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_type_changed ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' My new Feature story '
expected_message = ' Leo Franchi edited " My new Feature story " \
[ ( view ) ] ( https : / / www . pivotaltracker . com / s / projects / 807213 / stories / 48276573 ) '
self . send_and_test_stream_message ( ' type_changed ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def get_body ( self , fixture_name : Text ) - > Text :
2016-09-20 22:51:11 +02:00
return self . fixture_data ( ' pivotal ' , fixture_name , file_type = ' xml ' )
class PivotalV5HookTests ( WebhookTestCase ) :
STREAM_NAME = ' pivotal '
URL_TEMPLATE = u " /api/v1/external/pivotal?stream= {stream} &api_key= {api_key} "
2017-11-04 07:47:46 +01:00
def test_accepted ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63486316: Story of the Year '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
2017-02-12 04:22:13 +01:00
* state changed from * * unstarted * * to * * accepted * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' accepted ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_commented ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63486316: Story of the Year '
expected_message = """ Leo Franchi added a comment to [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
~ ~ ~ quote
A comment on the story
~ ~ ~ """
self . send_and_test_stream_message ( ' commented ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_created ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63495662: Story that I created '
expected_message = """ Leo Franchi created bug: [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story that I created](http://www.pivotaltracker.com/story/show/63495662)
* State is * * unscheduled * *
* Description is
> What a description """
self . send_and_test_stream_message ( ' created ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_delivered ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63486316: Story of the Year '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
2017-02-12 04:22:13 +01:00
* state changed from * * accepted * * to * * delivered * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' delivered ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_finished ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63486316: Story of the Year '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
2017-02-12 04:22:13 +01:00
* state changed from * * delivered * * to * * accepted * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' finished ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_moved ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63496066: Pivotal Test '
expected_message = """ Leo Franchi moved [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066) from **unstarted** to **unscheduled** """
self . send_and_test_stream_message ( ' moved ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_rejected ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63486316: Story of the Year '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
* Comment added :
~ ~ ~ quote
Try again next time
~ ~ ~
2017-02-12 04:22:13 +01:00
* state changed from * * delivered * * to * * rejected * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' rejected ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_started ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63495972: Fresh Story '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Fresh Story](http://www.pivotaltracker.com/story/show/63495972):
2017-02-12 04:22:13 +01:00
* state changed from * * unstarted * * to * * started * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' started ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_created_estimate ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63496066: Pivotal Test '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066):
2017-02-12 04:22:13 +01:00
* estimate is now * * 3 points * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' created_estimate ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def test_type_changed ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_subject = ' #63496066: Pivotal Test '
expected_message = """ Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066):
* estimate changed from 3 to * * 0 points * *
2017-02-12 04:22:13 +01:00
* type changed from * * feature * * to * * bug * * """
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message ( ' type_changed ' , expected_subject , expected_message , content_type = " application/xml " )
2017-11-04 07:47:46 +01:00
def get_body ( self , fixture_name : Text ) - > Text :
2016-09-20 22:51:11 +02:00
return self . fixture_data ( ' pivotal ' , " v5_ {} " . format ( fixture_name ) , file_type = ' json ' )