Debian Codegraph @

tests/test_builder_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.builder.builder_manager import BuilderManager
9 from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME, REPOSITORY_NAME
10 from ._helpers import get_credentials
11
12
13 class TestBuilderManager(unittest.TestCase):
14
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._build_definition_name = "_build_{org}_{proj}_{repo}".format(
25 org=ORGANIZATION_NAME,
26 proj=PROJECT_NAME,
27 repo=REPOSITORY_NAME
28 )
29 self.builder_manager = BuilderManager(
30 organization_name=ORGANIZATION_NAME,
31 project_name=PROJECT_NAME,
32 repository_name=REPOSITORY_NAME,
33 creds=get_credentials()
34 )
35
36 @unittest.skipIf(
37 not CREATE_DEVOPS_OBJECTS,
38 "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
39 )
40 def test_create_definition(self):
41 definitions = self.builder_manager.list_definitions()
42
43 # Skip if definition already exists
44 if self._build_definition_name in [d.name for d in definitions]:
45 raise unittest.SkipTest("Build definition exists. No need to create a new build definition.")
46
47 definition = self.builder_manager.create_devops_build_definition(self._build_definition_name, "Default")
48 self.assertEqual(definition.name, self._build_definition_name)
49 self.assertEqual(definition.process['yamlFilename'], 'azure-pipelines.yml')
50
51 def test_list_definitions(self):
52 result = self.builder_manager.list_definitions()
53 self.assertIsNotNone(result)
54 self.assertGreaterEqual(len(result), 0)
55
56 def test_list_builds(self):
57 result = self.builder_manager.list_builds()
58 self.assertIsNotNone(result)
59 self.assertGreaterEqual(len(result), 0)
60
61 @unittest.skipIf(
62 not CREATE_DEVOPS_OBJECTS,
63 "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
64 )
65 def test_create_build(self):
66 result = self.builder_manager.create_build(self._build_definition_name, "Default")
67 self.assertIsNotNone(result)
68 self.assertEqual(result.definition.name, self._build_definition_name)
69
70 if __name__ == '__main__':
71 unittest.main()