示例#1
0
文件: meta.py 项目: adewinter/data-hq
 def testMetaData_1(self):
     create_xsd_and_populate("data/brac_chw.xsd", "data/brac_chw_1.xml", self.domain)
     populate("data/brac_chw_1.xml", domain=self.domain)
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM xformmanager_metadata where formname='BRAC CHW visiting CHP'" )
     row = cursor.fetchone()
     self.assertEquals(row[1],"BRAC CHW visiting CHP")
     self.assertEquals(row[2],"0.0.1")
     self.assertEquals(row[3],"P6PH9SR0TKCO6RVDL4YML1D2Y")
     if settings.DATABASE_ENGINE=='mysql' :
         self.assertEquals(row[4],datetime(2008,1,8,11,55,49))
         self.assertEquals(row[5],datetime(2008,1,8,12,8,39))
     else:
         self.assertEquals(row[4],datetime(2008,1,8,11,55,49,977))
         self.assertEquals(row[5],datetime(2008,1,8,12,8,39,258))
     self.assertEquals(row[6],"cary")
     self.assertEquals(row[7],"99")
     self.assertEquals(row[8],"Z6WRHCRXYQO1C1V6B2SB3RBG8")
     
     cursor.execute("SELECT * FROM schema_metadomain_brac_chw_chwvisit_v0_0_1")
     row = cursor.fetchone()
     self.assertEquals(row[0],1)
     # checks to make sure that non-standard meta fields remain in the generated data table
     self.assertEquals(row[3],"0.0.5") # this is commcareversion number
     self.assertEquals(row[10],"worker")
     self.assertEquals(row[11],3)
     """ use these when we finally remove meta info from generate data tables
示例#2
0
文件: meta.py 项目: adewinter/data-hq
 def testMetaData_3(self):
     create_xsd_and_populate("data/pf_followup.xsd", "data/pf_followup_1.xml", self.domain)
     populate("data/pf_followup_2.xml", domain=self.domain)
     create_xsd_and_populate("data/pf_new_reg.xsd", "data/pf_new_reg_1.xml", self.domain)
     populate("data/pf_new_reg_2.xml", domain=self.domain)
     create_xsd_and_populate("data/pf_ref_completed.xsd", "data/pf_ref_completed_1.xml", self.domain)
     populate("data/pf_ref_completed_2.xml", domain=self.domain)
     create_xsd_and_populate("data/mvp_mother_reg.xsd", "data/mvp_mother_reg_1.xml", self.domain)
     populate("data/mvp_mother_reg_2.xml", domain=self.domain)
     populate("data/mvp_mother_reg_3.xml", domain=self.domain)
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM xformmanager_metadata order by id")
     row = cursor.fetchall()
     
     latest_attachment_id = ( Attachment.objects.latest('id') ).id
     latest_formdefmodel_id = ( FormDefModel.objects.latest('id') ).id
     
     self.assertEquals(row[0][1],"PathfinderFollowUpVisit")
     self.assertEquals(row[0][9],latest_attachment_id-8)
     self.assertEquals(row[0][10],1)
     self.assertEquals(row[0][11],latest_formdefmodel_id-3)
     self.assertEquals(row[1][1],"PathfinderFollowUpVisit")
     self.assertEquals(row[2][1],"PathfinderRegistratonVisit")
     self.assertEquals(row[3][1],"PathfinderRegistratonVisit")
     self.assertEquals(row[3][9],latest_attachment_id-5)
     self.assertEquals(row[3][10],2)
     self.assertEquals(row[3][11],latest_formdefmodel_id-2)
     self.assertEquals(row[4][1],"PathfinderReferralVisit")
     self.assertEquals(row[5][1],"PathfinderReferralVisit")
     self.assertEquals(row[6][1],"XOLIJZVDJKLORBQUABFLVGLEA")
     self.assertEquals(row[7][1],"XOLIJZVDJKLORBQUABFLVGLEA")
     self.assertEquals(row[8][1],"XOLIJZVDJKLORBQUABFLVGLEA")
     self.assertEquals(row[8][9],latest_attachment_id)
     self.assertEquals(row[8][10],3)
     self.assertEquals(row[8][11],latest_formdefmodel_id)
示例#3
0
 def testCrossDomainFormLookups(self):
     """Testing posting forms to the same xmlns in different domains."""
     form = create_xsd_and_populate("data/pf_followup.xsd", "data/pf_followup_1.xml", self.domain)
     cursor = connection.cursor()
     
     # we created one, make sure that's the case
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(1, cursor.fetchone()[0])
     
     # create another domain and post to it, make sure it doesnt' 
     # register
     other_domain = Domain.objects.create(name="otherdomain")
     form = populate("data/pf_followup_2.xml", other_domain)
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(1, cursor.fetchone()[0])
     
     # register on the second domain.  should be 1 and 1 now.
     form = create_xsd_and_populate("data/pf_followup.xsd", "data/pf_followup_3.xml", other_domain)
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(1, cursor.fetchone()[0])
     cursor.execute("SELECT count(*) FROM schema_otherdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(1, cursor.fetchone()[0])
     
     # post to individual domains, should behave as expected
     form = populate("data/pf_followup_4.xml", self.domain)
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(2, cursor.fetchone()[0])
     cursor.execute("SELECT count(*) FROM schema_otherdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(1, cursor.fetchone()[0])
     
     form = populate("data/pf_followup_5.xml", other_domain)
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(2, cursor.fetchone()[0])
     cursor.execute("SELECT count(*) FROM schema_otherdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(2, cursor.fetchone()[0])
示例#4
0
 def test4DeleteSubmissionMetadata(self):
     """ This is more a sanity check than anything else. Makes sure
     Django deletes the entire dependency chain for Submission objects. """
     formdefmodel_5 = create_xsd_and_populate("5_singlerepeat.xsd", domain=self.domain)
     instance_5 = populate("5_singlerepeat.xml", self.domain)
     formdefmodel_6 = create_xsd_and_populate("6_nestedrepeats.xsd", domain=self.domain)
     instance_6 = populate("6_nestedrepeats.xml", self.domain)
     instance_5.delete()
     instance_6.delete()
     # receiver unit tests already check for count([Submission|Attachment]) = 0
     # so here we test for metadata deletion
     count = Metadata.objects.all().count()
     self.assertEquals(0,count)
示例#5
0
文件: meta.py 项目: adewinter/data-hq
 def testDuplicates(self):
     create_xsd_and_populate("data/pf_followup.xsd", domain=self.domain)
     running_count = 0
     self.assertEqual(running_count, len(Metadata.objects.all()))
     
     for i in range(1, 6):
         populate("data/pf_followup_%s.xml" % i, domain=self.domain)
         # the first one should update the count.  The rest should not
         running_count = running_count + 1
         self.assertEqual(running_count, len(Metadata.objects.all()))
         for j in range(0, 3):
             logging.warn("EXPECTING A 'duplicate submission' ERROR NOW:")
             populate("data/pf_followup_%s.xml" % i, domain=self.domain)
             self.assertEqual(running_count, len(Metadata.objects.all()))
示例#6
0
    def testSaveFormData_8(self):
        """ Test repeated form definition created and data saved """
        formdefmodel = create_xsd_and_populate("data/8_singlerepeat_2.xsd", domain=self.domain)
        self.assertEquals(int(formdefmodel.version), 2)
        self.assertEquals(int(formdefmodel.uiversion), 3)

        submission = populate("data/8_singlerepeat_2.xml", self.domain)
        m = Metadata.objects.get(attachment__submission=submission)
        self.assertEquals(int(m.version), 2)
        self.assertEquals(int(m.uiversion), 2)
        
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM schema_versioneddomain_xml_singlerepeat_2")
        try:
            row = cursor.fetchone()
            self.assertEquals(row[9],"deviceid0")
            self.assertEquals(row[10],"starttime")
            self.assertEquals(row[11],"endtime")
            cursor.execute("SELECT * FROM schema_versioneddomain_xml_singlerepeat_root_userid_2")
            row = cursor.fetchall()
            self.assertEquals(row[0][1],"userid0")
            self.assertEquals(row[1][1],"userid2")
            self.assertEquals(row[2][1],"userid3")
            self.assertEquals(row[0][2],1)
            self.assertEquals(row[1][2],1)
            self.assertEquals(row[2][2],1)
        finally:
            manager = XFormManager()
            manager.remove_schema(formdefmodel.id)
示例#7
0
 def testSaveGeoDataMissingFields(self):
     """Test form definition with geopoint - EXTRA FIELDS"""
     filename = replace_in_file(self.instance_filename, "REPLACE_ME", 
                                "%s" % (LAT))
     create_xsd_and_populate("data/geopoint/geopoint_form.xhtml",
                             filename,
                             self.domain)
     self._check_row(LAT, None, None, None)
     
     filename = replace_in_file(self.instance_filename, "REPLACE_ME", 
                                "%s %s" % (LAT, LON))
     populate(filename, self.domain)
     self._check_row(LAT, LON, None, None)
     
     filename = replace_in_file(self.instance_filename, "REPLACE_ME", 
                                "%s %s %s" % (LAT, LON, ALT))
     populate(filename, self.domain)
     self._check_row(LAT, LON, ALT, None)
示例#8
0
    def test4DeleteInstance(self):
        """ Test instance data deletion from XFormmanager """
        formdefmodel_5 = create_xsd_and_populate("5_singlerepeat.xsd", domain=self.domain)
        instance_5 = populate("5_singlerepeat.xml", self.domain)
        formdefmodel_6 = create_xsd_and_populate("6_nestedrepeats.xsd", domain=self.domain)
        instance_6 = populate("6_nestedrepeats.xml", self.domain)
        xformmanager = XFormManager()

        num_handled = SubmissionHandlingOccurrence.objects.all().count()
        self.assertEquals(2,num_handled)
        count = Metadata.objects.all().count()
        self.assertEquals(2,count)
        
        # TODO - change this syntax once meta.attachment becomes meta.submission
        xformmanager.remove_data(formdefmodel_5.id, instance_5.xform.form_metadata.all()[0].raw_data )
        xformmanager.remove_data(formdefmodel_6.id, instance_6.xform.form_metadata.all()[0].raw_data )
        # test metadata deletion

        # Test that children have been marked as 'deleted' and are no longer 'initially handled'
        # (so that they are not considered 'orphans' i.e. unhandled)
        num_handled = SubmissionHandlingOccurrence.objects.all().count()
        self.assertEquals(2,num_handled)
        for handle_means in SubmissionHandlingOccurrence.objects.all():
            self.assertEqual("deleted", handle_means.handled.method)
        self.assertFalse(instance_5.is_orphaned())        
        self.assertFalse(instance_6.is_orphaned())        
        
        count = Metadata.objects.all().count()
        self.assertEquals(0,count)
        # test raw data deletion
        if settings.DATABASE_ENGINE == 'mysql':
            cursor = connection.cursor()
            cursor.execute("SELECT * FROM schema_remdomain_xml_singlerepeat")
            row = cursor.fetchall()
            self.assertEquals(len(row),0)
            cursor.execute("SELECT * FROM schema_remdomain_xml_singlerepeat_root_userid")
            row = cursor.fetchone()
            self.assertEquals(row,None)
            cursor.execute("SELECT * FROM schema_remdomain_xml_nestedrepeats")
            row = cursor.fetchone()
            self.assertEquals(row,None)
            cursor.execute("SELECT * FROM schema_remdomain_xml_nestedrepeats_root_nested")
            row = cursor.fetchone()
            self.assertEquals(row,None)
示例#9
0
文件: meta.py 项目: adewinter/data-hq
 def testReSubmit(self):
     # original submission
     submission = populate("data/pf_followup_1.xml", domain=self.domain)
     self.assertEquals(submission.is_orphaned(),True)
     # register schema
     create_xsd_and_populate("data/pf_followup.xsd", domain=self.domain)
     # xformmanagger resubmission
     xformmanager = XFormManager()
     status = xformmanager.save_form_data(submission.xform)
     self.assertEquals(status,True)
示例#10
0
 def testRepeatMultiples(self):
     """ Test multiple repeated form definition created and data saved """
     create_xsd_and_populate("data/repeat_multiple.xsd", "data/repeat_multiple_1.xml", self.domain)
     cursor = connection.cursor()
     cursor.execute("SELECT * FROM schema_repeatdomain_xml_singlerepeat")
     rows = cursor.fetchall()
     self.assertEqual(1, len(rows))
     row = rows[0]
     row_id = row[0]
     self.assertEquals(1, row_id)
     self.assertEquals(row[9], "starttime")
     self.assertEquals(row[10], "endtime")
     cursor.execute("SELECT * FROM schema_repeatdomain_xml_singlerepeat_root_userid")
     row = cursor.fetchall()
     self.assertEquals(row[0][1], "userid0")
     self.assertEquals(row[1][1], "userid2")
     self.assertEquals(row[2][1], "userid3")
     self.assertEquals(row[0][2], row_id)
     self.assertEquals(row[1][2], row_id)
     self.assertEquals(row[2][2], row_id)
     cursor.execute("SELECT * FROM schema_repeatdomain_xml_singlerepeat_root_my_device")
     row = cursor.fetchall()
     self.assertEquals(row[0][1], "deviceid0")
     self.assertEquals(row[1][1], "deviceid1")
     self.assertEquals(row[2][1], "deviceid2")
     self.assertEquals(row[0][2], row_id)
     self.assertEquals(row[1][2], row_id)
     self.assertEquals(row[2][2], row_id)
     # test a second repeat to make sure child ids link correctly
     populate("data/repeat_multiple_2.xml", self.domain)
     cursor.execute("SELECT distinct parent_id FROM schema_repeatdomain_xml_singlerepeat_root_my_device")
     rows = cursor.fetchall()
     self.assertEqual(2, len(rows))
     ids = [row[0] for row in rows]
     self.assertTrue(1 in ids)
     self.assertTrue(2 in ids)
     cursor.execute("SELECT * FROM schema_repeatdomain_xml_singlerepeat_root_my_device where parent_id=2")
     rows = cursor.fetchall()
     self.assertEqual(3, len(rows))
     for row in rows:
         self.assertTrue(row[1].startswith("second"))
示例#11
0
 def testRepostingPreservesData(self):
     """Testing reposting entire schemas."""
     form = create_xsd_and_populate("data/pf_followup.xsd", "data/pf_followup_1.xml", self.domain)
     original_id = form.id
     populate("data/pf_followup_2.xml", self.domain)
     
     # sanity checks to make sure things are behaving normally
     self.assertEqual(1, FormDefModel.objects.count())
     self.assertEqual(2, Metadata.objects.count())
     original_meta_ids = [meta.id for meta in Metadata.objects.all()]
     
     cursor = connection.cursor()
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(2, cursor.fetchone()[0])
     
     # repost - numbers should be the same, but the ids should all be different
     manager = XFormManager()
     new_form = manager.repost_schema(form)
     self.assertEqual(1, FormDefModel.objects.count())
     
     # compare basic form properties
     for field in FormDefModel._meta.fields:
         if field.name not in ("id", "xsd_file_location", "element"):
             self.assertEqual(getattr(form, field.name), getattr(new_form, field.name), 
                              "Field %s was not successfully migrated.  Previous value: %s, new value: %s" \
                              % (field.name, getattr(form, field.name), getattr(new_form, field.name))) 
             
     # check metadata
     self.assertEqual(2, Metadata.objects.count())
     self.assertNotEqual(original_id, new_form.id)
     for meta in Metadata.objects.all():
         self.assertFalse(meta.id in original_meta_ids)
     
     # check parsed data
     cursor = connection.cursor()
     cursor.execute("SELECT count(*) FROM schema_basicdomain_pathfinder_pathfinder_cc_follow_0_0_2a")
     self.assertEqual(2, cursor.fetchone()[0])
示例#12
0
文件: meta.py 项目: adewinter/data-hq
 def testSubmissionCount(self):
     create_xsd_and_populate("data/pf_followup.xsd", domain=self.domain)
     today = datetime.now().date()
     tomorrow = today + timedelta(days=1)
     day_after_tomorrow = today + timedelta(days=2)
     yesterday = today - timedelta(days=1)
     for i in range(1, 6):
         submission = populate("data/pf_followup_%s.xml" % i, domain=self.domain)
         meta = Metadata.objects.get(attachment=submission.xform)
         self.assertEqual(i, meta.get_submission_count(today, tomorrow, False))
         self.assertEqual(1, meta.get_submission_count(today, tomorrow, True))
         self.assertEqual(0, meta.get_submission_count(yesterday, today, False))
         self.assertEqual(0, meta.get_submission_count(tomorrow, day_after_tomorrow, False))
         self.assertEqual(i, meta.get_submission_count(yesterday, day_after_tomorrow, False))
         self.assertEqual(1, meta.get_submission_count(yesterday, day_after_tomorrow, True))
示例#13
0
文件: meta.py 项目: adewinter/data-hq
 def testSubmitHandling(self):
     create_xsd_and_populate("data/pf_followup.xsd", domain=self.domain)
     self.assertEqual(0, len(Metadata.objects.all()))
     self.assertEqual(0, len(Submission.objects.all()))
     self.assertEqual(0, len(SubmissionHandlingOccurrence.objects.all()))
     
     # this should create a linked submission
     populate("data/pf_followup_1.xml", domain=self.domain)
     
     self.assertEqual(1, len(Metadata.objects.all()))
     self.assertEqual(1, len(Submission.objects.all()))
     submission = Submission.objects.all()[0]
     self.assertEqual(1, len(SubmissionHandlingOccurrence.objects.all()))
     way_handled = SubmissionHandlingOccurrence.objects.all()[0]
     self.assertEqual(submission, way_handled.submission)
     # add check for a count from this user, equal to one
     self.assertEqual("1", way_handled.message)
     self.assertEqual("xformmanager", way_handled.handled.app)
     self.assertEqual("instance_data", way_handled.handled.method)
     self.assertFalse(submission.is_orphaned())
     
     # these should NOT create a linked submission.  No schema
     logging.warn("\nEXPECTING AN ERROR NOW:")
     populate("data/pf_new_reg_1.xml", domain=self.domain)
     logging.warn("EXPECTING AN ERROR NOW:")
     populate("data/pf_new_reg_2.xml", domain=self.domain)
     logging.warn("EXPECTING AN ERROR NOW:")
     populate("data/pf_ref_completed_1.xml", domain=self.domain)
     
     self.assertEqual(1, len(Metadata.objects.all()))
     self.assertEqual(4, len(Submission.objects.all()))
     for new_submission in Submission.objects.all():
         if new_submission == submission:
             self.assertFalse(new_submission.is_orphaned())
         else:
             self.assertTrue(new_submission.is_orphaned())
     self.assertEqual(1, len(SubmissionHandlingOccurrence.objects.all()))
     self.assertEqual(way_handled, SubmissionHandlingOccurrence.objects.all()[0])