azure-functions-devops-build/tests/test_project_manager.py

68 строки
2.7 KiB
Python
Исходник Постоянная ссылка Обычный вид История

2019-01-15 01:12:25 +03:00
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
2019-03-26 05:02:24 +03:00
import logging
import unittest
2019-03-26 05:02:24 +03:00
from azure_functions_devops_build.organization.organization_manager import OrganizationManager
2019-01-29 00:03:02 +03:00
from azure_functions_devops_build.project.project_manager import ProjectManager
2019-03-26 05:02:24 +03:00
from msrest.exceptions import HttpOperationError
2019-01-15 03:17:12 +03:00
from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME
from ._helpers import get_credentials
class TestProjectManager(unittest.TestCase):
2019-03-26 05:02:24 +03:00
@classmethod
def setUpClass(cls):
logging.disable(logging.CRITICAL)
2019-03-26 05:02:24 +03:00
@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,
2019-03-27 00:43:01 +03:00
"Set CREATE_DEVOPS_OBJECTS to True if you want to create resources for unit testing"
2019-03-26 05:02:24 +03:00
)
def test_create_project(self):
2019-03-26 05:02:24 +03:00
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.")
2019-03-26 05:02:24 +03:00
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.")
2019-03-26 05:02:24 +03:00
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__':
2019-03-26 05:02:24 +03:00
unittest.main()