File: conftest.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 (142 lines) | stat: -rw-r--r-- 5,274 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
142
"""Fixtures for testing."""

from collections.abc import AsyncGenerator

from aiohttp import ClientSession
from aioresponses import aioresponses
import pytest

from aioazuredevops.client import DEFAULT_API_VERSION, DEFAULT_BASE_URL, DevOpsClient

from . import (
    ORGANIZATION,
    PROJECT,
    RESPONSE_JSON_BASIC,
    RESPONSE_JSON_DEVOPS_BUILD,
    RESPONSE_JSON_DEVOPS_BUILDS,
    RESPONSE_JSON_DEVOPS_ITERATION,
    RESPONSE_JSON_DEVOPS_ITERATION_WORK_ITEMS,
    RESPONSE_JSON_DEVOPS_ITERATIONS,
    RESPONSE_JSON_DEVOPS_PROJECT,
    RESPONSE_JSON_DEVOPS_WIQL_RESULT,
    RESPONSE_JSON_DEVOPS_WORK_ITEM,
    RESPONSE_JSON_DEVOPS_WORK_ITEM_TYPES,
    RESPONSE_JSON_DEVOPS_WORK_ITEMS,
)


@pytest.fixture(autouse=True)
def mock_aioresponse():
    """Return a client session."""
    with aioresponses() as mocker:
        mocker.get(
            f"{DEFAULT_BASE_URL}/",
            payload=RESPONSE_JSON_BASIC,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_BASIC,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_BASIC,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/_apis?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_BASIC,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/_apis/projects?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_BASIC,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/_apis/projects/{PROJECT}?api-version={DEFAULT_API_VERSION}&includeCapabilities=true&includeHistory=true",
            payload=RESPONSE_JSON_DEVOPS_PROJECT,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/build/builds?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_BUILDS,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/build/builds/1?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_BUILD,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/work/teamsettings/iterations?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_ITERATIONS,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/work/teamsettings/iterations/abc123?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_ITERATION,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/work/teamsettings/iterations/abc123/workitems?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_ITERATION_WORK_ITEMS,
            status=200,
            repeat=True,
        )
        mocker.post(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/wiql?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_WIQL_RESULT,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/workitems?api-version={DEFAULT_API_VERSION}&errorPolicy=omit&ids=1",
            payload=RESPONSE_JSON_DEVOPS_WORK_ITEMS,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/workitems?api-version={DEFAULT_API_VERSION}&errorPolicy=omit&ids={'%252C'.join(str(i) for i in [1]*200)}",
            payload=RESPONSE_JSON_DEVOPS_WORK_ITEMS,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/workitems?api-version={DEFAULT_API_VERSION}&errorPolicy=omit&ids={'%252C'.join(str(i) for i in [1]*100)}",
            payload=RESPONSE_JSON_DEVOPS_WORK_ITEMS,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/workitems/1?api-version={DEFAULT_API_VERSION}&errorPolicy=omit",
            payload=RESPONSE_JSON_DEVOPS_WORK_ITEM,
            status=200,
            repeat=True,
        )
        mocker.get(
            f"{DEFAULT_BASE_URL}/{ORGANIZATION}/{PROJECT}/_apis/wit/workitemtypes?api-version={DEFAULT_API_VERSION}",
            payload=RESPONSE_JSON_DEVOPS_WORK_ITEM_TYPES,
            status=200,
            repeat=True,
        )

        yield mocker


@pytest.fixture
async def devops_client() -> AsyncGenerator[DevOpsClient, None]:
    """Return a DevOpsClient."""
    async with ClientSession() as session:
        yield DevOpsClient(session=session)