| 1 |
"""Fixtures for aiowebdav2 tests.""" |
| 2 |
|
| 3 |
from collections.abc import AsyncGenerator, Callable, Generator |
| 4 |
|
| 5 |
from aioresponses import aioresponses |
| 6 |
import pytest |
| 7 |
|
| 8 |
from aiowebdav2 import Client |
| 9 |
from tests import load_responses |
| 10 |
|
| 11 |
|
| 12 |
@pytest.fixture(name="responses") |
| 13 |
def aioresponses_fixture() -> Generator[aioresponses, None, None]: |
| 14 |
"""Return aioresponses fixture.""" |
| 15 |
with aioresponses() as mocked_responses: |
| 16 |
yield mocked_responses |
| 17 |
|
| 18 |
|
| 19 |
@pytest.fixture(autouse=True) |
| 20 |
def mock_responses(responses: aioresponses) -> None: |
| 21 |
"""Add default responses.""" |
| 22 |
responses.add( |
| 23 |
"https://webdav.example.com", |
| 24 |
"PROPFIND", |
| 25 |
headers={"Accept": "*/*", "Depth": "1"}, |
| 26 |
content_type="application/xml", |
| 27 |
status=200, |
| 28 |
body=load_responses("get_list.xml"), |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
@pytest.fixture(name="client") |
| 33 |
async def client() -> AsyncGenerator[Client, None]: |
| 34 |
"""Return a aiowebdav2 client.""" |
| 35 |
async with ( |
| 36 |
Client( |
| 37 |
url="https://webdav.example.com", |
| 38 |
username="user", |
| 39 |
password="password", |
| 40 |
) as c, |
| 41 |
): |
| 42 |
yield c |
| 43 |
|
| 44 |
|
| 45 |
@pytest.fixture |
| 46 |
async def get_client() -> Callable[[str], Client]: |
| 47 |
"""Return a aiowebdav2 client.""" |
| 48 |
|
| 49 |
def _get_client(path: str = "/") -> Client: |
| 50 |
return Client( |
| 51 |
url=f"https://webdav.example.com{path}", |
| 52 |
username="user", |
| 53 |
password="password", |
| 54 |
) |
| 55 |
|
| 56 |
return _get_client |