File: conftest.py

package info (click to toggle)
python-mill-local 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: python: 348; sh: 5; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,466 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
"""Test helpers """

import json
import pathlib

import pytest
from aiohttp import ClientSession
from aioresponses import aioresponses


# See https://github.com/pnuckowski/aioresponses/issues/218
@pytest.fixture
def mocked_response():
    with aioresponses() as m:
        yield m


@pytest.fixture(autouse=True)
async def client_session():
    """Fixture to execute asserts before and after a test is run"""
    # Setup
    client_session = ClientSession()

    yield client_session

    # Teardown
    await client_session.close()


@pytest.fixture(scope="session")
def status_command_response():
    """A response for GET /status request."""
    return load_fixture("status_command_response.json")


@pytest.fixture(scope="session")
def control_status_response():
    """A response for GET /control-status call."""
    return load_fixture("control_status_response.json")


@pytest.fixture(scope="session")
def generic_status_ok_response():
    """A generic response with status OK."""
    return load_fixture("generic_status_ok_response.json")


@pytest.fixture(scope="session")
def oil_heater_power_response():
    """A generic response with status OK."""
    return load_fixture("oil_heater_power_response.json")


def load_fixture(name: str):
    """Load a fixture from disk."""
    path = pathlib.Path(__file__).parent / "fixtures" / name

    content = path.read_text()

    if name.endswith(".json"):
        return json.loads(content)

    return content