Exemplo n.º 1
0
 def testSubmissionError(self):
     evil_laugh = "mwa ha ha!"
     
     def fail(sender, xform, **kwargs):
         raise Exception(evil_laugh)
     
     xform_saved.connect(fail)
     
     try:    
         file = os.path.join(os.path.dirname(__file__), "data", "simple_form.xml")
         with open(file) as f:
             res = self.client.post(self.url, {
                     "xml_submission_file": f
             })
             self.assertEqual(201, res.status_code)
             self.assertTrue(evil_laugh in res.content)
         
         # make sure we logged it
         log = SubmissionErrorLog.view("couchforms/all_submissions_by_domain",
                                       reduce=False,
                                       include_docs=True,
                                       startkey=[self.domain.name, "by_type", "XFormError"],
                                       endkey=[self.domain.name, "by_type", "XFormError", {}],
                                       classes={'XFormError': SubmissionErrorLog}).one()
         
         self.assertTrue(log is not None)
         self.assertTrue(evil_laugh in log.problem)
         with open(file) as f:
             self.assertEqual(f.read(), log.get_xml())
     
     finally:
         xform_saved.disconnect(fail)
Exemplo n.º 2
0
 def testSubmissionError(self):
     evil_laugh = "mwa ha ha!"
     
     def fail(sender, xform, **kwargs):
         raise Exception(evil_laugh)
     
     xform_saved.connect(fail)
     
     try:    
         file = os.path.join(os.path.dirname(__file__), "data", "simple_form.xml")
         with open(file) as f:
             res = self.client.post(self.url, {
                     "xml_submission_file": f
             })
             self.assertEqual(201, res.status_code)
             self.assertTrue(evil_laugh in res.content)
         
         # make sure we logged it
         log = SubmissionErrorLog.view("receiverwrapper/all_submissions_by_domain",
                                       reduce=False,
                                       include_docs=True,
                                       startkey=[self.domain.name, "by_type", "XFormError"],
                                       endkey=[self.domain.name, "by_type", "XFormError", {}]).one()
         
         self.assertTrue(log is not None)
         self.assertTrue(evil_laugh in log.problem)
         with open(file) as f:
             self.assertEqual(f.read(), log.get_xml())
     
     finally:
         xform_saved.disconnect(fail)
Exemplo n.º 3
0
from couchforms.signals import xform_saved
import logging
import simplejson

def process_dots_submission(sender, xform, **kwargs):

    try:
        if xform.xmlns != "http://dev.commcarehq.org/pact/dots_form":
            return
        try:
            if isinstance(dots_json, str) or isinstance(dots_json, unicode):
                dots_json_str = xform['form']['case']['update']['dots']
                json_data = simplejson.loads(dots_json_str)
                xform['pact_data'] = {}
                xform['pact_data']['dots'] = json_data
                xform.save()
        except Exception, ex:
            logging.error("Error, dots submission did not have a dots block in the update section: %s" % (ex))

    except:
        logging.error("Error processing the submission due to an unknown error.")

xform_saved.connect(process_dots_submission)