def testCreation(self): self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) logging.error("Fail!") self.assertEqual(1, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) log = ExceptionRecord.view("couchlog/all_by_date", include_docs=True).one() self.assertEqual("Fail!", log.message) self.assertTrue("tests.py" in log.pathname) self.assertFalse(log.archived)
def testPostSaveDrugBug(self): self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) folder_name = os.path.join(os.path.dirname(__file__), "testdata", "test_post_save_drug_bug") patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json")) updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_underfive.xml")) self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all()))
def testThreshold(self): # makes the shady assumption that the couchlog threshold is above debug self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) logging.debug("Don't write me to couchlog!") self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) # make sure we're not dependent on the root log level logging.root.setLevel(logging.DEBUG) logging.debug("Don't write me to couchlog either!") self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all()))
def get_matching_records(query, include_archived): if config.LUCENE_ENABLED: if not include_archived: query = "%s AND NOT archived" % query limit = ExceptionRecord.get_db().search(config.COUCHLOG_LUCENE_VIEW, handler="_fti/_design", q=query, limit=1).total_rows matches = ExceptionRecord.get_db().search(config.COUCHLOG_LUCENE_VIEW, handler="_fti/_design", q=query, limit=limit, include_docs=True) return [ExceptionRecord.wrap(res["doc"]) for res in matches] else: if include_archived: return ExceptionRecord.view("couchlog/all_by_msg", reduce=False, key=query, include_docs=True).all() else: return ExceptionRecord.view("couchlog/inbox_by_msg", reduce=False, key=query, include_docs=True).all()
def testFromException(self): self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) class CouchLogTestException(Exception): pass try: raise CouchLogTestException("Exceptional fail!") except Exception, e: logging.exception("some other message")
def handle(self, *args, **options): all_matching_records = ExceptionRecord.view("couchlog/all_by_msg", startkey="problem in form listener", endkey="problem in form listenerz", reduce=False).all() for row in all_matching_records: ExceptionRecord.get_db().delete_doc(row["id"])
def get_results(key): return ExceptionRecord.view( "couchlog/all_by_date", reduce=False, endkey=[key.isoformat()], limit=1000, include_docs=False)
def handle(self, *args, **options): all_matching_records = ExceptionRecord.view( "couchlog/all_by_msg", startkey="problem in form listener", endkey="problem in form listenerz", reduce=False).all() for row in all_matching_records: ExceptionRecord.get_db().delete_doc(row["id"])
def purge_old_logs(): key = datetime.now() - timedelta(weeks=52) results = ExceptionRecord.view( "couchlog/all_by_date", reduce=False, startkey=[key.isoformat()], descending=True, limit=1000, include_docs=False) db = ExceptionRecord.get_db() docs = [] for result in results: docs.append({ '_id': result['id'], '_rev': db.get_rev(result['id']), '_deleted': True, }) db.bulk_save(docs, use_uuids=False)
def setUp(self): for item in ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all(): item.delete()
def testSettingsInfo(self): self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all())) try: raise Exception("Fail!") except Exception, e: logging.exception("This is another message")