from datetime import datetime import unittest import model model.build_tables() import handlers class TestMessageHandler(unittest.TestCase): def test_message(self): handlers.handle_message({'data':{'text':'it all good man'}}) try: handlers.handle_message({'data':{'text':'why whould I say hipster?'}}) assert False, 'Exception you now say hipster' except: pass class TestHandleErrorCount(unittest.TestCase): def test_error_count(self): us = model.UserSession.find_or_create('test_foo') us.add_event({'type':'message', 'timestamp':datetime.now(), 'data':{'text':'hipster I am'}}) model.Error.new(us.id, subject='Test Python Error', text='testing error') assert us.errors
from datetime import datetime import unittest import model model.build_tables() # Build in memory tables ;) class TestEvent(unittest.TestCase): def test_create(self): n = {'type': 'test_create', 'timestamp':datetime.now(), 'data':{'foo':'yo', 'bar':'dude'}} e = model.Event.save(n) assert e.type == n['type'] assert e.timestamp == n['timestamp'] assert e.data['foo'] == n['data']['foo'] class TestSession(unittest.TestCase): def test_create(self): user_name = 'foo' us = model.UserSession.find_or_create(user_name) us2 = model.UserSession.find_or_create(user_name) assert us.id == us2.id n = {'type': 'test_create', 'timestamp':datetime.now(), 'data':{'foo':'yo', 'bar':'dude'}} us.add_event(e) us3 = model.UserSession.find_or_create(user_name) assert us3.events