Merge pull request #8313 from ryanpetrello/fix-garbled-unicode-in-notifications

fix a display bug in notification bodies with unicode characters

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-10-02 19:30:21 +00:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -393,7 +393,11 @@ class JobNotificationMixin(object):
'job': job_context, 'job': job_context,
'job_friendly_name': self.get_notification_friendly_name(), 'job_friendly_name': self.get_notification_friendly_name(),
'url': self.get_ui_url(), 'url': self.get_ui_url(),
'job_metadata': json.dumps(self.notification_data(), indent=4) 'job_metadata': json.dumps(
self.notification_data(),
ensure_ascii=False,
indent=4
)
} }
def build_context(node, fields, allowed_fields): def build_context(node, fields, allowed_fields):

View File

@@ -123,6 +123,15 @@ class TestJobNotificationMixin(object):
context = job.context(job_serialization) context = job.context(job_serialization)
check_structure(TestJobNotificationMixin.CONTEXT_STRUCTURE, context) check_structure(TestJobNotificationMixin.CONTEXT_STRUCTURE, context)
@pytest.mark.django_db
def test_context_job_metadata_with_unicode(self):
job = Job.objects.create(name='批量安装项目')
job_serialization = UnifiedJobSerializer(job).to_representation(job)
context = job.context(job_serialization)
assert '批量安装项目' in context['job_metadata']
def test_context_stub(self): def test_context_stub(self):
"""The context stub is a fake context used to validate custom notification messages. Ensure that """The context stub is a fake context used to validate custom notification messages. Ensure that
this also has the expected structure. Furthermore, ensure that the stub context contains this also has the expected structure. Furthermore, ensure that the stub context contains