I'm using Django 1.3 and need to check the output and number of interactions in my logging system. For logging I'm using Django-Sentry though it appears that it's working just like the regular Python logger.
I'm using python-mockito for mocking and if possible I would like to check the number of times different methods have been called and the messages they return.
I'm trying to achieve a check that does something like:
from foo import views
logger = mock()
views.logger = logger
do_method()
verify(logger).error(any, any)
do_method()
verifyZeroInteractions(logger)
Also being able to check the parameters would be nice.
models.py
:
from django.db import models
import logging
from sentry.client.handlers import SentryHandler
logger = logging.getLogger(__name__)
try:
is_logging_setup = True
except NameError:
is_logging_setup = True
logger.setLevel(settings.LOGGING_LEVEL)
logger.addHandler(SentryHandler())
class Foo(models.Model):
def bar(self):
logger.warning("Rawr", 'extra': { 'data': 'foo' })
tests.py
:
class TestModelFoo(TestCase):
def setUp(self):
self.foo = Foo()
def test_getting_logged(self):
self.foo.bar()
# Check the log output.
Any suggestions on how I can catch the output?