コード例 #1
0
ファイル: test_auth.py プロジェクト: rackerlabs/otter
 def test_invalidate_token(self):
     """Performig causes a call to authenticator.invalidate."""
     mock_auth = iMock(ICachingAuthenticator)
     mock_auth.invalidate.return_value = None
     eff = Effect(InvalidateToken(mock_auth, 'tenant_id1'))
     self.assertEqual(sync_perform(get_simple_dispatcher(None), eff), None)
     mock_auth.invalidate.assert_called_once_with('tenant_id1')
コード例 #2
0
ファイル: test_auth.py プロジェクト: stephamon/otter
 def test_invalidate_token(self):
     """Performig causes a call to authenticator.invalidate."""
     mock_auth = iMock(ICachingAuthenticator)
     mock_auth.invalidate.return_value = None
     eff = Effect(InvalidateToken(mock_auth, 'tenant_id1'))
     self.assertEqual(sync_perform(get_simple_dispatcher(None), eff), None)
     mock_auth.invalidate.assert_called_once_with('tenant_id1')
コード例 #3
0
ファイル: test_pure_http.py プロジェクト: stephamon/otter
 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"))
コード例 #4
0
ファイル: test_auth.py プロジェクト: rackerlabs/otter
 def test_authenticate(self):
     """Performing causes a call to authenticator.authenticate_tenant."""
     result = ('token', {'catalog': 'foo'})
     mock_auth = iMock(IAuthenticator)
     mock_auth.authenticate_tenant.return_value = succeed(result)
     log = object()
     eff = Effect(Authenticate(mock_auth, 'tenant_id1', log))
     self.assertEqual(sync_perform(get_simple_dispatcher(None), eff),
                      result)
     mock_auth.authenticate_tenant.assert_called_once_with('tenant_id1',
                                                           log=log)
コード例 #5
0
ファイル: test_auth.py プロジェクト: stephamon/otter
 def test_authenticate(self):
     """Performing causes a call to authenticator.authenticate_tenant."""
     result = ('token', {'catalog': 'foo'})
     mock_auth = iMock(IAuthenticator)
     mock_auth.authenticate_tenant.return_value = succeed(result)
     log = object()
     eff = Effect(Authenticate(mock_auth, 'tenant_id1', log))
     self.assertEqual(sync_perform(get_simple_dispatcher(None), eff),
                      result)
     mock_auth.authenticate_tenant.assert_called_once_with('tenant_id1',
                                                           log=log)
コード例 #6
0
ファイル: test_pure_http.py プロジェクト: rackerlabs/otter
 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"))
コード例 #7
0
ファイル: test_pure_http.py プロジェクト: rackerlabs/otter
 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"))
コード例 #8
0
ファイル: test_pure_http.py プロジェクト: stephamon/otter
 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"))
コード例 #9
0
ファイル: test_pure_http.py プロジェクト: stephamon/otter
 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"))
コード例 #10
0
ファイル: test_pure_http.py プロジェクト: rackerlabs/otter
 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"))
コード例 #11
0
ファイル: test_pure_http.py プロジェクト: stephamon/otter
 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"))
コード例 #12
0
ファイル: test_pure_http.py プロジェクト: rackerlabs/otter
 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"))
コード例 #13
0
 def get_dispatcher(self):
     return get_simple_dispatcher(None)
コード例 #14
0
 def get_dispatcher(self):
     return get_simple_dispatcher(None)