def test_get_service_admin_token_non_200(self): """Test to get the service admin token with a non-200 response.""" responses.add(responses.POST, 'http://{}:{}/api/v1/token-auth/'.format( self.koku_host, self.koku_port), json={'error': 'not found'}, status=404) accessor = CURAccountsNetwork() with self.assertRaises(CURAccountsInterfaceError): accessor._get_service_admin_token()
def test_get_service_admin_token_unexpected_response(self): """Test to get the service admin token with an unexpected response.""" responses.add(responses.POST, 'http://{}:{}/api/v1/token-auth/'.format( self.koku_host, self.koku_port), body='sample text response', headers={'Content-Type': 'text/plain'}, status=200) accessor = CURAccountsNetwork() with self.assertRaises(CURAccountsInterfaceError): accessor._get_service_admin_token()
def test_get_service_admin_token_unexpected_error(self): """Test to get the service admin token with an unexpected error.""" responses.add(responses.POST, 'http://{}:{}/api/v1/token-auth/'.format( self.koku_host, self.koku_port), json={'token': self.mock_token}, status=200) accessor = CURAccountsNetwork() with patch.object( requests, 'post', side_effect=requests.exceptions.RequestException('err')): with self.assertRaises(CURAccountsInterfaceError): accessor._get_service_admin_token()
def test_get_service_admin_token(self): """Test to get the service admin token.""" responses.add(responses.POST, 'http://{}:{}/api/v1/token-auth/'.format( self.koku_host, self.koku_port), json={'token': self.mock_token}, status=200) accessor = CURAccountsNetwork() token = accessor._get_service_admin_token() self.assertEqual(token, self.mock_token)
def test_get_service_admin_token_network_error(self, mock_host): """Test to get the service admin token with a network error.""" accessor = CURAccountsNetwork() with self.assertRaises(CURAccountsInterfaceError): accessor._get_service_admin_token()