Skip to content

Commit 0408e73

Browse files
authored
Add extra tests to flick_electric (#138017)
Add extra tests to flick_electric
1 parent 9467709 commit 0408e73

File tree

7 files changed

+799
-585
lines changed

7 files changed

+799
-585
lines changed

tests/components/flick_electric/__init__.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@
77
CONF_SUPPLY_NODE_REF,
88
)
99
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
10+
from homeassistant.core import HomeAssistant
11+
12+
from tests.common import MockConfigEntry
1013

1114
CONF = {
12-
CONF_USERNAME: "test-username",
15+
CONF_USERNAME: "[email protected]",
1316
CONF_PASSWORD: "test-password",
14-
CONF_ACCOUNT_ID: "1234",
15-
CONF_SUPPLY_NODE_REF: "123",
17+
CONF_ACCOUNT_ID: "134800",
18+
CONF_SUPPLY_NODE_REF: "/network/nz/supply_nodes/ed7617df-4b10-4c8a-a05d-deadbeef8299",
1619
}
1720

1821

22+
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
23+
"""Fixture for setting up the component."""
24+
config_entry.add_to_hass(hass)
25+
26+
await hass.config_entries.async_setup(config_entry.entry_id)
27+
await hass.async_block_till_done()
28+
29+
1930
def _mock_flick_price():
2031
return FlickPrice(
2132
{
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""Flick Electric tests configuration."""
2+
3+
from collections.abc import Generator
4+
from unittest.mock import AsyncMock, patch
5+
6+
import json_api_doc
7+
from pyflick import FlickPrice
8+
import pytest
9+
10+
from homeassistant.components.flick_electric.const import CONF_ACCOUNT_ID, DOMAIN
11+
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
12+
13+
from . import CONF
14+
15+
from tests.common import MockConfigEntry, load_json_value_fixture
16+
17+
18+
@pytest.fixture
19+
def mock_config_entry() -> MockConfigEntry:
20+
"""Mock a config entry."""
21+
return MockConfigEntry(
22+
domain=DOMAIN,
23+
title="123 Fake Street, Newtown, Wellington 6021",
24+
data={**CONF},
25+
version=2,
26+
entry_id="974e52a5c0724d17b7ed876dd6ff4bc8",
27+
unique_id=CONF[CONF_ACCOUNT_ID],
28+
)
29+
30+
31+
@pytest.fixture
32+
def mock_old_config_entry() -> MockConfigEntry:
33+
"""Mock an outdated config entry."""
34+
return MockConfigEntry(
35+
domain=DOMAIN,
36+
data={
37+
CONF_USERNAME: CONF[CONF_USERNAME],
38+
CONF_PASSWORD: CONF[CONF_PASSWORD],
39+
},
40+
title=CONF[CONF_USERNAME],
41+
unique_id=CONF[CONF_USERNAME],
42+
version=1,
43+
)
44+
45+
46+
@pytest.fixture
47+
def mock_flick_client() -> Generator[AsyncMock]:
48+
"""Mock a Flick Electric client."""
49+
with (
50+
patch(
51+
"homeassistant.components.flick_electric.FlickAPI",
52+
autospec=True,
53+
) as mock_api,
54+
patch(
55+
"homeassistant.components.flick_electric.config_flow.FlickAPI",
56+
new=mock_api,
57+
),
58+
patch(
59+
"homeassistant.components.flick_electric.config_flow.SimpleFlickAuth.async_get_access_token",
60+
return_value="123456789abcdef",
61+
),
62+
):
63+
api = mock_api.return_value
64+
65+
api.getCustomerAccounts.return_value = json_api_doc.deserialize(
66+
load_json_value_fixture("accounts.json", DOMAIN)
67+
)
68+
api.getPricing.return_value = FlickPrice(
69+
json_api_doc.deserialize(
70+
load_json_value_fixture("rated_period.json", DOMAIN)
71+
)
72+
)
73+
74+
yield api
75+
76+
77+
@pytest.fixture
78+
def mock_flick_client_multiple() -> Generator[AsyncMock]:
79+
"""Mock a Flick Electric with multiple accounts."""
80+
with (
81+
patch(
82+
"homeassistant.components.flick_electric.FlickAPI",
83+
autospec=True,
84+
) as mock_api,
85+
patch(
86+
"homeassistant.components.flick_electric.config_flow.FlickAPI",
87+
new=mock_api,
88+
),
89+
patch(
90+
"homeassistant.components.flick_electric.config_flow.SimpleFlickAuth.async_get_access_token",
91+
return_value="123456789abcdef",
92+
),
93+
):
94+
api = mock_api.return_value
95+
96+
api.getCustomerAccounts.return_value = json_api_doc.deserialize(
97+
load_json_value_fixture("accounts_multi.json", DOMAIN)
98+
)
99+
api.getPricing.return_value = FlickPrice(
100+
json_api_doc.deserialize(
101+
load_json_value_fixture("rated_period.json", DOMAIN)
102+
)
103+
)
104+
105+
yield api
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"data": [
3+
{
4+
"id": "134800",
5+
"type": "customer_account",
6+
"attributes": {
7+
"account_number": "10123404",
8+
"billing_name": "9973debf-963f-49b0-9a73-Ba9c3400cbed@Anonymised Example",
9+
"billing_email": null,
10+
"address": "123 Fake Street, Newtown, Wellington 6021",
11+
"brand": "flick",
12+
"vulnerability_state": "none",
13+
"medical_dependency": false,
14+
"status": "active",
15+
"start_at": "2023-03-02T00:00:00.000+13:00",
16+
"end_at": null,
17+
"application_id": "5dfc4978-07de-4d18-8ef7-055603805ba6",
18+
"active": true,
19+
"on_join_journey": false,
20+
"placeholder": false
21+
},
22+
"relationships": {
23+
"user": {
24+
"data": {
25+
"id": "106676",
26+
"type": "customer_user"
27+
}
28+
},
29+
"sign_up": {
30+
"data": {
31+
"id": "877039",
32+
"type": "customer_sign_up"
33+
}
34+
},
35+
"main_customer": {
36+
"data": {
37+
"id": "108335",
38+
"type": "customer_customer"
39+
}
40+
},
41+
"main_consumer": {
42+
"data": {
43+
"id": "108291",
44+
"type": "customer_icp_consumer"
45+
}
46+
},
47+
"primary_contact": {
48+
"data": {
49+
"id": "121953",
50+
"type": "customer_contact"
51+
}
52+
},
53+
"default_payment_method": {
54+
"data": {
55+
"id": "602801",
56+
"type": "customer_payment_method"
57+
}
58+
},
59+
"phone_numbers": {
60+
"data": [
61+
{
62+
"id": "111604",
63+
"type": "customer_phone_number"
64+
}
65+
]
66+
},
67+
"payment_methods": {
68+
"data": [
69+
{
70+
"id": "602801",
71+
"type": "customer_payment_method"
72+
}
73+
]
74+
}
75+
}
76+
}
77+
],
78+
"included": [
79+
{
80+
"id": "108291",
81+
"type": "customer_icp_consumer",
82+
"attributes": {
83+
"start_date": "2023-03-02",
84+
"end_date": null,
85+
"icp_number": "0001234567UNB12",
86+
"supply_node_ref": "/network/nz/supply_nodes/ed7617df-4b10-4c8a-a05d-deadbeef8299",
87+
"physical_address": "123 FAKE STREET,NEWTOWN,WELLINGTON,6021"
88+
}
89+
}
90+
],
91+
"meta": {
92+
"verb": "get",
93+
"type": "customer_account",
94+
"params": [],
95+
"permission": {
96+
"uri": "flick:customer_app:resource:account:list",
97+
"data_context": null
98+
},
99+
"host": "https://api.flickuat.com",
100+
"service": "customer",
101+
"path": "/accounts",
102+
"description": "Returns the accounts viewable by the current user",
103+
"respond_with_array": true
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"data": [
3+
{
4+
"id": "134800",
5+
"type": "customer_account",
6+
"attributes": {
7+
"account_number": "10123404",
8+
"billing_name": "9973debf-963f-49b0-9a73-Ba9c3400cbed@Anonymised Example",
9+
"billing_email": null,
10+
"address": "123 Fake Street, Newtown, Wellington 6021",
11+
"brand": "flick",
12+
"vulnerability_state": "none",
13+
"medical_dependency": false,
14+
"status": "active",
15+
"start_at": "2023-03-02T00:00:00.000+13:00",
16+
"end_at": null,
17+
"application_id": "5dfc4978-07de-4d18-8ef7-055603805ba6",
18+
"active": true,
19+
"on_join_journey": false,
20+
"placeholder": false
21+
},
22+
"relationships": {
23+
"user": {
24+
"data": {
25+
"id": "106676",
26+
"type": "customer_user"
27+
}
28+
},
29+
"sign_up": {
30+
"data": {
31+
"id": "877039",
32+
"type": "customer_sign_up"
33+
}
34+
},
35+
"main_customer": {
36+
"data": {
37+
"id": "108335",
38+
"type": "customer_customer"
39+
}
40+
},
41+
"main_consumer": {
42+
"data": {
43+
"id": "108291",
44+
"type": "customer_icp_consumer"
45+
}
46+
},
47+
"primary_contact": {
48+
"data": {
49+
"id": "121953",
50+
"type": "customer_contact"
51+
}
52+
},
53+
"default_payment_method": {
54+
"data": {
55+
"id": "602801",
56+
"type": "customer_payment_method"
57+
}
58+
},
59+
"phone_numbers": {
60+
"data": [
61+
{
62+
"id": "111604",
63+
"type": "customer_phone_number"
64+
}
65+
]
66+
},
67+
"payment_methods": {
68+
"data": [
69+
{
70+
"id": "602801",
71+
"type": "customer_payment_method"
72+
}
73+
]
74+
}
75+
}
76+
},
77+
{
78+
"id": "123456",
79+
"type": "customer_account",
80+
"attributes": {
81+
"account_number": "123123123",
82+
"billing_name": "9973debf-963f-49b0-9a73-Ba9c3400cbed@Anonymised Example",
83+
"billing_email": null,
84+
"address": "456 Fake Street, Newtown, Wellington 6021",
85+
"brand": "flick",
86+
"vulnerability_state": "none",
87+
"medical_dependency": false,
88+
"status": "active",
89+
"start_at": "2023-03-02T00:00:00.000+13:00",
90+
"end_at": null,
91+
"application_id": "5dfc4978-07de-4d18-8ef7-055603805ba6",
92+
"active": true,
93+
"on_join_journey": false,
94+
"placeholder": false
95+
},
96+
"relationships": {
97+
"main_consumer": {
98+
"data": {
99+
"id": "11223344",
100+
"type": "customer_icp_consumer"
101+
}
102+
}
103+
}
104+
}
105+
],
106+
"included": [
107+
{
108+
"id": "108291",
109+
"type": "customer_icp_consumer",
110+
"attributes": {
111+
"start_date": "2023-03-02",
112+
"end_date": null,
113+
"icp_number": "0001234567UNB12",
114+
"supply_node_ref": "/network/nz/supply_nodes/ed7617df-4b10-4c8a-a05d-deadbeef8299",
115+
"physical_address": "123 FAKE STREET,NEWTOWN,WELLINGTON,6021"
116+
}
117+
},
118+
{
119+
"id": "11223344",
120+
"type": "customer_icp_consumer",
121+
"attributes": {
122+
"start_date": "2023-03-02",
123+
"end_date": null,
124+
"icp_number": "9991234567UNB12",
125+
"supply_node_ref": "/network/nz/supply_nodes/ed7617df-4b10-4c8a-a05d-deadbeef1234",
126+
"physical_address": "456 FAKE STREET,NEWTOWN,WELLINGTON,6021"
127+
}
128+
}
129+
],
130+
"meta": {
131+
"verb": "get",
132+
"type": "customer_account",
133+
"params": [],
134+
"permission": {
135+
"uri": "flick:customer_app:resource:account:list",
136+
"data_context": null
137+
},
138+
"host": "https://api.flickuat.com",
139+
"service": "customer",
140+
"path": "/accounts",
141+
"description": "Returns the accounts viewable by the current user",
142+
"respond_with_array": true
143+
}
144+
}

0 commit comments

Comments
 (0)