def setUp(self): self.clock = Clock() self.log = mock_log() self.disp = ComposedDispatcher([ get_msg_time_dispatcher(self.clock), get_log_dispatcher(self.log, {}) ])
def test_log_none_effectful_fields(self): """ When log is not passed, but there are log fields from BoundFields, the log passed to treq has those fields. """ log = mock_log() # we have to include system='otter' in the expected log here because # the code falls back to otter.log.log, which has the system key bound. expected_log = matches(IsBoundWith(bound='stuff', system='otter')) req = ('GET', 'http://google.com/', None, None, None, { 'log': expected_log }) response = StubResponse(200, {}) treq = StubTreq(reqs=[(req, response)], contents=[(response, "content")]) req = Request(method="get", url="http://google.com/") req.treq = treq req_eff = Effect(req) bound_log_eff = with_log(req_eff, bound='stuff') dispatcher = ComposedDispatcher( [get_simple_dispatcher(None), get_log_dispatcher(log, {})]) self.assertEqual( self.successResultOf(perform(dispatcher, bound_log_eff)), (response, "content"))
def test_delete_group_log_context(self): """ When run in an effectful log context, the fields are bound to the log passed to get_scaling_group. """ self.group.delete_group.return_value = succeed('del') expected_lookup = (matches(IsBoundWith(base_log=True, effectful=True)), '00', 'g1') result = self.perform_with_group( Effect(DeleteGroup(tenant_id='00', group_id='g1')), expected_lookup, self.group, fallback_dispatcher=get_log_dispatcher(self.log, {'effectful': True})) self.assertEqual(result, 'del')
def test_get_scaling_group_info_log_context(self): """ When run in an effectful log context, the fields are bound to the log passed to delete_group. """ manifest = {} def view_manifest(with_policies, with_webhooks, get_deleting): return manifest self.group.view_manifest.side_effect = view_manifest eff = Effect(GetScalingGroupInfo(tenant_id='00', group_id='g1')) expected_lookup = (matches(IsBoundWith(base_log=True, effectful=True)), '00', 'g1') result = self.perform_with_group( eff, expected_lookup, self.group, fallback_dispatcher=get_log_dispatcher(self.log, {'effectful': True})) self.assertEqual(result, (self.group, manifest))
def test_log_effectful_fields(self): """ The log passed to treq is bound with the fields from BoundFields. """ log = mock_log().bind(duplicate='should be overridden') expected_log = matches(IsBoundWith(duplicate='effectful', bound='stuff')) req = ('GET', 'http://google.com/', None, None, None, {'log': expected_log}) response = StubResponse(200, {}) treq = StubTreq(reqs=[(req, response)], contents=[(response, "content")]) req = Request(method="get", url="http://google.com/", log=log) req.treq = treq req_eff = Effect(req) bound_log_eff = with_log(req_eff, bound='stuff', duplicate='effectful') dispatcher = ComposedDispatcher([ get_simple_dispatcher(None), get_log_dispatcher(log, {})]) self.assertEqual( self.successResultOf(perform(dispatcher, bound_log_eff)), (response, "content"))
def test_log_effectful_fields(self): """ The log passed to treq is bound with the fields from BoundFields. """ log = mock_log().bind(duplicate='should be overridden') expected_log = matches( IsBoundWith(duplicate='effectful', bound='stuff')) req = ('GET', 'http://google.com/', None, None, None, { 'log': expected_log }) response = StubResponse(200, {}) treq = StubTreq(reqs=[(req, response)], contents=[(response, "content")]) req = Request(method="get", url="http://google.com/", log=log) req.treq = treq req_eff = Effect(req) bound_log_eff = with_log(req_eff, bound='stuff', duplicate='effectful') dispatcher = ComposedDispatcher( [get_simple_dispatcher(None), get_log_dispatcher(log, {})]) self.assertEqual( self.successResultOf(perform(dispatcher, bound_log_eff)), (response, "content"))
def test_log_none_effectful_fields(self): """ When log is not passed, but there are log fields from BoundFields, the log passed to treq has those fields. """ log = mock_log() # we have to include system='otter' in the expected log here because # the code falls back to otter.log.log, which has the system key bound. expected_log = matches(IsBoundWith(bound='stuff', system='otter')) req = ('GET', 'http://google.com/', None, None, None, {'log': expected_log}) response = StubResponse(200, {}) treq = StubTreq(reqs=[(req, response)], contents=[(response, "content")]) req = Request(method="get", url="http://google.com/") req.treq = treq req_eff = Effect(req) bound_log_eff = with_log(req_eff, bound='stuff') dispatcher = ComposedDispatcher([ get_simple_dispatcher(None), get_log_dispatcher(log, {})]) self.assertEqual( self.successResultOf(perform(dispatcher, bound_log_eff)), (response, "content"))
def setUp(self): self.log = mock_log() self.disp = ComposedDispatcher([ get_log_dispatcher(self.log, {'f1': 'v'}), base_dispatcher])
def setUp(self): self.log = mock_log() self.disp = ComposedDispatcher( [get_log_dispatcher(self.log, {'f1': 'v'}), base_dispatcher])
def setUp(self): self.log = mock_log() self.disp = ComposedDispatcher([get_log_dispatcher(self.log, {"f1": "v"}), base_dispatcher])