def test__authenticate(self): authObj = auth.Authenticator(mock.Mock(), auth.KeyStoneV2Authenticator, mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()) # test response code 200 resp = mock.Mock() resp.status = 200 body = "test_body" auth.ServiceCatalog._load = mock.Mock(return_value=1) authObj.client._time_request = mock.Mock(return_value=(resp, body)) sc = authObj._authenticate(mock.Mock(), mock.Mock()) self.assertEqual(body, sc.catalog) # test AmbiguousEndpoints exception auth.ServiceCatalog.__init__ = mock.Mock( side_effect=exceptions.AmbiguousEndpoints) self.assertRaises(exceptions.AmbiguousEndpoints, authObj._authenticate, mock.Mock(), mock.Mock()) # test handling KeyError and raising AuthorizationFailure exception auth.ServiceCatalog.__init__ = mock.Mock(side_effect=KeyError) self.assertRaises(exceptions.AuthorizationFailure, authObj._authenticate, mock.Mock(), mock.Mock()) # test EndpointNotFound exception mock_obj = mock.Mock(side_effect=exceptions.EndpointNotFound) auth.ServiceCatalog.__init__ = mock_obj self.assertRaises(exceptions.EndpointNotFound, authObj._authenticate, mock.Mock(), mock.Mock()) mock_obj.side_effect = None # test response code 305 resp.__getitem__ = mock.Mock(return_value='loc') resp.status = 305 body = "test_body" authObj.client._time_request = mock.Mock(return_value=(resp, body)) l = authObj._authenticate(mock.Mock(), mock.Mock()) self.assertEqual('loc', l) # test any response code other than 200 and 305 resp.status = 404 exceptions.from_response = mock.Mock(side_effect=ValueError) self.assertRaises(ValueError, authObj._authenticate, mock.Mock(), mock.Mock())
def test_authenticate(self): authObj = auth.Authenticator(mock.Mock(), auth.KeyStoneV2Authenticator, mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()) self.assertRaises(NotImplementedError, authObj.authenticate)