def test_session_tracker_adds_session_object_to_queue(self):
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     tracker.start_session()
     self.assertEqual(len(tracker.session_counts), 1)
     for key, value in tracker.session_counts.items():
         self.assertEqual(value, 1)
 def test_session_tracker_adds_session_object_to_queue(self):
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     tracker.start_session()
     self.assertEqual(len(tracker.session_counts), 1)
     for key, value in tracker.session_counts.items():
         self.assertEqual(value, 1)
 def test_session_tracker_sessions_are_unique(self):
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     locs = ThreadLocals.get_instance()
     tracker.start_session()
     session_one = locs.get_item('bugsnag-session').copy()
     tracker.start_session()
     session_two = locs.get_item('bugsnag-session').copy()
     self.assertNotEqual(session_one['id'], session_two['id'])
 def test_session_tracker_sessions_are_unique(self):
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     locs = ThreadLocals.get_instance()
     tracker.start_session()
     session_one = locs.get_item('bugsnag-session').copy()
     tracker.start_session()
     session_two = locs.get_item('bugsnag-session').copy()
     self.assertNotEqual(session_one['id'], session_two['id'])
 def test_session_tracker_stores_session_in_threadlocals(self):
     locs = ThreadLocals.get_instance()
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     tracker.start_session()
     session = locs.get_item('bugsnag-session')
     self.assertTrue('id' in session)
     self.assertTrue('startedAt' in session)
     self.assertTrue('events' in session)
     self.assertTrue('handled' in session['events'])
     self.assertTrue('unhandled' in session['events'])
     self.assertEqual(session['events']['handled'], 0)
     self.assertEqual(session['events']['unhandled'], 0)
 def test_session_tracker_stores_session_in_threadlocals(self):
     locs = ThreadLocals.get_instance()
     tracker = SessionTracker(self.config)
     tracker.auto_sessions = True
     tracker.start_session()
     session = locs.get_item('bugsnag-session')
     self.assertTrue('id' in session)
     self.assertTrue('startedAt' in session)
     self.assertTrue('events' in session)
     self.assertTrue('handled' in session['events'])
     self.assertTrue('unhandled' in session['events'])
     self.assertEqual(session['events']['handled'], 0)
     self.assertEqual(session['events']['unhandled'], 0)
Exemple #7
0
class TestSessionMiddleware(unittest.TestCase):
    def setUp(self):
        self.config = Configuration()
        self.config.configure(api_key='fff', auto_capture_sessions=False)
        self.sessiontracker = SessionTracker(self.config)
        self.sessiontracker.auto_sessions = True  # Stub session delivery queue

    def tearDown(self):
        pass

    def test_increment_counts(self):
        """
        Every event should keep a list of prior events which occurred in the
        session
        """
        def next_callable(event):
            pass

        middleware = SessionMiddleware(next_callable)
        self.sessiontracker.start_session()

        event = Notification(Exception('shucks'), self.config, None)
        middleware(event)

        assert event.session['events']['unhandled'] == 0
        assert event.session['events']['handled'] == 1

        event2 = Notification(Exception('oh no'), self.config, None)
        middleware(event2)

        assert event2.session['events']['unhandled'] == 0
        assert event2.session['events']['handled'] == 2

        # Session counts should not change for events already handled
        assert event.session['events']['unhandled'] == 0
        assert event.session['events']['handled'] == 1