File: conftest.py

package info (click to toggle)
python-aioridwell 2024.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 1,062; sh: 41; makefile: 5
file content (112 lines) | stat: -rw-r--r-- 3,311 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
"""Define dynamic fixtures."""
import json
from collections.abc import Generator
from typing import Any, cast

import aiohttp
import pytest
from aresponses import ResponsesMockServer

from .common import generate_jwt, load_fixture


@pytest.fixture(name="authenticated_ridwell_api_server")
def authenticated_ridwell_api_server_fixture(
    authentication_response: dict[str, Any],
) -> Generator[ResponsesMockServer, None, None]:
    """Return a fixture that mocks an authenticated Ridwell API server.

    Args:
        authentication_response: An API response payload
    """
    server = ResponsesMockServer()
    server.add(
        "api.ridwell.com",
        "/",
        "post",
        response=aiohttp.web_response.json_response(
            authentication_response, status=200
        ),
    )
    yield server


@pytest.fixture(name="authentication_response")
def authentication_response_fixture() -> dict[str, Any]:
    """Define a fixture to return an authentication response.

    Returns:
        An API payload response.
    """
    return {"data": {"createAuthentication": {"authenticationToken": generate_jwt()}}}


@pytest.fixture(name="invalid_credentials_response", scope="session")
def invalid_credentials_response_fixture() -> dict[str, Any]:
    """Define a fixture to return an invalid credentials response.

    Returns:
        An API payload response.
    """
    return cast(
        dict[str, Any], json.loads(load_fixture("invalid_credentials_response.json"))
    )


@pytest.fixture(name="subscription_pickup_quote_response", scope="session")
def subscription_pickup_quote_response_fixture() -> dict[str, Any]:
    """Define a fixture to return estimated event cost info.

    Returns:
        An API payload response.
    """
    return cast(
        dict[str, Any],
        json.loads(load_fixture("subscription_pickup_quote_response.json")),
    )


@pytest.fixture(name="token_expired_response", scope="session")
def token_expired_response_fixture() -> dict[str, Any]:
    """Define a fixture to return an token expired response.

    Returns:
        An API payload response.
    """
    return cast(dict[str, Any], json.loads(load_fixture("token_expired_response.json")))


@pytest.fixture(name="upcoming_subscription_pickups_response", scope="session")
def upcoming_subscription_pickups_response_fixture() -> dict[str, Any]:
    """Define a fixture to return an info on all upcoming pickups.

    Returns:
        An API payload response.
    """
    return cast(
        dict[str, Any],
        json.loads(load_fixture("upcoming_subscription_pickups_response.json")),
    )


@pytest.fixture(name="update_subscription_pickup_response", scope="session")
def update_subscription_pickup_response_fixture() -> dict[str, Any]:
    """Define a fixture to return a response to opt in to a pickup event.

    Returns:
        An API payload response.
    """
    return cast(
        dict[str, Any],
        json.loads(load_fixture("update_subscription_pickup_response.json")),
    )


@pytest.fixture(name="user_response", scope="session")
def user_response_fixture() -> dict[str, Any]:
    """Define a fixture to return an user info response.

    Returns:
        An API payload response.
    """
    return cast(dict[str, Any], json.loads(load_fixture("user_response.json")))