Ejemplo n.º 1
0
class WaitingAuthenticatorTests(SynchronousTestCase):
    """
    Tests for `WaitingAuthenticator`
    """

    def setUp(self):
        """
        Create WaitingAuthenticator
        """
        self.clock = Clock()
        self.mock_auth = iMock(IAuthenticator)
        self.authenticator = WaitingAuthenticator(self.clock, self.mock_auth, 5)

    def test_waits(self):
        """
        Waits before returning token
        """
        self.mock_auth.authenticate_tenant.return_value = succeed('token')
        d = self.authenticator.authenticate_tenant('t1', 'log')
        self.assertNoResult(d)
        self.clock.advance(5)
        self.assertEqual(self.successResultOf(d), 'token')
        self.mock_auth.authenticate_tenant.assert_called_once_with('t1', log='log')

    def test_no_wait_on_error(self):
        """
        Does not wait if internal auth errors
        """
        self.mock_auth.authenticate_tenant.return_value = fail(ValueError('e'))
        d = self.authenticator.authenticate_tenant('t1', 'log')
        self.failureResultOf(d, ValueError)
Ejemplo n.º 2
0
class WaitingAuthenticatorTests(SynchronousTestCase):
    """
    Tests for `WaitingAuthenticator`
    """
    def setUp(self):
        """
        Create WaitingAuthenticator
        """
        self.clock = Clock()
        self.mock_auth = iMock(IAuthenticator)
        self.authenticator = WaitingAuthenticator(self.clock, self.mock_auth,
                                                  5)

    def test_waits(self):
        """
        Waits before returning token
        """
        self.mock_auth.authenticate_tenant.return_value = succeed('token')
        d = self.authenticator.authenticate_tenant('t1', 'log')
        self.assertNoResult(d)
        self.clock.advance(5)
        self.assertEqual(self.successResultOf(d), 'token')
        self.mock_auth.authenticate_tenant.assert_called_once_with('t1',
                                                                   log='log')

    def test_no_wait_on_error(self):
        """
        Does not wait if internal auth errors
        """
        self.mock_auth.authenticate_tenant.return_value = fail(ValueError('e'))
        d = self.authenticator.authenticate_tenant('t1', 'log')
        self.failureResultOf(d, ValueError)
Ejemplo n.º 3
0
 def setUp(self):
     """
     Create WaitingAuthenticator
     """
     self.clock = Clock()
     self.mock_auth = iMock(IAuthenticator)
     self.authenticator = WaitingAuthenticator(self.clock, self.mock_auth,
                                               5)
Ejemplo n.º 4
0
 def setUp(self):
     """
     Create WaitingAuthenticator
     """
     self.clock = Clock()
     self.mock_auth = iMock(IAuthenticator)
     self.authenticator = WaitingAuthenticator(self.clock, self.mock_auth, 5)