Convert all template strings to unicode

(imported from commit ddf60d53d30a02e1bb87fac35bb45768d17e378c)
This commit is contained in:
Jason Michalski
2015-02-08 21:38:20 -08:00
parent 179bf06940
commit 3ad140e5a7
2 changed files with 18 additions and 18 deletions

View File

@@ -802,7 +802,7 @@ class PagerDutyHookTests(AuthedTestCase):
self.assertEqual(msg.subject, 'incident 48219') self.assertEqual(msg.subject, 'incident 48219')
self.assertEqual( self.assertEqual(
msg.content, msg.content,
':healthy_heart: Incident [48219](https://dropbox.pagerduty.com/incidents/PJKGZF9) resolved\n\n>mp_error_block_down_critical' u':healthy_heart: Incident [48219](https://dropbox.pagerduty.com/incidents/PJKGZF9) resolved\n\n>mp_error_block_down_critical\u2119\u01b4'
) )
def test_bad_message(self): def test_bad_message(self):

View File

@@ -968,40 +968,40 @@ def build_pagerdudy_formatdict(message):
trigger_description = message['data']['incident']['trigger_summary_data'].get('description', '') trigger_description = message['data']['incident']['trigger_summary_data'].get('description', '')
if trigger_description: if trigger_description:
trigger_message.append(trigger_description) trigger_message.append(trigger_description)
format_dict['trigger_message'] = '\n'.join(trigger_message) format_dict['trigger_message'] = u'\n'.join(trigger_message)
return format_dict return format_dict
def send_raw_pagerduty_json(user_profile, stream, message): def send_raw_pagerduty_json(user_profile, stream, message):
subject = 'pagerduty' subject = 'pagerduty'
body = ( body = (
'Unknown pagerdudy message\n' u'Unknown pagerdudy message\n'
'``` py\n' u'``` py\n'
'%s\n' u'%s\n'
'```') % (pprint.pformat(message),) u'```') % (pprint.pformat(message),)
check_send_message(user_profile, get_client('ZulipPagerDutyWebhook'), 'stream', check_send_message(user_profile, get_client('ZulipPagerDutyWebhook'), 'stream',
[stream], subject, body) [stream], subject, body)
def send_formated_pagerduty(user_profile, stream, message_type, format_dict): def send_formated_pagerduty(user_profile, stream, message_type, format_dict):
if message_type in ('incident.trigger', 'incident.unacknowledge'): if message_type in ('incident.trigger', 'incident.unacknowledge'):
template = (':unhealthy_heart: Incident ' template = (u':unhealthy_heart: Incident '
'[{incident_num}]({incident_url}) {action} by ' u'[{incident_num}]({incident_url}) {action} by '
'[{service_name}]({service_url}) and assigned to ' u'[{service_name}]({service_url}) and assigned to '
'[{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}') u'[{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}')
elif message_type == 'incident.resolve' and format_dict['resolved_by_url']: elif message_type == 'incident.resolve' and format_dict['resolved_by_url']:
template = (':healthy_heart: Incident ' template = (u':healthy_heart: Incident '
'[{incident_num}]({incident_url}) resolved by ' u'[{incident_num}]({incident_url}) resolved by '
'[{resolved_by_username}@]({resolved_by_url})\n\n>{trigger_message}') u'[{resolved_by_username}@]({resolved_by_url})\n\n>{trigger_message}')
elif message_type == 'incident.resolve' and not format_dict['resolved_by_url']: elif message_type == 'incident.resolve' and not format_dict['resolved_by_url']:
template = (':healthy_heart: Incident ' template = (u':healthy_heart: Incident '
'[{incident_num}]({incident_url}) resolved\n\n>{trigger_message}') u'[{incident_num}]({incident_url}) resolved\n\n>{trigger_message}')
else: else:
template = (':average_heart: Incident [{incident_num}]({incident_url}) ' template = (u':average_heart: Incident [{incident_num}]({incident_url}) '
'{action} by [{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}') u'{action} by [{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}')
subject = 'incident {incident_num}'.format(**format_dict) subject = u'incident {incident_num}'.format(**format_dict)
body = template.format(**format_dict) body = template.format(**format_dict)
check_send_message(user_profile, get_client('ZulipPagerDutyWebhook'), 'stream', check_send_message(user_profile, get_client('ZulipPagerDutyWebhook'), 'stream',