| 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.artifact.artifact_manager import ArtifactManager |
| 9 |
from ._config import ORGANIZATION_NAME, PROJECT_NAME |
| 10 |
from ._helpers import get_credentials |
| 11 |
|
| 12 |
class TestArtifactManager(unittest.TestCase): |
| 13 |
@classmethod |
| 14 |
def setUpClass(cls): |
| 15 |
logging.disable(logging.CRITICAL) |
| 16 |
|
| 17 |
@classmethod |
| 18 |
def tearDownClass(cls): |
| 19 |
logging.disable(logging.NOTSET) |
| 20 |
|
| 21 |
def setUp(self): |
| 22 |
self.artifact_manager = ArtifactManager( |
| 23 |
organization_name=ORGANIZATION_NAME, |
| 24 |
project_name=PROJECT_NAME, |
| 25 |
creds=get_credentials() |
| 26 |
) |
| 27 |
|
| 28 |
def test_list_artifacts(self): |
| 29 |
artifacts = self.artifact_manager.list_artifacts(build_id="1") |
| 30 |
if not artifacts: |
| 31 |
raise unittest.SkipTest("The build pipeline has no artifacts") |
| 32 |
|
| 33 |
# If the user is using the devops build manager to make builds there should only be one artifact |
| 34 |
# called drop as a result of running the builder commands. |
| 35 |
self.assertEqual(artifacts[0].name, 'drop') |
| 36 |
|
| 37 |
def test_invalid_list_artifacts_negative_build_id(self): |
| 38 |
artifacts = self.artifact_manager.list_artifacts(build_id="-1") |
| 39 |
self.assertEqual(len(artifacts), 0) |
| 40 |
|
| 41 |
def test_invalid_list_artifacts_str_build_id(self): |
| 42 |
with self.assertRaises(TypeError): |
| 43 |
artifacts = self.artifact_manager.list_artifacts(build_id="bad_id") |