def test_success_finishes_action(self): tracer = TimelineTracer(self.factory) action = timeline.Timeline().start('foo', 'bar') tracer.threadinfo.action = action tracer.connection_raw_execute_success( 'conn', 'cursor', 'statement', 'params') self.assertNotEqual(None, action.duration)
def test_success_finishes_action(self): tracer = TimelineTracer(self.factory) action = timeline.Timeline().start('foo', 'bar') tracer.threadinfo.action = action tracer.connection_raw_execute_success('conn', 'cursor', 'statement', 'params') self.assertNotEqual(None, action.duration)
def test_category_from_prefix_and_connection_name(self): class StubConnection(Connection): def __init__(self): self._database = None self._event = None self._raw_connection = None self.name = 'Foo' tracer = TimelineTracer(self.factory, prefix='bar-') tracer._expanded_raw_execute(StubConnection(), 'cursor', 'statement') self.assertEqual('bar-Foo', self.timeline.actions[-1].category)
def test_default_prefix(self): """By default the prefix "SQL-" is added to the action's category.""" tracer = TimelineTracer(self.factory) tracer._expanded_raw_execute('conn', 'cursor', 'statement') self.assertEqual('SQL-<unknown>', self.timeline.actions[-1].category)
def test_unnamed_connection(self): """A connection with no name has <unknown> put in as a placeholder.""" tracer = TimelineTracer(self.factory, prefix='bar-') tracer._expanded_raw_execute('conn', 'cursor', 'statement') self.assertEqual('bar-<unknown>', self.timeline.actions[-1].category)
def test_action_details_are_statement(self): """The detail in the timeline action is the formatted SQL statement.""" tracer = TimelineTracer(self.factory) tracer._expanded_raw_execute('conn', 'cursor', 'statement') self.assertEqual('statement', self.timeline.actions[-1].detail)
def test_finds_timeline_from_factory(self): factory_result = timeline.Timeline() tracer = TimelineTracer(lambda: factory_result) tracer._expanded_raw_execute('conn', 'cursor', 'statement') self.assertEqual(1, len(factory_result.actions))
def test_category_from_prefix_and_connection_name(self): tracer = TimelineTracer(self.factory, prefix='bar-') tracer._expanded_raw_execute(StubConnection(), 'cursor', 'statement') self.assertEqual('bar-Foo', self.timeline.actions[-1].category)
def test_separate_tracers_own_state(self): """Check that multiple TimelineTracer's could be used at once.""" tracer1 = TimelineTracer(self.factory) tracer2 = TimelineTracer(self.factory) tracer1.threadinfo.action = 'foo' self.assertEqual(None, getattr(tracer2.threadinfo, 'action', None))