2016-09-20 22:51:11 +02:00
# -*- coding: utf-8 -*-
import ujson
2017-11-16 00:43:10 +01:00
2016-11-10 19:30:09 +01:00
from zerver . lib . test_classes import WebhookTestCase
2017-11-16 00:43:10 +01:00
from zerver . models import Recipient
2016-09-20 22:51:11 +02:00
class TeamcityHookTests ( WebhookTestCase ) :
STREAM_NAME = ' teamcity '
URL_TEMPLATE = u " /api/v1/external/teamcity?stream= {stream} &api_key= {api_key} "
SUBJECT = u " Project :: Compile "
FIXTURE_DIR_NAME = ' teamcity '
2017-11-04 07:47:46 +01:00
def test_teamcity_success ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_message = u " Project :: Compile build 5535 - CL 123456 was successful! :thumbsup: \n Details: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952) "
self . send_and_test_stream_message ( ' success ' , self . SUBJECT , expected_message )
2017-11-04 07:47:46 +01:00
def test_teamcity_broken ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_message = u " Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbsdown: \n Details: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952) "
self . send_and_test_stream_message ( ' broken ' , self . SUBJECT , expected_message )
2017-11-04 07:47:46 +01:00
def test_teamcity_failure ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_message = u " Project :: Compile build 5535 - CL 123456 is still broken with status Exit code 1! :thumbsdown: \n Details: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952) "
self . send_and_test_stream_message ( ' failure ' , self . SUBJECT , expected_message )
2017-11-04 07:47:46 +01:00
def test_teamcity_fixed ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_message = u " Project :: Compile build 5535 - CL 123456 has been fixed! :thumbsup: \n Details: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952) "
self . send_and_test_stream_message ( ' fixed ' , self . SUBJECT , expected_message )
2017-11-04 07:47:46 +01:00
def test_teamcity_personal ( self ) - > None :
2016-09-20 22:51:11 +02:00
expected_message = u " Your personal build of Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbsdown: \n Details: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952) "
payload = ujson . dumps ( ujson . loads ( self . fixture_data ( self . FIXTURE_DIR_NAME , ' personal ' ) ) )
self . client_post ( self . url , payload , content_type = " application/json " )
msg = self . get_last_message ( )
self . assertEqual ( msg . content , expected_message )
self . assertEqual ( msg . recipient . type , Recipient . PERSONAL )