-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Expand file tree
/
Copy pathconftest.py
More file actions
122 lines (104 loc) · 3.36 KB
/
conftest.py
File metadata and controls
122 lines (104 loc) · 3.36 KB
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
"""Fixtures for the Nord Pool integration."""
from collections.abc import AsyncGenerator
import json
from typing import Any
from pynordpool import API, NordPoolClient
import pytest
from homeassistant.components.nordpool.const import DOMAIN, PLATFORMS
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from . import ENTRY_CONFIG
from tests.common import MockConfigEntry, load_fixture, patch
from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.fixture(name="load_platforms")
async def patch_platform_constant() -> list[Platform]:
"""Return list of platforms to load."""
return PLATFORMS
@pytest.fixture
async def load_int(
hass: HomeAssistant,
get_client: NordPoolClient,
load_platforms: list[Platform],
) -> MockConfigEntry:
"""Set up the Nord Pool integration in Home Assistant."""
config_entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_USER,
data=ENTRY_CONFIG,
)
config_entry.add_to_hass(hass)
with patch("homeassistant.components.nordpool.PLATFORMS", load_platforms):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry
@pytest.fixture(name="get_client")
async def get_data_from_library(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
load_json: list[dict[str, Any]],
) -> AsyncGenerator[NordPoolClient]:
"""Retrieve data from Nord Pool library."""
aioclient_mock.request(
"GET",
url=API + "/DayAheadPrices",
params={
"date": "2025-10-01",
"market": "DayAhead",
"deliveryArea": "SE3,SE4",
"currency": "SEK",
},
json=load_json[0],
)
aioclient_mock.request(
"GET",
url=API + "/DayAheadPrices",
params={
"date": "2025-10-01",
"market": "DayAhead",
"deliveryArea": "SE3",
"currency": "EUR",
},
json=load_json[0],
)
aioclient_mock.request(
"GET",
url=API + "/DayAheadPrices",
params={
"date": "2025-09-30",
"market": "DayAhead",
"deliveryArea": "SE3,SE4",
"currency": "SEK",
},
json=load_json[1],
)
aioclient_mock.request(
"GET",
url=API + "/DayAheadPrices",
params={
"date": "2025-10-02",
"market": "DayAhead",
"deliveryArea": "SE3,SE4",
"currency": "SEK",
},
json=load_json[2],
)
client = NordPoolClient(aioclient_mock.create_session(hass.loop))
yield client
await client._session.close()
@pytest.fixture(name="load_json")
def load_json_from_fixture(load_data: list[str, str, str]) -> list[dict[str, Any]]:
"""Load fixture with json data and return."""
return [
json.loads(load_data[0]),
json.loads(load_data[1]),
json.loads(load_data[2]),
]
@pytest.fixture(name="load_data", scope="package")
def load_data_from_fixture() -> list[str, str, str]:
"""Load fixture with fixture data and return."""
return [
load_fixture("delivery_period_today.json", DOMAIN),
load_fixture("delivery_period_yesterday.json", DOMAIN),
load_fixture("delivery_period_tomorrow.json", DOMAIN),
]