def process_sql(self, doc_dict): doc = self.document_class.wrap(doc_dict) doc = ReadOnlyObject(doc) try: FormData.create_or_update_from_xforminstance(doc) except InvalidDataException, e: # this is a less severe class of errors logger.info("FormDataPillow: bad update in form listener for line: %s\n%s" % (doc_dict, e))
def process_sql(self, doc_dict): doc = self.document_class.wrap(doc_dict) doc = ReadOnlyObject(doc) try: FormData.create_or_update_from_xforminstance(doc) except InvalidDataException, e: # this is a less severe class of errors logger.info( "FormDataPillow: bad update in form listener for line: %s\n%s" % (doc_dict, e))
def process_sql(self, doc_dict, delete=False): if delete or doc_dict['doc_type'] != 'XFormInstance': try: FormData.objects.get(instance_id=doc_dict['_id']).delete() except FormData.DoesNotExist: pass return doc = self.document_class.wrap(doc_dict) doc = ReadOnlyObject(doc) try: FormData.create_or_update_from_instance(doc) except InvalidDataException, e: # this is a less severe class of errors logger.info("FormDataPillow: bad update in form listener for line: %s\n%s" % (doc_dict, e))
def testFromInstance(self): formdata = FormData.from_instance(self.instance) self.assertEqual(date(2010, 07, 22), formdata.time_start.date()) self.assertEqual(date(2010, 07, 23), formdata.time_end.date()) self.assertEqual("THIS_IS_THE_INSTANCEID", formdata.instance_id) self.assertEqual("THIS_IS_THE_DEVICEID", formdata.device_id) self.assertEqual("THIS_IS_THE_USERID", formdata.user_id)
def process_sql(self, doc_dict, delete=False): if delete or doc_dict['doc_type'] != 'XFormInstance': try: FormData.objects.get(instance_id=doc_dict['_id']).delete() except FormData.DoesNotExist: pass return doc = self.document_class.wrap(doc_dict) doc = ReadOnlyObject(doc) try: FormData.create_or_update_from_instance(doc) except InvalidDataException, e: # this is a less severe class of errors logger.info( "FormDataPillow: bad update in form listener for line: %s\n%s" % (doc_dict, e))
def get_formdata(days_ago, domain, user_id, xmlns=None, duration=1): now = datetime.utcnow() return FormData( domain=domain, user_id=user_id, time_end=now - timedelta(days=days_ago), received_on=now, instance_id=uuid.uuid4(), time_start=now, duration=duration * 1000, # convert to ms xmlns=xmlns)
def testCreateOrUpdate(self): self.assertEqual(0, FormData.objects.count()) FormData.create_or_update_from_instance(self.instance) self.assertEqual(1, FormData.objects.count()) self.assertTrue(FormData.objects.all()[0].matches_exact(self.instance)) FormData.create_or_update_from_instance(self.instance) self.assertEqual(1, FormData.objects.count()) self.assertTrue(FormData.objects.all()[0].matches_exact(self.instance)) self.instance["form"]["meta"]["deviceID"] = "UPDATED_DEVICEID" FormData.create_or_update_from_instance(self.instance) self.assertEqual(1, FormData.objects.count()) self.assertTrue(FormData.objects.all()[0].matches_exact(self.instance)) self.instance["form"]["meta"]["instanceID"] = "UPDATED_INSTANCEID" self.instance._id = "UPDATED_INSTANCEID" FormData.create_or_update_from_instance(self.instance) self.assertEqual(2, FormData.objects.count()) self.assertTrue(FormData.objects.get(instance_id="UPDATED_INSTANCEID").matches_exact(self.instance))
def testUpdate(self): formdata = FormData.from_instance(self.instance) self.instance["form"]["meta"]["deviceID"] = "UPDATED_DEVICEID" formdata.update(self.instance) self.assertEqual("UPDATED_DEVICEID", formdata.device_id) self.assertTrue(formdata.matches_exact(self.instance))
def testMatches(self): formdata = FormData.from_instance(self.instance) self.assertTrue(formdata.matches_exact(self.instance)) formdata.device_id = "UPDATED_DEVICEID" self.assertFalse(formdata.matches_exact(self.instance))