def test_old_run(self): """non-recorded events should return False""" et = EventTracker() # Times older than 3 hours don't get recorded according to: http://mixpanel.com/api/docs/specification # equests will be rejected that are 3 hours older than present time result = et.run('event_foo', {'time': 1245613885}) self.assertFalse(result)
def test_non_recorded(self): """non-recorded events should return False""" self.response.read.return_value = '0' et = EventTracker() # Times older than 3 hours don't get recorded according to: # http://mixpanel.com/api/docs/specification # requests will be rejected that are 3 hours older than present time # (though actually this is returnin False because of mocking network) result = et.run('event_foo', {'time': 1245613885}) self.assertFalse(result)
def test_debug_logger(self): et = EventTracker() result = et.run('event_foo', {}, loglevel=logging.DEBUG) self.assertTrue(result)
def test_run(self): # "correct" result obtained from: http://mixpanel.com/api/docs/console et = EventTracker() result = et.run('event_foo', {}) self.assertTrue(result)
from guelphapi.api.utils.log import get_data from tastypie.resources import Resource, ModelResource from mixpanel.tasks import EventTracker tracker = EventTracker() track_event = lambda *a, **kw: tracker.run(*a, **kw) class LoggingResource(Resource): def dispatch(self, request_type, request, **kwargs): # Let the "real" dispatch do its thing. # This includes checking a throttle, authentication, authorization, etc response = super(LoggingResource, self).dispatch(request_type, request, **kwargs) # Only log "good" requests for now # We know once we're down here, that things are fine data = get_data(request_type, request, kwargs) track_event('request-%s' % request.META.get('REQUEST_METHOD', request_type), data) return response class LoggingModelResource(ModelResource): def dispatch(self, request_type, request, **kwargs): # Let the "real" dispatch do its thing. # This includes checking a throttle, authentication, authorization, etc. response = super(LoggingModelResource, self).dispatch(request_type, request, **kwargs) # Only log "good" requests for now # We know once we're down here, that things are fine data = get_data(request_type, request, kwargs) track_event('request-%s' % request.META.get('REQUEST_METHOD', request_type), data) return response
def index(request): et = EventTracker() et.run('dj_event', {'distinct_id': 1}, token=settings.token ) return HttpResponse("Hello, world!.")