File: authentication.py

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (30 lines) | stat: -rw-r--r-- 1,724 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import unittest

try:
    # Attempt to load mock (works on Python 3.3 and above)
    from unittest.mock import patch
except ImportError:
    # Attempt to load mock (works on Python version below 3.3)
    from mock import patch
from .helper import UNIT_TEST_PAT_TOKEN

class AuthenticatedTests(unittest.TestCase):

    def authentication_setup(self):
        self.resolve_identity_patcher = patch('azext_devops.dev.common.identities.resolve_identity_as_id') # pylint: disable=attribute-defined-outside-init
        self.get_credential_patcher = patch('azext_devops.dev.common.services.get_credential') # pylint: disable=attribute-defined-outside-init
        self.validate_token_patcher = patch('azext_devops.dev.common.services.validate_token_for_instance') # pylint: disable=attribute-defined-outside-init

        # start the patchers
        self.mock_resolve_identity = self.resolve_identity_patcher.start() # pylint: disable=attribute-defined-outside-init
        self.mock_get_credential = self.get_credential_patcher.start() # pylint: disable=attribute-defined-outside-init
        self.mock_validate_token = self.validate_token_patcher.start() # pylint: disable=attribute-defined-outside-init

    def authenticate(self):
        # set return values
        self.mock_validate_token.return_value = True
        self.mock_get_credential.return_value = UNIT_TEST_PAT_TOKEN