old_contents: from casexml.apps.case.models import CommCareCase
  from casexml.apps.case.sharedmodels import CommCareCaseIndex
  from corehq.apps.reminders.event_handlers import get_message_template_params
  from corehq.apps.reminders.models import Message
  from corehq.apps.reminders.tests.utils import BaseReminderTestCase
  from corehq.form_processor.tests.utils import set_case_property_directly
  from datetime import datetime, timedelta
  
  
  class MessageTestCase(BaseReminderTestCase):
  
      def setUp(self):
          self.domain = "test"
  
          self.parent_case = CommCareCase(
              domain=self.domain,
              type="parent",
              name="P001",
          )
          set_case_property_directly(self.parent_case, "parent_prop1", "abc")
          self.parent_case.save()
  
          self.child_case = CommCareCase(
              domain=self.domain,
              type="child",
              name="P002",
              indices=[CommCareCaseIndex(
                  identifier="parent",
                  referenced_type="parent",
                  referenced_id=self.parent_case._id,
              )],
          )
          set_case_property_directly(self.child_case, "child_prop1", "def")
          self.child_case.save()
  
      def tearDown(self):
          self.child_case.delete()
          self.parent_case.delete()
  
      def test_message(self):
          message = 'The EDD for client with ID {case.external_id} is approaching in {case.edd.days_until} days.'
          case = {'external_id': 123, 'edd': datetime.utcnow() + timedelta(days=30)}
          outcome = 'The EDD for client with ID 123 is approaching in 30 days.'
          self.assertEqual(Message.render(message, case=case), outcome)
  
      def test_template_params(self):
          child_result = {"case": self.child_case.case_properties()}
          child_result["case"]["parent"] = self.parent_case.case_properties()
          self.assertEqual(
              get_message_template_params(self.child_case), child_result)
  
          parent_result = {"case": self.parent_case.case_properties()}
          parent_result["case"]["parent"] = {}
          self.assertEqual(
              get_message_template_params(self.parent_case), parent_result)
  
new_contents: from corehq.apps.reminders.event_handlers import get_message_template_params
  from corehq.apps.reminders.models import Message
  from corehq.form_processor.interfaces.dbaccessors import CaseAccessors
  from corehq.form_processor.tests.utils import run_with_all_backends
  from corehq.util.test_utils import create_test_case, set_parent_case
  from datetime import datetime, timedelta
  from django.test import TestCase
  
  
  class MessageTestCase(TestCase):
  
      def setUp(self):
          self.domain = 'message-formatting-test'
  
      def test_message(self):
          message = 'The EDD for client with ID {case.external_id} is approaching in {case.edd.days_until} days.'
          case_json = {'external_id': 123, 'edd': datetime.utcnow() + timedelta(days=30)}
          expected = 'The EDD for client with ID 123 is approaching in 30 days.'
          self.assertEqual(Message.render(message, case=case_json), expected)
  
      def create_child_case(self):
          return create_test_case(self.domain, 'child', 'P002', case_properties={'child_prop1': 'def'})
  
      def create_parent_case(self):
          return create_test_case(self.domain, 'parent', 'P001', case_properties={'parent_prop1': 'abc'})
  
      @run_with_all_backends
      def test_template_params(self):
          with self.create_child_case() as child_case, self.create_parent_case() as parent_case:
              set_parent_case(self.domain, child_case, parent_case)
              child_case = CaseAccessors(self.domain).get_case(child_case.case_id)
              parent_case = CaseAccessors(self.domain).get_case(parent_case.case_id)
  
              child_result = {'case': child_case.to_json()}
              child_result['case']['parent'] = parent_case.to_json()
              self.assertEqual(get_message_template_params(child_case), child_result)
  
              parent_result = {'case': parent_case.to_json()}
              parent_result['case']['parent'] = {}
              self.assertEqual(get_message_template_params(parent_case), parent_result)
  
subject: Update message formatting tests