Esempio n. 1
0
 def test_has_transaction_id(self):
     trace_ctx = TracingContext()
     self.assertFalse(trace_ctx.has_transaction_id())
     trace_ctx.set_transaction_id('123')
     self.assertTrue(trace_ctx.has_transaction_id())
     trace_ctx.remove_transaction_id()
     self.assertFalse(trace_ctx.has_transaction_id())
Esempio n. 2
0
 def test_to_log_dict(self):
     trace_ctx = TracingContext()
     trace_ctx.set_transaction_id('123')
     trace_ctx.set('processid', '456')
     self.assertEqual(trace_ctx.to_log_dict(), {
         'tracectx.transactionid': '123',
         'tracectx.processid': '456'
     })
Esempio n. 3
0
 def test_to_http_header_dict(self):
     trace_ctx = TracingContext()
     trace_ctx.set_transaction_id('123')
     trace_ctx.set('processid', '456')
     self.assertEqual(trace_ctx.to_http_header_dict(), {
         'x-tracectx-transactionid': '123',
         'x-tracectx-processid': '456'
     })
Esempio n. 4
0
    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())
Esempio n. 5
0
    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')
Esempio n. 6
0
 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())
Esempio n. 7
0
 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')