def test_case_template_params(self): with self.create_child_case() as case: r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("No template variables"), "No template variables") self.assertEqual(r.render("Case's name is {case.name}"), "Case's name is P002") self.assertEqual( r.render( "Multiple properties: {case.name}, {case.child_prop1}"), "Multiple properties: P002, def") self.assertEqual( r.render("Unicode property: {case.unicode_property}"), "Unicode property: \u0928\u092e\u0938\u094d\u0924\u0947") self.assertEqual(r.render("Don't render case: {case}"), "Don't render case: (?)") self.assertEqual(r.render("Unknown property: {case.unknown}"), "Unknown property: (?)") self.assertEqual( r.render("Unknown property: {case.unknown.unknown}"), "Unknown property: (?)") self.assertEqual(r.render("Unknown param: {x}"), "Unknown param: (?)")
def test_host_case_template_params(self): with self.create_child_case() as extension_case, self.create_parent_case() as host_case: set_parent_case(self.domain, extension_case, host_case, relationship='extension') extension_case = CaseAccessors(self.domain).get_case(extension_case.case_id) r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(extension_case)) self.assertEqual( r.render("Extension case prop: {case.child_prop1}"), "Extension case prop: def" ) self.assertEqual( r.render("Host case prop: {case.host.parent_prop1}"), "Host case prop: abc" ) self.assertEqual( r.render("Don't render case: {case.host}"), "Don't render case: (?)" ) self.assertEqual( r.render("No host host case: {case.host.host.name}"), "No host host case: (?)" ) self.assertEqual( r.render("No parent case: {case.parent.name}"), "No parent case: (?)" )
def test_parent_case_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) r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(child_case)) self.assertEqual( r.render("Child case prop: {case.child_prop1}"), "Child case prop: def" ) self.assertEqual( r.render("Parent case prop: {case.parent.parent_prop1}"), "Parent case prop: abc" ) self.assertEqual( r.render("Don't render case: {case.parent}"), "Don't render case: (?)" ) self.assertEqual( r.render("No grandparent case: {case.parent.parent.name}"), "No grandparent case: (?)" ) self.assertEqual( r.render("No host case: {case.host.name}"), "No host case: (?)" )
def test_host_case_template_params(self): with self.create_child_case() as extension_case, self.create_parent_case() as host_case: set_parent_case(self.domain, extension_case, host_case, relationship='extension') extension_case = CaseAccessors(self.domain).get_case(extension_case.case_id) r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(extension_case)) self.assertEqual( r.render("Extension case prop: {case.child_prop1}"), "Extension case prop: def" ) self.assertEqual( r.render("Host case prop: {case.host.parent_prop1}"), "Host case prop: abc" ) self.assertEqual( r.render("Don't render case: {case.host}"), "Don't render case: (?)" ) self.assertEqual( r.render("No host host case: {case.host.host.name}"), "No host host case: (?)" ) self.assertEqual( r.render("No parent case: {case.parent.name}"), "No parent case: (?)" )
def test_parent_case_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) r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(child_case)) self.assertEqual( r.render("Child case prop: {case.child_prop1}"), "Child case prop: def" ) self.assertEqual( r.render("Parent case prop: {case.parent.parent_prop1}"), "Parent case prop: abc" ) self.assertEqual( r.render("Don't render case: {case.parent}"), "Don't render case: (?)" ) self.assertEqual( r.render("No grandparent case: {case.parent.parent.name}"), "No grandparent case: (?)" ) self.assertEqual( r.render("No host case: {case.host.name}"), "No host case: (?)" )
def get_template_renderer(self, recipient): r = MessagingTemplateRenderer() r.set_context_param('recipient', SimpleDictTemplateParam(_get_obj_template_info(recipient))) if self.case_rendering_context: r.set_context_param('case', self.case_rendering_context) return r
def test_case_template_params(self): with self.create_child_case() as case: r = MessagingTemplateRenderer() r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual( r.render("No template variables"), "No template variables" ) self.assertEqual( r.render("Case's name is {case.name}"), "Case's name is P002" ) self.assertEqual( r.render("Multiple properties: {case.name}, {case.child_prop1}"), "Multiple properties: P002, def" ) self.assertEqual( r.render("Unicode property: {case.unicode_property}"), "Unicode property: \u0928\u092e\u0938\u094d\u0924\u0947" ) self.assertEqual( r.render("Don't render case: {case}"), "Don't render case: (?)" ) self.assertEqual( r.render("Unknown property: {case.unknown}"), "Unknown property: (?)" ) self.assertEqual( r.render("Unknown property: {case.unknown.unknown}"), "Unknown property: (?)" ) self.assertEqual( r.render("Unknown param: {x}"), "Unknown param: (?)" )
def test_modified_by_template_params(self): r = MessagingTemplateRenderer() with self.create_parent_case(modified_by=self.mobile_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: mobile1") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: Mobile") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: 999123") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(modified_by=self.web_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: web1@templating-test") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: Web") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: 999456") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)") with create_test_case(self.domain, 'person', 'Joe', user_id='system') as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: System") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: System") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: ") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: ") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)")
def test_owner_template_params(self): r = MessagingTemplateRenderer() with self.create_parent_case(owner=self.mobile_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: mobile1") self.assertEqual(r.render("First Name: {case.owner.first_name}"), "First Name: Mobile") self.assertEqual(r.render("Last Name: {case.owner.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.owner.phone_number}"), "Phone: 999123") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.web_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: web1@templating-test") self.assertEqual(r.render("First Name: {case.owner.first_name}"), "First Name: Web") self.assertEqual(r.render("Last Name: {case.owner.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.owner.phone_number}"), "Phone: 999456") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.group) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: Test Group") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.location) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: Test Location") self.assertEqual(r.render("Site Code: {case.owner.site_code}"), "Site Code: loc1234") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)")
def test_modified_by_template_params(self): r = MessagingTemplateRenderer() with self.create_parent_case(modified_by=self.mobile_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: mobile1") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: Mobile") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: 999123") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(modified_by=self.web_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: web1@templating-test") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: Web") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: 999456") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)") with create_test_case(self.domain, 'person', 'Joe', user_id='system') as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.last_modified_by.name}"), "Name: System") self.assertEqual(r.render("First Name: {case.last_modified_by.first_name}"), "First Name: System") self.assertEqual(r.render("Last Name: {case.last_modified_by.last_name}"), "Last Name: ") self.assertEqual(r.render("Phone: {case.last_modified_by.phone_number}"), "Phone: ") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.last_modified_by.unknown.unknown}"), "Unknown: (?)")
def test_owner_template_params(self): r = MessagingTemplateRenderer() with self.create_parent_case(owner=self.mobile_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: mobile1") self.assertEqual(r.render("First Name: {case.owner.first_name}"), "First Name: Mobile") self.assertEqual(r.render("Last Name: {case.owner.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.owner.phone_number}"), "Phone: 999123") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.web_user) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: web1@templating-test") self.assertEqual(r.render("First Name: {case.owner.first_name}"), "First Name: Web") self.assertEqual(r.render("Last Name: {case.owner.last_name}"), "Last Name: User") self.assertEqual(r.render("Phone: {case.owner.phone_number}"), "Phone: 999456") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.group) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: Test Group") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)") with self.create_parent_case(owner=self.location) as case: r.set_context_param('case', CaseMessagingTemplateParam(case)) self.assertEqual(r.render("Name: {case.owner.name}"), "Name: Test Location") self.assertEqual(r.render("Site Code: {case.owner.site_code}"), "Site Code: loc1234") self.assertEqual(r.render("Unknown: {case.owner.unknown}"), "Unknown: (?)") self.assertEqual(r.render("Unknown: {case.owner.unknown.unknown}"), "Unknown: (?)")