def test_10_publish(self): """Test direct exception publishing. """ self.app = self.create_application() try: raise ValueError except ValueError: type, exception, traceback = exc_info() traceback = Traceback(type, exception, traceback) with self.app.test_request_context(): Exceptional.publish(self.app.config, traceback) data = json.loads(g.exceptional) exception = data["exception"] assert exception["exception_class"] == ValueError.__name__
def test_07_unexceptional(self): """Test disabled Exceptional logging. """ self.app = self.create_application() del self.app.config["EXCEPTIONAL_API_KEY"] Exceptional(self.app) with self.app.test_client() as client: client.get("/error") assert hasattr(g, "exceptional") is False
def test_11_utf8_decode(self): """Test sending an invalid UTF-8 byte sequence through Exceptional. """ self.app.config["INVALID_UTF-8"] = "\xf0" Exceptional(self.app) with self.app.test_client() as client: client.get("/error") data = json.loads(g.exceptional) application_environment = data["application_environment"] environment = application_environment["env"] assert environment["INVALID_UTF-8"] == u"\ufffd"
def test_05_filter_header(self): """Test header data filtering. """ self.app.config["EXCEPTIONAL_HEADER_FILTER"] = ["Host"] Exceptional(self.app) with self.app.test_client() as client: client.get("/error") data = json.loads(g.exceptional) request = data["request"] headers = request["headers"] assert headers["Host"] == "[FILTERED]"
def test_12_json(self): """Test JSON request handling. """ self.app = self.create_application() Exceptional(self.app) data = json.dumps({"foo": {"bar": "baz"}}) with self.app.test_client() as client: client.post("/error", content_type="application/json", data=data) data = json.loads(g.exceptional) request = data["request"] parameters = request["parameters"] assert "bar" in parameters["foo"]
def test_06_filter_parameter(self): """Test parameter data filtering. """ data = {"foo": "bar", "baz": "qux"} self.app.config["EXCEPTIONAL_PARAMETER_FILTER"] = ["baz"] Exceptional(self.app) with self.app.test_client() as client: client.post("/error", data=data) data = json.loads(g.exceptional) request = data["request"] parameters = request["parameters"] assert parameters["baz"] == "[FILTERED]"
def test_10_publish(self): """Test direct exception publishing. """ self.app = self.create_application() try: raise ValueError except ValueError: type, exception, traceback = exc_info() traceback = Traceback(type, exception, traceback) data = json.loads(Exceptional.publish(self.app.config, traceback)) exception = data["exception"] assert exception["exception_class"] == ValueError.__name__
def test_09_debug(self): """Test exception in debug mode. """ self.app = self.create_application() self.app.debug = True exceptional = Exceptional(self.app) self.app.config["EXCEPTIONAL_ENVIRONMENT_FILTER"].append("os.*") self.app.config["PROPAGATE_EXCEPTIONS"] = None assert exceptional.url == self.app.config["EXCEPTIONAL_DEBUG_URL"] with self.app.test_client() as client: self.assertRaises(ZeroDivisionError, client.get, "/error") json.loads(g.exceptional) print "See %s for HTTP request details." % exceptional.url
def ret_val(exception): Exceptional.context(foo="bar") return handle_exception(exception)
def setUp(self): """Set up each test. """ self.app = self.create_application() self.exceptional = Exceptional(self.app)