Ejemplo n.º 1
0
    def test_no_propagators(self):
        propagator = CompositeHTTPPropagator([])
        new_carrier = {}
        propagator.inject(new_carrier)
        self.assertEqual(new_carrier, {})

        context = propagator.extract(carrier=new_carrier,
                                     context={},
                                     getter=get_as_list)
        self.assertEqual(context, {})
Ejemplo n.º 2
0
    def test_no_propagators(self):
        propagator = CompositeHTTPPropagator([])
        new_carrier = {}
        propagator.inject(dict.__setitem__, carrier=new_carrier)
        self.assertEqual(new_carrier, {})

        context = propagator.extract(get_as_list,
                                     carrier=new_carrier,
                                     context={})
        self.assertEqual(context, {})
Ejemplo n.º 3
0
    def test_single_propagator(self):
        propagator = CompositeHTTPPropagator([self.mock_propagator_0])

        new_carrier = {}
        propagator.inject(new_carrier)
        self.assertEqual(new_carrier, {"mock-0": "data"})

        context = propagator.extract(carrier=new_carrier,
                                     context={},
                                     getter=get_as_list)
        self.assertEqual(context, {"mock-0": "context"})
Ejemplo n.º 4
0
    def test_multiple_propagators(self):
        propagator = CompositeHTTPPropagator(
            [self.mock_propagator_0, self.mock_propagator_1])

        new_carrier = {}
        propagator.inject(dict.__setitem__, carrier=new_carrier)
        self.assertEqual(new_carrier, {"mock-0": "data", "mock-1": "data"})

        context = propagator.extract(get_as_list,
                                     carrier=new_carrier,
                                     context={})
        self.assertEqual(context, {"mock-0": "context", "mock-1": "context"})
Ejemplo n.º 5
0
    def test_multiple_propagators_same_key(self):
        # test that when multiple propagators extract/inject the same
        # key, the later propagator values are extracted/injected
        propagator = CompositeHTTPPropagator(
            [self.mock_propagator_0, self.mock_propagator_2])

        new_carrier = {}
        propagator.inject(new_carrier)
        self.assertEqual(new_carrier, {"mock-0": "data2"})

        context = propagator.extract(carrier=new_carrier,
                                     context={},
                                     getter=get_as_list)
        self.assertEqual(context, {"mock-0": "context2"})
Ejemplo n.º 6
0
    def test_fields(self):
        propagator = CompositeHTTPPropagator([
            self.mock_propagator_0,
            self.mock_propagator_1,
            self.mock_propagator_2,
        ])

        mock_setter = Mock()

        propagator.inject({}, setter=mock_setter)

        inject_fields = set()

        for mock_call in mock_setter.mock_calls:
            inject_fields.add(mock_call[1][1])

        self.assertEqual(inject_fields, propagator.fields)