Skip to content

Commit

Permalink
Add test for logging_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
richaagarwal committed Sep 18, 2017
1 parent 19ad9c9 commit 33bb7e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 0 additions & 3 deletions cfgov/alerts/logging_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@


class CFGovErrorHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)

def emit(self, record):
GithubAlert({}).post(
title=record.message[:30],
Expand Down
24 changes: 24 additions & 0 deletions cfgov/alerts/tests/test_logging_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

from django.test import TestCase
from mock import patch, MagicMock

from alerts.logging_handlers import CFGovErrorHandler


class TestLoggingHandlers(TestCase):

@patch('alerts.github_alert.GithubAlert.post')
def test_emit(self, github_alert):
""" Test that calling CFGOVErrorHandler.emit
makes a GithubAlert post with the right parameters
"""
message = (u'Internal Server Error: /tést-page/'
'Traceback (most recent call last):'
'... more details ...')
record = MagicMock(message=message)
CFGovErrorHandler().emit(record)
github_alert.assert_called_once_with(
title=message[:30],
body=message,
)

0 comments on commit 33bb7e3

Please sign in to comment.