File: test_artifact_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 (43 lines) | stat: -rw-r--r-- 1,764 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
# --------------------------------------------------------------------------------------------
# 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.artifact.artifact_manager import ArtifactManager
from ._config import ORGANIZATION_NAME, PROJECT_NAME
from ._helpers import get_credentials

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

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

    def setUp(self):
        self.artifact_manager = ArtifactManager(
            organization_name=ORGANIZATION_NAME,
            project_name=PROJECT_NAME,
            creds=get_credentials()
        )

    def test_list_artifacts(self):
        artifacts = self.artifact_manager.list_artifacts(build_id="1")
        if not artifacts:
            raise unittest.SkipTest("The build pipeline has no artifacts")

        # If the user is using the devops build manager to make builds there should only be one artifact
        # called drop as a result of running the builder commands.
        self.assertEqual(artifacts[0].name, 'drop')

    def test_invalid_list_artifacts_negative_build_id(self):
        artifacts = self.artifact_manager.list_artifacts(build_id="-1")
        self.assertEqual(len(artifacts), 0)

    def test_invalid_list_artifacts_str_build_id(self):
        with self.assertRaises(TypeError):
            artifacts = self.artifact_manager.list_artifacts(build_id="bad_id")