Skip to content

Commit ed85021

Browse files
committed
TypeError to ValueError and test none for vlan config
1 parent 3ff541f commit ed85021

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

aiohasupervisor/models/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,5 @@ class AccessPointList(ResponseData):
194194
class VlanConfig(Options):
195195
"""VlanConfig model."""
196196

197-
ipv4: IPv4Config
198-
ipv6: IPv6Config
197+
ipv4: IPv4Config | None = None
198+
ipv6: IPv6Config | None = None

tests/test_network.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ async def test_network_update_interface(
9696
) -> None:
9797
"""Test network interface update API."""
9898
responses.post(f"{SUPERVISOR_URL}/network/interface/end0/update", status=200)
99-
100-
# Must set something
101-
with pytest.raises(TypeError):
102-
config = NetworkInterfaceConfig()
103-
10499
config = NetworkInterfaceConfig(
105100
ipv4=IPv4Config(
106101
method=InterfaceMethod.STATIC,
@@ -135,18 +130,29 @@ async def test_network_access_points(
135130
assert result[1].ssid == "VQ@35(55720"
136131

137132

133+
@pytest.mark.parametrize(
134+
"config",
135+
[None, NetworkInterfaceConfig(ipv4=IPv4Config(method=InterfaceMethod.AUTO))],
136+
)
138137
async def test_network_save_vlan(
139-
responses: aioresponses, supervisor_client: SupervisorClient
138+
responses: aioresponses,
139+
supervisor_client: SupervisorClient,
140+
config: NetworkInterfaceConfig | None,
140141
) -> None:
141142
"""Test network save vlan API."""
142143
responses.post(f"{SUPERVISOR_URL}/network/interface/end0/vlan/1", status=200)
143-
144-
# Must set something
145-
with pytest.raises(TypeError):
146-
config = VlanConfig()
147-
148-
config = NetworkInterfaceConfig(ipv4=IPv4Config(method=InterfaceMethod.AUTO))
149144
assert await supervisor_client.network.save_vlan("end0", 1, config=config) is None
150145
assert responses.requests.keys() == {
151146
("POST", URL(f"{SUPERVISOR_URL}/network/interface/end0/vlan/1"))
152147
}
148+
149+
150+
async def test_network_configs_cannot_be_empty() -> None:
151+
"""Test network config instances require at least one field specified."""
152+
# Network interface config for update calls
153+
with pytest.raises(ValueError, match="At least one field must have a value"):
154+
NetworkInterfaceConfig()
155+
156+
# Vlan config for save vlan calls
157+
with pytest.raises(ValueError, match="At least one field must have a value"):
158+
VlanConfig()

0 commit comments

Comments
 (0)