aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-06-03 15:29:01 +0400
committerGravatar GitHub <[email protected]>2022-06-03 15:29:01 +0400
commit8d3f9ecc3a78dc2ffd749a43939763de4f93835f (patch)
treef348629cb9c1787ac2e9b7655e588d1e82a582fa
parentFix WSGI app not being called (diff)
parentImport the WSGI app via the config during tests (diff)
Merge pull request #143 from python-discord/feat/tests/wsgi-app-from-cfg
Import the WSGI app via the config during tests
-rw-r--r--snekbox/utils/logging.py17
-rw-r--r--tests/gunicorn_utils.py16
2 files changed, 19 insertions, 14 deletions
diff --git a/snekbox/utils/logging.py b/snekbox/utils/logging.py
index c15e3f1..a73db2d 100644
--- a/snekbox/utils/logging.py
+++ b/snekbox/utils/logging.py
@@ -1,6 +1,10 @@
import logging
import os
import sys
+import warnings
+
+from falcon.util.deprecation import DeprecatedWarning
+
__all__ = ("FORMAT", "init_logger", "init_sentry")
@@ -21,11 +25,14 @@ def init_logger(debug: bool) -> None:
def init_sentry(version: str) -> None:
"""Initialise the Sentry SDK if it's installed."""
- try:
- import sentry_sdk
- from sentry_sdk.integrations.falcon import FalconIntegration
- except ImportError:
- return
+ with warnings.catch_warnings():
+ warnings.filterwarnings("ignore", message=r".*\bapi_helpers\b", category=DeprecatedWarning)
+
+ try:
+ import sentry_sdk
+ from sentry_sdk.integrations.falcon import FalconIntegration
+ except ImportError:
+ return
sentry_sdk.init(
dsn=os.environ.get("SNEKBOX_SENTRY_DSN", ""),
diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py
index b417b1b..f5dae7a 100644
--- a/tests/gunicorn_utils.py
+++ b/tests/gunicorn_utils.py
@@ -3,10 +3,10 @@ import contextlib
import multiprocessing
from typing import Iterator
-from gunicorn.app.base import Application
+from gunicorn.app.wsgiapp import WSGIApplication
-class _StandaloneApplication(Application):
+class _StandaloneApplication(WSGIApplication):
def __init__(self, config_path: str = None, **kwargs):
self.config_path = config_path
self.options = kwargs
@@ -14,19 +14,17 @@ class _StandaloneApplication(Application):
super().__init__()
def init(self, parser, opts, args):
- pass
-
- def load(self):
- from snekbox.api import SnekAPI
- return SnekAPI()
+ """Patch `opts` to simulate the config path being passed as a command-line argument."""
+ super().init(parser, opts, args)
+ opts.config = self.config_path
def load_config(self):
+ """Set the option kwargs in the config, then load the config as usual."""
for key, value in self.options.items():
if key in self.cfg.settings and value is not None:
self.cfg.set(key.lower(), value)
- if self.config_path:
- self.load_config_from_file(self.config_path)
+ super().load_config()
def _proc_target(config_path: str, event: multiprocessing.Event, **kwargs) -> None: