File: test_helper.py

package info (click to toggle)
python-aioazuredevops 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: python: 1,770; makefile: 5
file content (141 lines) | stat: -rw-r--r-- 3,622 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""Test helpers."""

from aioresponses import aioresponses
import pytest
from syrupy.assertion import SnapshotAssertion

from aioazuredevops.client import DevOpsClient
from aioazuredevops.helper import (
    current_iteration,
    next_iteration,
    previous_iteration,
    work_item_types_states_filter,
    work_items_by_type_and_state,
)
from aioazuredevops.models.work_item_type import Category

from . import ORGANIZATION, PROJECT


@pytest.mark.asyncio
async def test_current_iteration(
    devops_client: DevOpsClient,
    mock_aioresponse: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test the current_iteration method."""
    iterations = await devops_client.get_iterations(
        organization=ORGANIZATION,
        project=PROJECT,
    )

    assert iterations is not None

    assert current_iteration(iterations) == snapshot()

    assert current_iteration([]) is None


@pytest.mark.asyncio
async def test_previous_iteration(
    devops_client: DevOpsClient,
    mock_aioresponse: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test the previous_iteration method."""
    iterations = await devops_client.get_iterations(
        organization=ORGANIZATION,
        project=PROJECT,
    )

    assert iterations is not None

    assert previous_iteration(iterations) == snapshot()

    assert previous_iteration([]) is None


@pytest.mark.asyncio
async def test_next_iteration(
    devops_client: DevOpsClient,
    mock_aioresponse: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test the next_iteration method."""
    iterations = await devops_client.get_iterations(
        organization=ORGANIZATION,
        project=PROJECT,
    )

    assert iterations is not None

    assert next_iteration(iterations) == snapshot()

    assert next_iteration([]) is None


@pytest.mark.asyncio
async def test_work_item_types_states_filter(
    devops_client: DevOpsClient,
    mock_aioresponse: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test the get_work_item_types method."""
    work_item_types = await devops_client.get_work_item_types(
        organization=ORGANIZATION,
        project=PROJECT,
    )

    assert work_item_types is not None

    assert work_item_types_states_filter(work_item_types) == snapshot(name="no_filter")

    assert (
        work_item_types_states_filter(
            work_item_types,
            categories=[Category.IN_PROGRESS],
            ignored_categories=[Category.COMPLETED, Category.REMOVED],
        )
        == snapshot()
    )


@pytest.mark.asyncio
async def test_work_items_by_type_and_state(
    devops_client: DevOpsClient,
    mock_aioresponse: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test the get_work_item_types method."""
    work_item_types = await devops_client.get_work_item_types(
        organization=ORGANIZATION,
        project=PROJECT,
    )

    assert work_item_types is not None

    work_item_ids = await devops_client.get_work_item_ids(
        organization=ORGANIZATION,
        project=PROJECT,
        states=work_item_types_states_filter(work_item_types),
    )

    assert work_item_ids is not None

    work_items = await devops_client.get_work_items(
        organization=ORGANIZATION,
        project=PROJECT,
        ids=work_item_ids,
    )

    assert work_items is not None

    assert (
        work_items_by_type_and_state(
            work_item_types,
            work_items,
            categories=[Category.IN_PROGRESS],
            ignored_categories=[Category.COMPLETED, Category.REMOVED],
        )
        == snapshot()
    )