| 1 |
"""Test helpers.""" |
| 2 |
|
| 3 |
from aioresponses import aioresponses |
| 4 |
import pytest |
| 5 |
from syrupy.assertion import SnapshotAssertion |
| 6 |
|
| 7 |
from aioazuredevops.client import DevOpsClient |
| 8 |
from aioazuredevops.helper import ( |
| 9 |
current_iteration, |
| 10 |
next_iteration, |
| 11 |
previous_iteration, |
| 12 |
work_item_types_states_filter, |
| 13 |
work_items_by_type_and_state, |
| 14 |
) |
| 15 |
from aioazuredevops.models.work_item_type import Category |
| 16 |
|
| 17 |
from . import ORGANIZATION, PROJECT |
| 18 |
|
| 19 |
|
| 20 |
@pytest.mark.asyncio |
| 21 |
async def test_current_iteration( |
| 22 |
devops_client: DevOpsClient, |
| 23 |
mock_aioresponse: aioresponses, |
| 24 |
snapshot: SnapshotAssertion, |
| 25 |
) -> None: |
| 26 |
"""Test the current_iteration method.""" |
| 27 |
iterations = await devops_client.get_iterations( |
| 28 |
organization=ORGANIZATION, |
| 29 |
project=PROJECT, |
| 30 |
) |
| 31 |
|
| 32 |
assert iterations is not None |
| 33 |
|
| 34 |
assert current_iteration(iterations) == snapshot() |
| 35 |
|
| 36 |
assert current_iteration([]) is None |
| 37 |
|
| 38 |
|
| 39 |
@pytest.mark.asyncio |
| 40 |
async def test_previous_iteration( |
| 41 |
devops_client: DevOpsClient, |
| 42 |
mock_aioresponse: aioresponses, |
| 43 |
snapshot: SnapshotAssertion, |
| 44 |
) -> None: |
| 45 |
"""Test the previous_iteration method.""" |
| 46 |
iterations = await devops_client.get_iterations( |
| 47 |
organization=ORGANIZATION, |
| 48 |
project=PROJECT, |
| 49 |
) |
| 50 |
|
| 51 |
assert iterations is not None |
| 52 |
|
| 53 |
assert previous_iteration(iterations) == snapshot() |
| 54 |
|
| 55 |
assert previous_iteration([]) is None |
| 56 |
|
| 57 |
|
| 58 |
@pytest.mark.asyncio |
| 59 |
async def test_next_iteration( |
| 60 |
devops_client: DevOpsClient, |
| 61 |
mock_aioresponse: aioresponses, |
| 62 |
snapshot: SnapshotAssertion, |
| 63 |
) -> None: |
| 64 |
"""Test the next_iteration method.""" |
| 65 |
iterations = await devops_client.get_iterations( |
| 66 |
organization=ORGANIZATION, |
| 67 |
project=PROJECT, |
| 68 |
) |
| 69 |
|
| 70 |
assert iterations is not None |
| 71 |
|
| 72 |
assert next_iteration(iterations) == snapshot() |
| 73 |
|
| 74 |
assert next_iteration([]) is None |
| 75 |
|
| 76 |
|
| 77 |
@pytest.mark.asyncio |
| 78 |
async def test_work_item_types_states_filter( |
| 79 |
devops_client: DevOpsClient, |
| 80 |
mock_aioresponse: aioresponses, |
| 81 |
snapshot: SnapshotAssertion, |
| 82 |
) -> None: |
| 83 |
"""Test the get_work_item_types method.""" |
| 84 |
work_item_types = await devops_client.get_work_item_types( |
| 85 |
organization=ORGANIZATION, |
| 86 |
project=PROJECT, |
| 87 |
) |
| 88 |
|
| 89 |
assert work_item_types is not None |
| 90 |
|
| 91 |
assert work_item_types_states_filter(work_item_types) == snapshot(name="no_filter") |
| 92 |
|
| 93 |
assert ( |
| 94 |
work_item_types_states_filter( |
| 95 |
work_item_types, |
| 96 |
categories=[Category.IN_PROGRESS], |
| 97 |
ignored_categories=[Category.COMPLETED, Category.REMOVED], |
| 98 |
) |
| 99 |
== snapshot() |
| 100 |
) |
| 101 |
|
| 102 |
|
| 103 |
@pytest.mark.asyncio |
| 104 |
async def test_work_items_by_type_and_state( |
| 105 |
devops_client: DevOpsClient, |
| 106 |
mock_aioresponse: aioresponses, |
| 107 |
snapshot: SnapshotAssertion, |
| 108 |
) -> None: |
| 109 |
"""Test the get_work_item_types method.""" |
| 110 |
work_item_types = await devops_client.get_work_item_types( |
| 111 |
organization=ORGANIZATION, |
| 112 |
project=PROJECT, |
| 113 |
) |
| 114 |
|
| 115 |
assert work_item_types is not None |
| 116 |
|
| 117 |
work_item_ids = await devops_client.get_work_item_ids( |
| 118 |
organization=ORGANIZATION, |
| 119 |
project=PROJECT, |
| 120 |
states=work_item_types_states_filter(work_item_types), |
| 121 |
) |
| 122 |
|
| 123 |
assert work_item_ids is not None |
| 124 |
|
| 125 |
work_items = await devops_client.get_work_items( |
| 126 |
organization=ORGANIZATION, |
| 127 |
project=PROJECT, |
| 128 |
ids=work_item_ids, |
| 129 |
) |
| 130 |
|
| 131 |
assert work_items is not None |
| 132 |
|
| 133 |
assert ( |
| 134 |
work_items_by_type_and_state( |
| 135 |
work_item_types, |
| 136 |
work_items, |
| 137 |
categories=[Category.IN_PROGRESS], |
| 138 |
ignored_categories=[Category.COMPLETED, Category.REMOVED], |
| 139 |
) |
| 140 |
== snapshot() |
| 141 |
) |