Пример #1
0
    def test_credentials_retrieve_session(self, mock_retrieve):

        creds = ServicePrincipalCredentials.retrieve_session("client_id")
        mock_retrieve.asset_called_with(mock.ANY)

        mock_retrieve.side_effect = ValueError("No stored token")
        with self.assertRaises(ValueError):
            ServicePrincipalCredentials.retrieve_session("client_id")

        mock_retrieve.side_effect = TokenExpiredError("Token expired")
        with self.assertRaises(TokenExpiredError):
            ServicePrincipalCredentials.retrieve_session("client_id")
Пример #2
0
    def test_credentials_retrieve_session(self, mock_retrieve):

        creds = InteractiveCredentials.retrieve_session("client_id", "redirect")
        mock_retrieve.asset_called_with(mock.ANY)

        mock_retrieve.side_effect = ValueError("No stored token")
        with self.assertRaises(ValueError):
            InteractiveCredentials.retrieve_session("client_id", "redirect")

        mock_retrieve.side_effect = TokenExpiredError("Token expired")
        with self.assertRaises(TokenExpiredError):
            InteractiveCredentials.retrieve_session("client_id", "redirect")
Пример #3
0
    def test_credentials_retrieve_session(self):

        creds = mock.create_autospec(InteractiveCredentials)
        creds._retrieve_stored_token.return_value = {
            'expires_at': '1',
            'expires_in': '2',
            'refresh_token': "test"
        }

        token = InteractiveCredentials.retrieve_session(creds)
        self.assertEqual(token, creds._retrieve_stored_token.return_value)

        creds._retrieve_stored_token.side_effect = ValueError(
            "No stored token")
        self.assertIsNone(InteractiveCredentials.retrieve_session(creds))

        creds._retrieve_stored_token.side_effect = None
        creds.signed_session.side_effect = TokenExpiredError("Token expired")
        self.assertIsNone(InteractiveCredentials.retrieve_session(creds))