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] = get_forms_by_type(self.domain.name, 'XFormError', limit=1) 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)
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)
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 failing_signal_handler(error_message): def fail(sender, xform, **kwargs): raise Exception(error_message) successful_form_received.connect(fail) try: yield finally: successful_form_received.disconnect(fail)
def testSubmissionError(self): evil_laugh = "mwa ha ha!" def fail(sender, xform, **kwargs): raise Exception(evil_laugh) successful_form_received.connect(fail) try: file, res = self._submit("simple_form.xml") self.assertEqual(201, res.status_code) self.assertIn(evil_laugh, res.content) # make sure we logged it [log] = FormAccessors(self.domain.name).get_forms_by_type('XFormError', limit=1) 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)
def testSubmissionError(self): evil_laugh = "mwa ha ha!" def fail(sender, xform, **kwargs): raise Exception(evil_laugh) successful_form_received.connect(fail) try: file, res = self._submit("simple_form.xml") self.assertEqual(201, res.status_code) self.assertIn(evil_laugh, res.content) # make sure we logged it [log] = FormAccessors(self.domain.name).get_forms_by_type( 'XFormError', limit=1) 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)