File: test_project_manager.py

package info (click to toggle)
azure-functions-devops-build 0.0.22-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: python: 2,422; sh: 12; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import logging
import unittest
from azure_functions_devops_build.organization.organization_manager import OrganizationManager
from azure_functions_devops_build.project.project_manager import ProjectManager
from msrest.exceptions import HttpOperationError
from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME
from ._helpers import get_credentials

class TestProjectManager(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        logging.disable(logging.CRITICAL)

    @classmethod
    def tearDownClass(cls):
        logging.disable(logging.NOTSET)

    def setUp(self):
        self.project_manager = ProjectManager(creds=get_credentials(), organization_name=ORGANIZATION_NAME)

    @unittest.skipIf(
        not CREATE_DEVOPS_OBJECTS,
        "Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
    )
    def test_create_project(self):
        existing_project_names = [
            proj.name for proj in self.project_manager.list_projects().value
        ]

        # If the project exists, we will skip this test
        if PROJECT_NAME in existing_project_names:
            raise unittest.SkipTest("Project already exists. No need to create a new project.")

        result = self.project_manager.create_project(PROJECT_NAME)
        self.assertIsNotNone(result.id)
        self.assertEqual(result.name, PROJECT_NAME)

    def test_invalid_create_duplicated_project(self):
        existing_project_names = [
            proj.name for proj in self.project_manager.list_projects().value
        ]

        # If no project exists, we will skip this test
        if len(existing_project_names) == 0:
            raise unittest.SkipTest("There is no existing project. Cannot create a duplicate.")

        result = self.project_manager.create_project(existing_project_names[0])
        self.assertFalse(result.valid)

    def test_invalid_create_project_with_bad_name(self):
        bad_project_name = "invalid-project-name#"
        result = self.project_manager.create_project(bad_project_name)
        self.assertFalse(result.valid)

    def test_list_projects(self):
        projects = self.project_manager.list_projects()
        self.assertIsNotNone(projects)
        self.assertIsNotNone(projects.value)
        self.assertGreaterEqual(projects.count, 0)

if __name__ == '__main__':
    unittest.main()