def test_parent_cases(self): with _with_case(self.domain, 'test-child-case-type', datetime(2016, 1, 1)) as child, \ _with_case(self.domain, 'test-parent-case-type', datetime(2016, 1, 1), case_name='abc') as parent: # Set the parent case relationship child = set_parent_case(self.domain, child, parent) # Create a rule that references parent/name which should match rule = AutomaticUpdateRule( domain=self.domain, name='test-parent-rule', case_type='test-child-case-type', active=True, server_modified_boundary=30, ) rule.save() self.addCleanup(rule.delete) AutomaticUpdateRuleCriteria.objects.create( property_name='parent/name', property_value='abc', match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL, rule=rule, ) AutomaticUpdateAction.objects.create( action=AutomaticUpdateAction.ACTION_UPDATE, property_name='parent/update_flag', property_value='P', rule=rule, ) AutomaticUpdateAction.objects.create( action=AutomaticUpdateAction.ACTION_UPDATE, property_name='parent_name', property_value='parent/name', property_value_type=AutomaticUpdateAction.CASE_PROPERTY, rule=rule, ) # rule should match on parent case property and update parent case rule.apply_rule(child, datetime(2016, 3, 1)) updated_parent = self.case_db.get_case(parent.case_id) updated_child = self.case_db.get_case(child.case_id) self.assertEqual(updated_parent.get_case_property('update_flag'), 'P') self.assertEqual(updated_child.get_case_property('parent_name'), 'abc') # Update the rule to match on a different name and now it shouldn't match rule.automaticupdaterulecriteria_set.all().delete() AutomaticUpdateRuleCriteria.objects.create( property_name='parent/name', property_value='def', match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL, rule=rule, ) self.assertFalse( rule.rule_matches_case(child, datetime(2016, 3, 1)))
def test_parent_cases(self): with _with_case(self.domain, 'test-child-case-type', datetime(2016, 1, 1)) as child, \ _with_case(self.domain, 'test-parent-case-type', datetime(2016, 1, 1), case_name='abc') as parent: # Set the parent case relationship child = set_parent_case(self.domain, child, parent) # Create a rule that references parent/name which should match rule = AutomaticUpdateRule( domain=self.domain, name='test-parent-rule', case_type='test-child-case-type', active=True, server_modified_boundary=30, ) rule.save() self.addCleanup(rule.delete) AutomaticUpdateRuleCriteria.objects.create( property_name='parent/name', property_value='abc', match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL, rule=rule, ) AutomaticUpdateAction.objects.create( action=AutomaticUpdateAction.ACTION_UPDATE, property_name='parent/update_flag', property_value='P', rule=rule, ) AutomaticUpdateAction.objects.create( action=AutomaticUpdateAction.ACTION_UPDATE, property_name='parent_name', property_value='parent/name', property_value_type=AutomaticUpdateAction.CASE_PROPERTY, rule=rule, ) # rule should match on parent case property and update parent case rule.apply_rule(child, datetime(2016, 3, 1)) updated_parent = self.case_db.get_case(parent.case_id) updated_child = self.case_db.get_case(child.case_id) self.assertEqual(updated_parent.get_case_property('update_flag'), 'P') self.assertEqual(updated_child.get_case_property('parent_name'), 'abc') # Update the rule to match on a different name and now it shouldn't match rule.automaticupdaterulecriteria_set.all().delete() AutomaticUpdateRuleCriteria.objects.create( property_name='parent/name', property_value='def', match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL, rule=rule, ) self.assertFalse(rule.rule_matches_case(child, datetime(2016, 3, 1)))