Debian Codegraph @

tests/test_service_endpoint_manager.py

raw
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5
6 import logging
7 import unittest
8 from azure_functions_devops_build.service_endpoint.service_endpoint_manager import ServiceEndpointManager
9 from azure_functions_devops_build.exceptions import RoleAssignmentException
10 from ._config import ORGANIZATION_NAME, PROJECT_NAME, REPOSITORY_NAME, CREATE_DEVOPS_OBJECTS
11 from ._helpers import get_credentials
12
13
14 class TestServiceEndpointManager(unittest.TestCase):
15 @classmethod
16 def setUpClass(cls):
17 logging.disable(logging.CRITICAL)
18
19 @classmethod
20 def tearDownClass(cls):
21 logging.disable(logging.NOTSET)
22
23 def setUp(self):
24 self.service_endpoint_manager = ServiceEndpointManager(
25 organization_name=ORGANIZATION_NAME,
26 project_name=PROJECT_NAME,
27 creds=get_credentials()
28 )
29
30 @unittest.SkipTest
31 def test_get_service_endpoints(self):
32 endpoints = self.service_endpoint_manager.get_service_endpoints(REPOSITORY_NAME)
33 self.assertIsNotNone(endpoints)
34 self.assertGreaterEqual(len(endpoints), 0)
35
36 @unittest.SkipTest
37 def test_get_service_endpoints_has_existing_endpoint(self):
38 expected_endpoint_name = self.service_endpoint_manager._get_service_endpoint_name(REPOSITORY_NAME, "pipeline")
39 endpoints = self.service_endpoint_manager.get_service_endpoints(REPOSITORY_NAME)
40 if len(endpoints) > 0:
41 self.assertEqual(endpoints[0].name, expected_endpoint_name)
42
43 @unittest.skipIf(
44 not CREATE_DEVOPS_OBJECTS,
45 "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for testing"
46 )
47 def test_create_service_endpoint(self):
48 expected_endpoint_name = self.service_endpoint_manager._get_service_endpoint_name(REPOSITORY_NAME, "pipeline")
49 existing_endpoints = self.service_endpoint_manager.get_service_endpoints(REPOSITORY_NAME)
50
51 # Skip if endpoint exists
52 if len(existing_endpoints) > 0:
53 raise unittest.SkipTest("Service endpoint does not exist")
54
55 # Skip if role assignment permission is not granted
56 try:
57 endpoint = self.service_endpoint_manager.create_service_endpoint(expected_endpoint_name)
58 except RoleAssignmentException:
59 raise unittest.SkipTest("Test operator may not have RoleAssignment/Write permission")
60
61 self.assertIsNotNone(endpoint)
62 self.assertEqual(endpoint.name, expected_endpoint_name)
63
64 if __name__ == '__main__':
65 unittest.main()