Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_order_of_middleware(self):
a = []
m = MiddlewareStack()
m.before_notify(lambda _: a.append(1))
m.before_notify(lambda _: a.append(2))
m.after_notify(lambda _: a.append(4))
m.after_notify(lambda _: a.append(3))
m.run(None, lambda: None)
self.assertEqual(a, [1, 2, 3, 4])
def test_insert_before_default_ordering(self):
a = []
m = MiddlewareStack()
m.append(TestMiddlewareClassA)
m.append(TestMiddlewareClassB)
m.insert_before(TestMiddlewareClass, TestMiddlewareClassC)
m.run(a, lambda: a.append('Callback'))
self.assertEqual(a, ['A', 'B', 'C', 'Callback'])
def test_before_notify_returning_false(self):
a = []
m = MiddlewareStack()
m.before_notify(lambda _: False)
m.before_notify(lambda _: a.append(1))
m.run(None, lambda: a.append(2))
self.assertEqual(a, [])
def test_after_exception_handling(self):
a = []
m = MiddlewareStack()
m.after_notify(lambda _: a.penned(1))
m.run(None, lambda: a.append(2))
self.assertEqual(a, [2])
def test_insert_before_ordering(self):
a = []
m = MiddlewareStack()
m.append(TestMiddlewareClassA)
m.append(TestMiddlewareClassB)
m.insert_before(TestMiddlewareClassA, TestMiddlewareClassC)
m.run(a, lambda: a.append('Callback'))
self.assertEqual(a, ['C', 'A', 'B', 'Callback'])
def test_before_exception_handling(self):
a = []
m = MiddlewareStack()
m.before_notify(lambda _: a.penned(1))
m.run(None, lambda: a.append(2))
self.assertEqual(a, [2])
def test_insert_after_ordering(self):
a = []
m = MiddlewareStack()
m.append(TestMiddlewareClassA)
m.append(TestMiddlewareClassB)
m.insert_after(TestMiddlewareClassA, TestMiddlewareClassC)
m.run(a, lambda: a.append('Callback'))
self.assertEqual(a, ['A', 'C', 'B', 'Callback'])
def test_insert_after_default_ordering(self):
a = []
m = MiddlewareStack()
m.append(TestMiddlewareClassA)
m.append(TestMiddlewareClassB)
m.insert_after(TestMiddlewareClass, TestMiddlewareClassC)
m.run(a, lambda: a.append('Callback'))
self.assertEqual(a, ['A', 'B', 'C', 'Callback'])
self.lib_root = get_python_lib()
self.project_root = os.getcwd()
self.app_version = None
self.params_filters = ["password", "password_confirmation", "cookie",
"authorization"]
self.ignore_classes = [
"KeyboardInterrupt",
"django.http.Http404",
"django.http.response.Http404",
]
self.endpoint = "https://notify.bugsnag.com"
self.session_endpoint = "https://sessions.bugsnag.com"
self.auto_capture_sessions = False
self.traceback_exclude_modules = []
self.middleware = MiddlewareStack()
self.internal_middleware = MiddlewareStack()
self.internal_middleware.append(DefaultMiddleware)
self.internal_middleware.append(SessionMiddleware)
self.proxy_host = None
if not os.getenv("DYNO"):
self.hostname = socket.gethostname()
else:
self.hostname = None
self.runtime_versions = {"python": platform.python_version()}
self.app_version = None
self.params_filters = ["password", "password_confirmation", "cookie",
"authorization"]
self.ignore_classes = [
"KeyboardInterrupt",
"django.http.Http404",
"django.http.response.Http404",
]
self.endpoint = "https://notify.bugsnag.com"
self.session_endpoint = "https://sessions.bugsnag.com"
self.auto_capture_sessions = False
self.traceback_exclude_modules = []
self.middleware = MiddlewareStack()
self.internal_middleware = MiddlewareStack()
self.internal_middleware.append(DefaultMiddleware)
self.internal_middleware.append(SessionMiddleware)
self.proxy_host = None
if not os.getenv("DYNO"):
self.hostname = socket.gethostname()
else:
self.hostname = None
self.runtime_versions = {"python": platform.python_version()}