Exemple #1
0
 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"))
Exemple #2
0
 def test_log(self):
     """
     The log specified in the Request is passed on to the treq implementation.
     """
     log = object()
     req = ('GET', 'http://google.com/', None, None, {'log': 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
     self.assertEqual(self.successResultOf(perform(Effect(req))),
                      (response, "content"))
Exemple #3
0
 def test_perform(self):
     """
     The Request effect dispatches a request to treq, and returns a two-tuple
     of the Twisted Response object and the content as bytes.
     """
     req = ('GET', 'http://google.com/', None, None,  {'log': None})
     response = StubResponse(200, {})
     treq = StubTreq(reqs=[(req, response)],
                     contents=[(response, "content")])
     req = Request(method="get", url="http://google.com/")
     req.treq = treq
     self.assertEqual(
         self.successResultOf(perform(Effect(req))),
         (response, "content"))
Exemple #4
0
 def test_log(self):
     """
     The log specified in the Request is passed on to the treq
     implementation.
     """
     log = object()
     req = ('GET', 'http://google.com/', None, None, None, {'log': 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
     dispatcher = get_simple_dispatcher(None)
     self.assertEqual(
         self.successResultOf(perform(dispatcher, Effect(req))),
         (response, "content"))
Exemple #5
0
 def test_perform(self):
     """
     The Request effect dispatches a request to treq, and returns a
     two-tuple of the Twisted Response object and the content as bytes.
     """
     req = ('GET', 'http://google.com/', None, None, None, {
         'log': default_log
     })
     response = StubResponse(200, {})
     treq = StubTreq(reqs=[(req, response)],
                     contents=[(response, "content")])
     req = Request(method="get", url="http://google.com/")
     req.treq = treq
     dispatcher = get_simple_dispatcher(None)
     self.assertEqual(
         self.successResultOf(perform(dispatcher, Effect(req))),
         (response, "content"))
Exemple #6
0
 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"))
Exemple #7
0
 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"))
Exemple #8
0
 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"))