def test_clear(self): trace_ctx = TracingContext() trace_ctx.set_transaction_id('123') trace_ctx.set('name', 'tester') self.assertEqual(trace_ctx.get('name'), 'tester') self.assertEqual(trace_ctx.get_transaction_id(), '123') trace_ctx.clear() self.assertIsNone(trace_ctx.get('name')) self.assertIsNone(trace_ctx.get_transaction_id())
def test_scope(self): trace_ctx = TracingContext() trace_ctx.set_transaction_id('123') trace_ctx.set('dash-item', 'testing a dash item') trace_ctx.set('name', 'orig-name') trace_ctx.set('static', 'this value never changes') with trace_ctx.scope(transaction_id='789'): self.assertEqual(trace_ctx.get_transaction_id(), '789') self.assertEqual(trace_ctx.get('name'), 'orig-name') self.assertEqual(trace_ctx.get('dash-item'), 'testing a dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(transaction_id='789', name='new-name'): self.assertEqual(trace_ctx.get_transaction_id(), '789') self.assertEqual(trace_ctx.get('name'), 'new-name') self.assertEqual(trace_ctx.get('dash-item'), 'testing a dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(name='new-name'): self.assertEqual(trace_ctx.get_transaction_id(), '123') self.assertEqual(trace_ctx.get('name'), 'new-name') self.assertEqual(trace_ctx.get('dash-item'), 'testing a dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(ctx_values={'name': 'new-name-in-dict', 'dash-item': 'updated dash item'}): self.assertEqual(trace_ctx.get_transaction_id(), '123') self.assertEqual(trace_ctx.get('name'), 'new-name-in-dict') self.assertEqual(trace_ctx.get('dash-item'), 'updated dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(transaction_id='789', name='new-name', ctx_values={'dash-item': 'updated dash item'}): self.assertEqual(trace_ctx.get_transaction_id(), '789') self.assertEqual(trace_ctx.get('name'), 'new-name') self.assertEqual(trace_ctx.get('dash-item'), 'updated dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(name='new-name', ctx_values={'name': 'new-name-in-dict'}): self.assertEqual(trace_ctx.get_transaction_id(), '123') self.assertEqual(trace_ctx.get('name'), 'new-name') # Kwarg > ctx_values self.assertEqual(trace_ctx.get('dash-item'), 'testing a dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes') with trace_ctx.scope(transactionid='789'): self.assertEqual(trace_ctx.get_transaction_id(), '789') with trace_ctx.scope(transaction_id='789', ctx_values={'transactionid': '456'}): self.assertEqual(trace_ctx.get_transaction_id(), '789') # transaction_id arg > ctx_values self.assertEqual(trace_ctx.get_transaction_id(), '123') self.assertEqual(trace_ctx.get('name'), 'orig-name') self.assertEqual(trace_ctx.get('dash-item'), 'testing a dash item') self.assertEqual(trace_ctx.get('static'), 'this value never changes')
def test_remove_transaction_id(self): trace_ctx = TracingContext() trace_ctx.set_transaction_id('123') self.assertEqual(trace_ctx.get_transaction_id(), '123') trace_ctx.remove_transaction_id() self.assertIsNone(trace_ctx.get_transaction_id())
def test_set_and_get_transaction_id(self): trace_ctx = TracingContext() trace_ctx.set_transaction_id('123') self.assertEqual(trace_ctx.get_transaction_id(), '123')