From 30b6fd27b3ae7b4e302871ca485ef1fd0b164506 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Fri, 2 Oct 2020 14:21:17 -0400 Subject: [PATCH] fix a display bug in notification bodies with unicode characters see: https://github.com/ansible/awx/issues/7400 --- awx/main/models/notifications.py | 6 +++++- awx/main/tests/functional/models/test_notifications.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index c374f6042081..11d97c7690df 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -393,7 +393,11 @@ def context(self, serialized_job): 'job': job_context, 'job_friendly_name': self.get_notification_friendly_name(), '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): diff --git a/awx/main/tests/functional/models/test_notifications.py b/awx/main/tests/functional/models/test_notifications.py index 8d514312ae6b..5e5f19f0fd8c 100644 --- a/awx/main/tests/functional/models/test_notifications.py +++ b/awx/main/tests/functional/models/test_notifications.py @@ -123,6 +123,15 @@ def check_structure(expected_structure, obj): context = job.context(job_serialization) 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): """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