mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 19:30:13 -04:00
Localize notification_utils to the admin
This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin. Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
51
tests/notifications_utils/test_logging.py
Normal file
51
tests/notifications_utils/test_logging.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import json
|
||||
import logging as builtin_logging
|
||||
|
||||
from notifications_utils import logging
|
||||
|
||||
|
||||
def test_get_handlers_sets_up_logging_appropriately_with_debug():
|
||||
class App:
|
||||
config = {"NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "ERROR"}
|
||||
debug = True
|
||||
|
||||
app = App()
|
||||
|
||||
handlers = logging.get_handlers(app)
|
||||
|
||||
assert len(handlers) == 1
|
||||
assert isinstance(handlers[0], builtin_logging.StreamHandler)
|
||||
assert isinstance(handlers[0].formatter, builtin_logging.Formatter)
|
||||
|
||||
|
||||
def test_get_handlers_sets_up_logging_appropriately_without_debug():
|
||||
class App:
|
||||
config = {"NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "ERROR"}
|
||||
debug = False
|
||||
|
||||
app = App()
|
||||
|
||||
handlers = logging.get_handlers(app)
|
||||
|
||||
assert len(handlers) == 1
|
||||
assert isinstance(handlers[0], builtin_logging.StreamHandler)
|
||||
assert isinstance(handlers[0].formatter, logging.JSONFormatter)
|
||||
|
||||
|
||||
def test_base_json_formatter_contains_service_id():
|
||||
record = builtin_logging.LogRecord(
|
||||
name="log thing",
|
||||
level="info",
|
||||
pathname="path",
|
||||
lineno=123,
|
||||
msg="message to log",
|
||||
exc_info=None,
|
||||
args=None,
|
||||
)
|
||||
|
||||
service_id_filter = logging.ServiceIdFilter()
|
||||
assert (
|
||||
json.loads(logging.BaseJSONFormatter().format(record))["message"]
|
||||
== "message to log"
|
||||
)
|
||||
assert service_id_filter.filter(record).service_id == "no-service-id"
|
||||
Reference in New Issue
Block a user