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.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 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())
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()
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()
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())