File: conftest.py

package info (click to toggle)
pypaperless 5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,440 kB
  • sloc: python: 5,607; sh: 26; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,122 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
"""Setup pytest."""

from collections.abc import AsyncGenerator, Generator
from typing import Any

import pytest
from aioresponses import aioresponses

from pypaperless import Paperless
from pypaperless.const import API_PATH

from .const import PAPERLESS_TEST_REQ_ARGS, PAPERLESS_TEST_TOKEN, PAPERLESS_TEST_URL
from .data import DATA_SCHEMA

# mypy: ignore-errors


@pytest.fixture(name="resp")
def aioresponses_fixture() -> Generator[aioresponses]:
    """Return aioresponses fixture."""
    with aioresponses() as m:
        yield m


@pytest.fixture(name="api")
def api_obj_fixture() -> Paperless:
    """Return Paperless."""
    return Paperless(
        PAPERLESS_TEST_URL,
        PAPERLESS_TEST_TOKEN,
        request_args=PAPERLESS_TEST_REQ_ARGS,
    )


@pytest.fixture(name="paperless")
async def paperless_fixture(
    resp: aioresponses,
    api: Paperless,
) -> AsyncGenerator[Paperless, Any]:
    """Return a Paperless object with given version."""
    resp.get(
        f"{PAPERLESS_TEST_URL}{API_PATH['index']}",
        status=200,
        payload=DATA_SCHEMA,
    )
    async with api:
        yield api