"""Test the basics including the bmark and tags"""
from nose.tools import eq_
from nose.tools import ok_
from pyramid import testing
from bookie.models import DBSession
from bookie.models.applog import AppLogMgr
from bookie.tests import empty_db
from bookie.tests import TestDBBase
from bookie.tests.factory import make_applog
class TestAppLogMgr(TestDBBase):
"""Verify the AppLogMgr works as expected."""
def test_log_find(self):
"""Verify that a basic find works"""
log1 = make_applog()
log2 = make_applog()
DBSession.add(log1)
DBSession.add(log2)
DBSession.flush()
found = AppLogMgr.find()
eq_(2, len(found))
def test_log_find_status(self):
"""Verify we can filter on the status field."""
log1 = make_applog(status=0)
log2 = make_applog(status=2)
log3 = make_applog(status=0)
DBSession.add(log1)
DBSession.add(log2)
DBSession.add(log3)
DBSession.flush()
found = AppLogMgr.find(status=0)
eq_(2, len(found))
def test_log_find_message(self):
"""Verify we can search on the message field."""
msg1 = "Auth error rharding"
msg2 = "Login issue rick"
log1 = make_applog(message=msg1)
log2 = make_applog(message=msg2)
DBSession.add(log1)
DBSession.add(log2)
DBSession.flush()
found = AppLogMgr.find(message_filter='rharding')
eq_(1, len(found))
eq_(found[0].message, msg1)
found = AppLogMgr.find(message_filter='login')
eq_(1, len(found))
eq_(found[0].message, msg2)
|