def testCreate(self):
        xform, case = bootstrap_case_from_xml(self, "create.xml")
        self._check_static_properties(case)
        self.assertEqual(False, case.closed)

        self._check_transactions(case, [xform])
        self.assertTrue(case.transactions[0].is_case_create)
    def testCreateThenClose(self):
        xform1, case = bootstrap_case_from_xml(self, "create.xml")

        # now close it
        xform2, case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
        self.assertEqual(True, case.closed)

        if getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self._check_transactions(case, [xform1, xform2])
            self.assertTrue(case.transactions[0].is_case_create)
            self.assertTrue(case.transactions[1].is_case_close)
        else:
            self.assertEqual(3, len(case.actions))
            update_action = case.actions[1]
            close_action = case.actions[2]
            self.assertEqual(const.CASE_ACTION_UPDATE,
                             update_action.action_type)
            self.assertEqual(const.CASE_ACTION_CLOSE, close_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/close",
                             close_action.xform_xmlns)
            self.assertEqual("", close_action.xform_name)
            self.assertEqual(
                "abcde", update_action.updated_unknown_properties["someprop"])
            self.assertEqual(
                "case closed",
                update_action.updated_unknown_properties["someclosedprop"])
            self.assertEqual(CLOSE_DATE, close_action.date)

        self.assertEqual("abcde", case.dynamic_case_properties()["someprop"])
        self.assertEqual("case closed",
                         case.dynamic_case_properties()["someclosedprop"])
        self.assertEqual(CLOSE_DATE, case.modified_on)
    def testCreateThenClose(self):
        xform1, case = bootstrap_case_from_xml(self, "create.xml")

        # now close it
        xform2, case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
        self.assertEqual(True, case.closed)

        if getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self._check_transactions(case, [xform1, xform2])
            self.assertTrue(case.transactions[0].is_case_create)
            self.assertTrue(case.transactions[1].is_case_close)
        else:
            self.assertEqual(3, len(case.actions))
            update_action = case.actions[1]
            close_action = case.actions[2]
            self.assertEqual(const.CASE_ACTION_UPDATE, update_action.action_type)
            self.assertEqual(const.CASE_ACTION_CLOSE, close_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/close", close_action.xform_xmlns)
            self.assertEqual("", close_action.xform_name)
            self.assertEqual("abcde", update_action.updated_unknown_properties["someprop"])
            self.assertEqual("case closed", update_action.updated_unknown_properties["someclosedprop"])
            self.assertEqual(CLOSE_DATE, close_action.date)

        self.assertEqual("abcde", case.dynamic_case_properties()["someprop"])
        self.assertEqual("case closed", case.dynamic_case_properties()["someclosedprop"])
        self.assertEqual(CLOSE_DATE, case.modified_on)
Exemple #4
0
 def test_close(self):
     case_id = 'uid_blah_3'
     domain = "test.domain"
     case = bootstrap_case_from_xml(self,
                                    'create.xml',
                                    case_id_override=case_id)
     case.domain = domain
     case.save()
     referral_indexes = []
     case = CommCareCase.get(case_id)
     for i in referral_indexes:
         case.force_close_referral(case.referrals[i])
Exemple #5
0
    def testCreateThenUpdateInSeparateForms(self):
        # recycle our previous test's form
        original_case = bootstrap_case_from_xml(self, "create_update.xml")
        original_case.save()
        self.assertEqual(original_case.type, "test_case_type")
        self.assertEqual(original_case.name, "test case name")
        # we don't need to bother checking all the properties because this is
        # the exact same workflow as above.

        case = bootstrap_case_from_xml(self, "update.xml",
                                       original_case.case_id)
        self.assertEqual(False, case.closed)

        self.assertEqual(3, len(case.actions))
        new_update_action = case.actions[2]
        self.assertEqual(const.CASE_ACTION_UPDATE,
                         new_update_action.action_type)
        self.assertEqual("http://openrosa.org/case/test/update",
                         new_update_action.xform_xmlns)
        self.assertEqual("", new_update_action.xform_name)

        # some properties didn't change
        self.assertEqual("123", str(case["someotherprop"]))

        # but some should have
        self.assertEqual("abcd", case["someprop"])
        self.assertEqual(
            "abcd", new_update_action.updated_unknown_properties["someprop"])

        # and there are new ones
        self.assertEqual("efgh", case["somenewprop"])
        self.assertEqual(
            "efgh",
            new_update_action.updated_unknown_properties["somenewprop"])

        # we also changed everything originally in the case
        self.assertEqual("a_new_type", case.type)
        self.assertEqual("a_new_type",
                         new_update_action.updated_known_properties["type"])
        self.assertEqual("a new name", case.name)
        self.assertEqual("a new name",
                         new_update_action.updated_known_properties["name"])
        self.assertEqual(UPDATE_DATE, case.opened_on)
        self.assertEqual(
            UPDATE_DATE,
            new_update_action.updated_known_properties["opened_on"])

        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)

        self.assertEqual(0, len(case.referrals))
Exemple #6
0
 def testReferralOpen(self):
     case = bootstrap_case_from_xml(self, "create.xml")
     case.save()
     self.assertEqual(0, len(case.referrals))
     case = bootstrap_case_from_xml(self, "open_referral.xml", case.case_id)
     self.assertEqual(False, case.closed)
     self.assertEqual(1, len(case.actions))
     self.assertEqual(2, len(case.referrals))
     for referral in case.referrals:
         self.assertTrue(referral.type in ("t1", "t2"))
         self.assertEqual(False, referral.closed)
         self.assertEqual(REFER_DATE, referral.followup_on)
         self.assertEqual(case.modified_on, referral.modified_on)
         self.assertEqual(case.modified_on, referral.opened_on)
    def testCreateThenClose(self):
        xform1, case = bootstrap_case_from_xml(self, "create.xml")

        # now close it
        xform2, case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
        self.assertEqual(True, case.closed)

        self._check_transactions(case, [xform1, xform2])
        self.assertTrue(case.transactions[0].is_case_create)
        self.assertTrue(case.transactions[1].is_case_close)

        self.assertEqual("abcde", case.dynamic_case_properties()["someprop"])
        self.assertEqual("case closed",
                         case.dynamic_case_properties()["someclosedprop"])
        self.assertEqual(CLOSE_DATE, case.modified_on)
Exemple #8
0
    def testCreate(self):
        xform, case = bootstrap_case_from_xml(self, "create.xml")
        self._check_static_properties(case)
        self.assertEqual(False, case.closed)

        if getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self._check_transactions(case, [xform])
            self.assertTrue(case.transactions[0].is_case_create)
        else:
            self.assertEqual(1, len(case.actions))
            create_action = case.actions[0]
            self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/create", create_action.xform_xmlns)
            self.assertEqual(xform.form_id, create_action.xform_id)
            self.assertEqual("test create", create_action.xform_name)
    def testCreateThenUpdateInSeparateForms(self):
        # recycle our previous test's form
        xform1, original_case = bootstrap_case_from_xml(self, "create_update.xml")
        self.assertEqual(original_case.type, "test_case_type")
        self.assertEqual(original_case.name, "test case name")
        # we don't need to bother checking all the properties because this is
        # the exact same workflow as above.
        
        xform2, case = bootstrap_case_from_xml(self, "update.xml", original_case.case_id)
        # fetch the case from the DB to ensure it is property wrapped
        case = CaseAccessors().get_case(case.case_id)
        self.assertEqual(False, case.closed)

        if getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self._check_transactions(case, [xform1, xform2])
            self.assertTrue(case.transactions[0].is_case_create)
        else:
            self.assertEqual(3, len(case.actions))
            new_update_action = case.actions[2]
            self.assertEqual(const.CASE_ACTION_UPDATE, new_update_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/update", new_update_action.xform_xmlns)
            self.assertEqual("", new_update_action.xform_name)
            # updated prop
            self.assertEqual("abcd", new_update_action.updated_unknown_properties["someprop"])
            # new prop
            self.assertEqual("efgh", new_update_action.updated_unknown_properties["somenewprop"])

            # update original case fields
            self.assertEqual("a_new_type", new_update_action.updated_known_properties["type"])
            self.assertEqual("a new name", new_update_action.updated_known_properties["name"])
            self.assertEqual(UPDATE_DATE, new_update_action.updated_known_properties["opened_on"])

        # some properties didn't change
        self.assertEqual("123", str(case.dynamic_case_properties()['someotherprop']))

        # but some should have
        self.assertEqual("abcd", case.dynamic_case_properties()["someprop"])

        # and there are new ones
        self.assertEqual("efgh", case.dynamic_case_properties()["somenewprop"])

        # we also changed everything originally in the case
        self.assertEqual("a_new_type", case.type)
        self.assertEqual("a new name", case.name)
        self.assertEqual(coerce_to_datetime(UPDATE_DATE), coerce_to_datetime(case.opened_on))

        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)
Exemple #10
0
    def testCreateThenUpdateInSeparateForms(self):
        # recycle our previous test's form
        xform1, original_case = bootstrap_case_from_xml(self, "create_update.xml")
        self.assertEqual(original_case.type, "test_case_type")
        self.assertEqual(original_case.name, "test case name")
        # we don't need to bother checking all the properties because this is
        # the exact same workflow as above.
        
        xform2, case = bootstrap_case_from_xml(self, "update.xml", original_case.case_id)
        # fetch the case from the DB to ensure it is property wrapped
        case = CaseAccessors().get_case(case.case_id)
        self.assertEqual(False, case.closed)

        if getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self._check_transactions(case, [xform1, xform2])
            self.assertTrue(case.transactions[0].is_case_create)
        else:
            self.assertEqual(3, len(case.actions))
            new_update_action = case.actions[2]
            self.assertEqual(const.CASE_ACTION_UPDATE, new_update_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/update", new_update_action.xform_xmlns)
            self.assertEqual("", new_update_action.xform_name)
            # updated prop
            self.assertEqual("abcd", new_update_action.updated_unknown_properties["someprop"])
            # new prop
            self.assertEqual("efgh", new_update_action.updated_unknown_properties["somenewprop"])

            # update original case fields
            self.assertEqual("a_new_type", new_update_action.updated_known_properties["type"])
            self.assertEqual("a new name", new_update_action.updated_known_properties["name"])
            self.assertEqual(UPDATE_DATE, new_update_action.updated_known_properties["opened_on"])

        # some properties didn't change
        self.assertEqual("123", str(case.dynamic_case_properties()['someotherprop']))

        # but some should have
        self.assertEqual("abcd", case.dynamic_case_properties()["someprop"])

        # and there are new ones
        self.assertEqual("efgh", case.dynamic_case_properties()["somenewprop"])

        # we also changed everything originally in the case
        self.assertEqual("a_new_type", case.type)
        self.assertEqual("a new name", case.name)
        self.assertEqual(coerce_to_datetime(UPDATE_DATE), coerce_to_datetime(case.opened_on))

        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)
 def testCreate(self):
     case = bootstrap_case_from_xml(self, "create.xml")
     self._check_static_properties(case)
     self.assertEqual(False, case.closed)
     
     self.assertEqual(1, len(case.actions))
     create_action = case.actions[0]
     self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
     
     self.assertEqual(0, len(case.referrals))
 def testCreate(self):
     case = bootstrap_case_from_xml(self, "create.xml")
     self._check_static_properties(case)
     self.assertEqual(False, case.closed)
     
     self.assertEqual(1, len(case.actions))
     create_action = case.actions[0]
     self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
     self.assertEqual("http://openrosa.org/case/test/create", create_action.xform_xmlns)
     self.assertEqual("test create", create_action.xform_name)
Exemple #13
0
    def testCreateThenUpdateInSeparateForms(self):
        # recycle our previous test's form
        original_case = bootstrap_case_from_xml(self, "create_update.xml")
        original_case.save()
        self.assertEqual(original_case.type, "test_case_type")
        self.assertEqual(original_case.name, "test case name")
        # we don't need to bother checking all the properties because this is
        # the exact same workflow as above.
        
        case = bootstrap_case_from_xml(self, "update.xml", original_case.case_id)
        self.assertEqual(False, case.closed)
        
        self.assertEqual(3, len(case.actions))
        new_update_action = case.actions[2]
        self.assertEqual(const.CASE_ACTION_UPDATE, new_update_action.action_type)
        self.assertEqual("http://openrosa.org/case/test/update", new_update_action.xform_xmlns)
        self.assertEqual("", new_update_action.xform_name)

        # some properties didn't change
        self.assertEqual("123", str(case["someotherprop"]))
        
        # but some should have
        self.assertEqual("abcd", case["someprop"])
        self.assertEqual("abcd", new_update_action.updated_unknown_properties["someprop"])
        
        # and there are new ones
        self.assertEqual("efgh", case["somenewprop"])
        self.assertEqual("efgh", new_update_action.updated_unknown_properties["somenewprop"])
        
        # we also changed everything originally in the case
        self.assertEqual("a_new_type", case.type)
        self.assertEqual("a_new_type", new_update_action.updated_known_properties["type"])
        self.assertEqual("a new name", case.name)
        self.assertEqual("a new name", new_update_action.updated_known_properties["name"])        
        self.assertEqual(UPDATE_DATE, case.opened_on)
        self.assertEqual(UPDATE_DATE, new_update_action.updated_known_properties["opened_on"])
        
        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)
        
        self.assertEqual(0, len(case.referrals))
Exemple #14
0
class CaseFromXFormTest(TestCase):
    
    def testCreate(self):
        case = bootstrap_case_from_xml(self, "create.xml")
        self._check_static_properties(case)
        self.assertEqual(False, case.closed)
        
        self.assertEqual(1, len(case.actions))
        create_action = case.actions[0]
        self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
        self.assertEqual("http://openrosa.org/case/test/create", create_action.xform_xmlns)
        self.assertEqual("test create", create_action.xform_name)
    def testCreateThenClose(self):
        case = bootstrap_case_from_xml(self, "create.xml")

        # now close it
        case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
        self.assertEqual(True, case.closed)
        
        self.assertEqual(3, len(case.actions))
        update_action = case.actions[1]
        close_action = case.actions[2]
        self.assertEqual(const.CASE_ACTION_UPDATE, update_action.action_type)
        self.assertEqual(const.CASE_ACTION_CLOSE, close_action.action_type)
        self.assertEqual("http://openrosa.org/case/test/close", close_action.xform_xmlns)
        self.assertEqual("", close_action.xform_name)

        self.assertEqual("abcde", case["someprop"])
        self.assertEqual("abcde", update_action.updated_unknown_properties["someprop"])
        self.assertEqual("case closed", case["someclosedprop"])
        self.assertEqual("case closed", update_action.updated_unknown_properties["someclosedprop"])
        
        self.assertEqual(CLOSE_DATE, close_action.date)
        self.assertEqual(CLOSE_DATE, case.modified_on)
Exemple #16
0
 def testReferralUpdate(self):
     case = bootstrap_case_from_xml(self, "create.xml")
     case.save()
     case = bootstrap_case_from_xml(self, "open_referral.xml", case.case_id)
     case.save()
     case = bootstrap_case_from_xml(self, "update_referral.xml", case.case_id, case.referrals[0].referral_id)
     self.assertEqual(False, case.closed)
     self.assertEqual(1, len(case.actions))
     self.assertEqual(2, len(case.referrals))
     self.assertEqual(MODIFY_2_DATE, case.modified_on)
     for referral in case.referrals:
         self.assertEqual(False, referral.closed)
         if referral.type == "t1":
             self.assertEqual(REFER_DATE_UPDATE, referral.followup_on)
             self.assertEqual(case.modified_on, referral.modified_on)
             self.assertEqual(MODIFY_DATE, referral.opened_on)
         elif referral.type == "t2":
             self.assertEqual(REFER_DATE, referral.followup_on)
             self.assertEqual(MODIFY_DATE, referral.modified_on)
             self.assertEqual(MODIFY_DATE, referral.opened_on)
         else:
             self.fail("Unexpected referral type %s!" % referral.type)
Exemple #17
0
 def testCreate(self):
     from casexml.apps.case import settings
     settings.CASEXML_FORCE_DOMAIN_CHECK = False
     case = bootstrap_case_from_xml(self, "create.xml")
     self._check_static_properties(case)
     self.assertEqual(False, case.closed)
     
     self.assertEqual(1, len(case.actions))
     create_action = case.actions[0]
     self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
     self.assertEqual("http://openrosa.org/case/test/create", create_action.xform_xmlns)
     self.assertEqual("test create", create_action.xform_name)
     self.assertEqual(0, len(case.referrals))
Exemple #18
0
 def test_close(self):
     case_id = 'uid_blah_3'
     domain = "test.domain"
     case = bootstrap_case_from_xml(self, 'create.xml', case_id_override=case_id)
     case.domain = domain
     case.save()
     referral_indexes=[]
     case = CommCareCase.get(case_id)
     for i in referral_indexes:
         case.force_close_referral(case.referrals[i])
     case.force_close("/a/{domain}/receiver".format(domain=domain))
     case = CommCareCase.get(case_id)
     self.failUnless(case.closed)
 def testCreateThenClose(self):
     case = bootstrap_case_from_xml(self, "create.xml")
     case.save()
             
     # now close it
     case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
     self.assertEqual(True, case.closed)
     
     self.assertEqual(3, len(case.actions))
     update_action = case.actions[1]
     close_action = case.actions[2]
     self.assertEqual(const.CASE_ACTION_UPDATE, update_action.action_type)
     self.assertEqual(const.CASE_ACTION_CLOSE, close_action.action_type)
     
     self.assertEqual("abcde", case["someprop"])
     self.assertEqual("abcde", update_action.updated_unknown_properties["someprop"])
     self.assertEqual("case closed", case["someclosedprop"])
     self.assertEqual("case closed", update_action.updated_unknown_properties["someclosedprop"])
     
     self.assertEqual(CLOSE_DATE, close_action.date)
     self.assertEqual(CLOSE_DATE, case.modified_on)
     self.assertEqual(0, len(case.referrals))
    def testCreate(self):
        xform, case = bootstrap_case_from_xml(self, "create.xml")
        self._check_static_properties(case)
        self.assertEqual(False, case.closed)

        if settings.TESTS_SHOULD_USE_SQL_BACKEND:
            self._check_transactions(case, [xform])
        else:
            self.assertEqual(1, len(case.actions))
            create_action = case.actions[0]
            self.assertEqual(const.CASE_ACTION_CREATE, create_action.action_type)
            self.assertEqual("http://openrosa.org/case/test/create", create_action.xform_xmlns)
            self.assertEqual(xform.form_id, create_action.xform_id)
            self.assertEqual("test create", create_action.xform_name)
Exemple #21
0
    def testCreateThenUpdateInSeparateForms(self):
        # recycle our previous test's form
        xform1, original_case = bootstrap_case_from_xml(
            self, "create_update.xml")
        self.assertEqual(original_case.type, "test_case_type")
        self.assertEqual(original_case.name, "test case name")
        # we don't need to bother checking all the properties because this is
        # the exact same workflow as above.

        xform2, case = bootstrap_case_from_xml(self, "update.xml",
                                               original_case.case_id)
        # fetch the case from the DB to ensure it is property wrapped
        case = CommCareCase.objects.get_case(case.case_id, case.domain)
        self.assertEqual(False, case.closed)

        self._check_transactions(case, [xform1, xform2])
        self.assertTrue(case.transactions[0].is_case_create)

        # some properties didn't change
        self.assertEqual("123",
                         str(case.dynamic_case_properties()['someotherprop']))

        # but some should have
        self.assertEqual("abcd", case.dynamic_case_properties()["someprop"])

        # and there are new ones
        self.assertEqual("efgh", case.dynamic_case_properties()["somenewprop"])

        # we also changed everything originally in the case
        self.assertEqual("a_new_type", case.type)
        self.assertEqual("a new name", case.name)
        self.assertEqual(coerce_to_datetime(UPDATE_DATE),
                         coerce_to_datetime(case.opened_on))

        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)
 def test_close(self):
     case_id = 'uid_blah_3'
     domain = "test.domain"
     create_domain(domain)
     case = bootstrap_case_from_xml(
         self,
         filename='create.xml',
         case_id_override=case_id,
         domain=domain,
     )
     case.save()
     referral_indexes=[]
     case = CommCareCase.get(case_id)
     for i in referral_indexes:
         case.force_close_referral(case.referrals[i])
     case.force_close("/a/{domain}/receiver".format(domain=domain))
     case = CommCareCase.get(case_id)
     self.assertTrue(case.closed)
Exemple #23
0
                         new_update_action.updated_known_properties["type"])
        self.assertEqual("a new name", case.name)
        self.assertEqual("a new name",
                         new_update_action.updated_known_properties["name"])
        self.assertEqual(UPDATE_DATE, case.opened_on)
        self.assertEqual(
            UPDATE_DATE,
            new_update_action.updated_known_properties["opened_on"])

        # case should have a new modified date
        self.assertEqual(MODIFY_DATE, case.modified_on)

        self.assertEqual(0, len(case.referrals))

    def testCreateThenClose(self):
        case = bootstrap_case_from_xml(self, "create.xml")
        case.save()

        # now close it
        case = bootstrap_case_from_xml(self, "close.xml", case.case_id)
        self.assertEqual(True, case.closed)

        self.assertEqual(3, len(case.actions))
        update_action = case.actions[1]
        close_action = case.actions[2]
        self.assertEqual(const.CASE_ACTION_UPDATE, update_action.action_type)
        self.assertEqual(const.CASE_ACTION_CLOSE, close_action.action_type)
        self.assertEqual("http://openrosa.org/case/test/close",
                         close_action.xform_xmlns)
        self.assertEqual("", close_action.xform_name)