Debian Codegraph @

tests/test_barrier.py

raw symbols SCIP
1 from unittest.mock import AsyncMock, MagicMock
2
3 import pytest
4
5 from nice_go import Barrier
6 from nice_go._barrier import BarrierState
7
8
9 async def test_open() -> None:
10 barrier = Barrier(
11 "barrier_id",
12 "barrier_type",
13 "control_level",
14 [],
15 BarrierState(
16 deviceId="device_id",
17 reported={"key": "value"},
18 timestamp="timestamp",
19 version="version",
20 connectionState=None,
21 ),
22 MagicMock(open_barrier=AsyncMock(return_value=True)),
23 )
24 assert await barrier.open() is True
25
26
27 async def test_close() -> None:
28 barrier = Barrier(
29 "barrier_id",
30 "barrier_type",
31 "control_level",
32 [],
33 BarrierState(
34 deviceId="device_id",
35 reported={"key": "value"},
36 timestamp="timestamp",
37 version="version",
38 connectionState=None,
39 ),
40 MagicMock(close_barrier=AsyncMock(return_value=True)),
41 )
42 assert await barrier.close() is True
43
44
45 async def test_light_on() -> None:
46 barrier = Barrier(
47 "barrier_id",
48 "barrier_type",
49 "control_level",
50 [],
51 BarrierState(
52 deviceId="device_id",
53 reported={"key": "value"},
54 timestamp="timestamp",
55 version="version",
56 connectionState=None,
57 ),
58 MagicMock(light_on=AsyncMock(return_value=True)),
59 )
60 assert await barrier.light_on() is True
61
62
63 async def test_light_off() -> None:
64 barrier = Barrier(
65 "barrier_id",
66 "barrier_type",
67 "control_level",
68 [],
69 BarrierState(
70 deviceId="device_id",
71 reported={"key": "value"},
72 timestamp="timestamp",
73 version="version",
74 connectionState=None,
75 ),
76 MagicMock(light_off=AsyncMock(return_value=True)),
77 )
78 assert await barrier.light_off() is True
79
80
81 async def test_get_attr() -> None:
82 barrier = Barrier(
83 "barrier_id",
84 "barrier_type",
85 "control_level",
86 [{"key": "key", "value": "value"}],
87 BarrierState(
88 deviceId="device_id",
89 reported={"key": "value"},
90 timestamp="timestamp",
91 version="version",
92 connectionState=None,
93 ),
94 MagicMock(),
95 )
96 assert await barrier.get_attr("key") == "value"
97
98
99 async def test_get_attr_not_found() -> None:
100 barrier = Barrier(
101 "barrier_id",
102 "barrier_type",
103 "control_level",
104 [{"key": "key", "value": "value"}],
105 BarrierState(
106 deviceId="device_id",
107 reported={"key": "value"},
108 timestamp="timestamp",
109 version="version",
110 connectionState=None,
111 ),
112 MagicMock(),
113 )
114 with pytest.raises(KeyError) as exc_info:
115 await barrier.get_attr("not_found")
116 assert str(exc_info.value) == "'Attribute with key not_found not found.'"
117
118
119 async def test_vacation_mode_on() -> None:
120 mock_api = MagicMock(vacation_mode_on=AsyncMock())
121 barrier = Barrier(
122 "barrier_id",
123 "barrier_type",
124 "control_level",
125 [],
126 BarrierState(
127 deviceId="device_id",
128 reported={"key": "value"},
129 timestamp="timestamp",
130 version="version",
131 connectionState=None,
132 ),
133 mock_api,
134 )
135 await barrier.vacation_mode_on()
136 mock_api.vacation_mode_on.assert_called_once_with("barrier_id")
137
138
139 async def test_vacation_mode_off() -> None:
140 mock_api = MagicMock(vacation_mode_off=AsyncMock())
141 barrier = Barrier(
142 "barrier_id",
143 "barrier_type",
144 "control_level",
145 [],
146 BarrierState(
147 deviceId="device_id",
148 reported={"key": "value"},
149 timestamp="timestamp",
150 version="version",
151 connectionState=None,
152 ),
153 mock_api,
154 )
155 await barrier.vacation_mode_off()
156 mock_api.vacation_mode_off.assert_called_once_with("barrier_id")