Ejemplo n.º 1
0
def _clear_all_forms(domain):
    for item in SubmissionErrorLog.view("couchforms/all_submissions_by_domain",
                                  reduce=False,
                                  include_docs=True,
                                  startkey=[domain, "by_type"],
                                  endkey=[domain, "by_type", {}],
                                  wrapper=lambda row: SubmissionErrorLog.wrap(row['doc'])).all():

        item.delete()
def _clear_all_forms(domain):
    for item in SubmissionErrorLog.view(
            "couchforms/all_submissions_by_domain",
            reduce=False,
            include_docs=True,
            startkey=[domain, "by_type"],
            endkey=[domain, "by_type", {}],
            wrapper=lambda row: SubmissionErrorLog.wrap(row['doc'])).all():

        item.delete()
Ejemplo n.º 3
0
    def testSubmissionError(self):
        evil_laugh = "mwa ha ha!"

        def fail(sender, xform, **kwargs):
            raise Exception(evil_laugh)

        successful_form_received.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.assertIn(evil_laugh, 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", {}],
            ).one()

            self.assertIsNotNone(log)
            self.assertIn(evil_laugh, log.problem)
            with open(file) as f:
                self.assertEqual(f.read(), log.get_xml())
        
        finally:
            successful_form_received.disconnect(fail)
Ejemplo n.º 4
0
 def testSubmitDuplicate(self):
     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.assertIn("Thanks for submitting", res.content)
     
     with open(file) as f:
         res = self.client.post(self.url, {
                 "xml_submission_file": f
         })
         self.assertEqual(201, res.status_code)
         self.assertIn("Form is a duplicate", 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", "XFormDuplicate"],
         endkey=[self.domain.name, "by_type", "XFormDuplicate", {}],
         classes={'XFormDuplicate': SubmissionErrorLog},
     ).one()
     
     self.assertIsNotNone(log)
     self.assertIn("Form is a duplicate", log.problem)
     with open(file) as f:
         self.assertEqual(f.read(), log.get_xml())
    def testSubmissionError(self):
        evil_laugh = "mwa ha ha!"

        def fail(sender, xform, **kwargs):
            raise Exception(evil_laugh)

        successful_form_received.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.assertIn(evil_laugh, 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", {}],
            ).one()

            self.assertTrue(log is not None)
            self.assertIn(evil_laugh, log.problem)
            with open(file) as f:
                self.assertEqual(f.read(), log.get_xml())

        finally:
            successful_form_received.disconnect(fail)
    def testSubmitDuplicate(self):
        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.assertIn("Thanks for submitting", res.content)

        with open(file) as f:
            res = self.client.post(self.url, {"xml_submission_file": f})
            self.assertEqual(201, res.status_code)
            self.assertIn("Form is a duplicate", 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", "XFormDuplicate"],
            endkey=[self.domain.name, "by_type", "XFormDuplicate", {}],
            classes={
                'XFormDuplicate': SubmissionErrorLog
            }).one()

        self.assertTrue(log is not None)
        self.assertIn("Form is a duplicate", log.problem)
        with open(file) as f:
            self.assertEqual(f.read(), log.get_xml())
Ejemplo n.º 7
0
def _clear_all_forms(domain):
    for item in SubmissionErrorLog.view("receiverwrapper/all_submissions_by_domain",
                                  reduce=False,
                                  include_docs=True,
                                  startkey=[domain, "by_type"],
                                  endkey=[domain, "by_type", {}]).all():

        item.delete()
Ejemplo n.º 8
0
 def error_callback(error_log):
     error_doc = SubmissionErrorLog.get(error_log.get_id)
     _attach_shared_props(error_doc)
     submission_error_received.send(sender="receiver", xform=error_doc)
     error_doc.save()
     return HttpResponseServerError(
         xml.get_simple_response_xml(
             message="The sever got itself into big trouble! Details: %s" % error_log.problem,
             nature=ResponseNature.SUBMIT_ERROR)) 
Ejemplo n.º 9
0
def _log_hard_failure(instance, attachments, error):
    """
    Handle's a hard failure from posting a form to couch. 
    
    Currently, it will save the raw payload to couch in a hard-failure doc
    and return that doc.
    """
    try:
        message = unicode(error)
    except UnicodeDecodeError:
        message = unicode(str(error), encoding='utf-8')

    return SubmissionErrorLog.from_instance(instance, message)
Ejemplo n.º 10
0
 def testSubmitBadXML(self):
     f, path = tmpfile()
     with f:
         f.write("this isn't even close to xml")
     with open(path) as f:
         res = self.client.post(self.url, {
                 "xml_submission_file": f
         })
         self.assertEqual(500, res.status_code)
         self.assertIn('Invalid XML', 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", "SubmissionErrorLog"],
                                   endkey=[self.domain.name, "by_type", "SubmissionErrorLog", {}]).one()
     
     self.assertTrue(log is not None)
     self.assertIn('Invalid XML', log.problem)
     self.assertEqual("this isn't even close to xml", log.get_xml())
    def testSubmitBadXML(self):
        f, path = tmpfile()
        with f:
            f.write("this isn't even close to xml")
        with open(path) as f:
            res = self.client.post(self.url, {"xml_submission_file": f})
            self.assertEqual(500, res.status_code)
            self.assertIn('Invalid XML', 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", "SubmissionErrorLog"],
            endkey=[self.domain.name, "by_type", "SubmissionErrorLog",
                    {}]).one()

        self.assertTrue(log is not None)
        self.assertIn('Invalid XML', log.problem)
        self.assertEqual("this isn't even close to xml", log.get_xml())
Ejemplo n.º 12
0
 def submission_error_form_instance(cls, domain, instance, message):
     log = SubmissionErrorLog.from_instance(instance, message)
     log.domain = domain
     return log
Ejemplo n.º 13
0
 def submission_error_form_instance(cls, domain, instance, message):
     log = SubmissionErrorLog.from_instance(instance, message)
     log.domain = domain
     return log