@@ -26,21 +26,27 @@ def test_charger_auth_err(status_mock_err, config_mock_err):
2626
2727
2828@pytest .fixture (name = "status_mock_err" )
29- def mock_status_err (requests_mock ):
29+ def mock_status_err ():
3030 """Mock the status reply."""
31- requests_mock .get (
32- TEST_URL_STATUS ,
33- status_code = 401 ,
34- )
31+ with aioresponses () as client_mock :
32+ client_mock .get (
33+ TEST_URL_STATUS ,
34+ status = 401 ,
35+ )
36+
37+ yield client_mock
3538
3639
3740@pytest .fixture (name = "config_mock_err" )
38- def mock_config_err (requests_mock ):
41+ def mock_config_err ():
3942 """Mock the config reply."""
40- requests_mock .get (
41- TEST_URL_CONFIG ,
42- status_code = 401 ,
43- )
43+ with aioresponses () as client_mock :
44+ client_mock .get (
45+ TEST_URL_CONFIG ,
46+ status = 401 ,
47+ )
48+
49+ yield client_mock
4450
4551
4652@pytest .fixture (name = "test_charger" )
@@ -56,87 +62,114 @@ def test_charger_v2(status_mock_v2, config_mock_v2):
5662
5763
5864@pytest .fixture (name = "status_mock" )
59- def mock_status (requests_mock ):
65+ def mock_status ():
6066 """Mock the status reply."""
61- requests_mock .get (
62- TEST_URL_STATUS ,
63- text = load_fixture ("v4_json/status.json" ),
64- )
67+ with aioresponses () as client_mock :
68+ client_mock .get (
69+ TEST_URL_STATUS ,
70+ status = 200 ,
71+ body = load_fixture ("v4_json/status.json" ),
72+ )
73+
74+ yield client_mock
6575
6676
6777@pytest .fixture (name = "config_mock" )
68- def mock_config (requests_mock ):
78+ def mock_config ():
6979 """Mock the config reply."""
70- requests_mock .get (
71- TEST_URL_CONFIG ,
72- text = load_fixture ("v4_json/config.json" ),
73- )
80+ with aioresponses () as client_mock :
81+ client_mock .get (
82+ TEST_URL_CONFIG ,
83+ status = 200 ,
84+ body = load_fixture ("v4_json/config.json" ),
85+ )
86+
87+ yield client_mock
7488
7589
7690@pytest .fixture (name = "status_mock_v2" )
77- def mock_status_v2 (requests_mock ):
91+ def mock_status_v2 ():
7892 """Mock the status reply."""
79- requests_mock .get (
80- TEST_URL_STATUS ,
81- text = load_fixture ("v2_json/status.json" ),
82- )
93+ with aioresponses () as client_mock :
94+ client_mock .get (
95+ TEST_URL_STATUS ,
96+ status = 200 ,
97+ body = load_fixture ("v2_json/status.json" ),
98+ )
99+ yield client_mock
83100
84101
85102@pytest .fixture (name = "config_mock_v2" )
86- def mock_config_v2 (requests_mock ):
103+ def mock_config_v2 ():
87104 """Mock the config reply."""
88- requests_mock .get (
89- TEST_URL_CONFIG ,
90- text = load_fixture ("v2_json/config.json" ),
91- )
105+ with aioresponses () as client_mock :
106+ client_mock .get (
107+ TEST_URL_CONFIG ,
108+ status = 200 ,
109+ body = load_fixture ("v2_json/config.json" ),
110+ )
111+ yield client_mock
92112
93113
94114@pytest .fixture (name = "send_command_mock" )
95- def mock_send_command (requests_mock ):
115+ def mock_send_command ():
96116 """Mock the command reply."""
97- value = {"cmd" : "OK" , "ret" : "$OK^20" }
98- requests_mock .post (
99- TEST_URL_RAPI ,
100- text = json .dumps (value ),
101- )
117+ with aioresponses () as client_mock :
118+ value = {"cmd" : "OK" , "ret" : "$OK^20" }
119+ client_mock .post (
120+ TEST_URL_RAPI ,
121+ status = 200 ,
122+ body = json .dumps (value ),
123+ )
124+ yield client_mock
102125
103126
104127@pytest .fixture (name = "send_command_parse_err" )
105- def mock_send_command_parse_err (requests_mock ):
128+ def mock_send_command_parse_err ():
106129 """Mock the command reply parse err."""
107- requests_mock .post (
108- TEST_URL_RAPI ,
109- status_code = 400 ,
110- )
130+ with aioresponses () as client_mock :
131+ client_mock .post (
132+ TEST_URL_RAPI ,
133+ status = 400 ,
134+ )
135+ yield client_mock
111136
112137
113138@pytest .fixture (name = "send_command_auth_err" )
114- def mock_send_command_auth_err (requests_mock ):
139+ def mock_send_command_auth_err ():
115140 """Mock the command reply auth err."""
116- requests_mock .post (
117- TEST_URL_RAPI ,
118- status_code = 401 ,
119- )
141+ with aioresponses () as client_mock :
142+ client_mock .post (
143+ TEST_URL_RAPI ,
144+ status = 401 ,
145+ )
146+ yield client_mock
120147
121148
122149@pytest .fixture (name = "send_command_mock_missing" )
123- def mock_send_command_missing (requests_mock ):
150+ def mock_send_command_missing ():
124151 """Mock the command reply."""
125- value = {"cmd" : "OK" , "what" : "$NK^21" }
126- requests_mock .post (
127- TEST_URL_RAPI ,
128- text = json .dumps (value ),
129- )
152+ with aioresponses () as client_mock :
153+ value = {"cmd" : "OK" , "what" : "$NK^21" }
154+ client_mock .post (
155+ TEST_URL_RAPI ,
156+ status = 200 ,
157+ body = json .dumps (value ),
158+ )
159+ yield client_mock
130160
131161
132162@pytest .fixture (name = "send_command_mock_failed" )
133- def mock_send_command_failed (requests_mock ):
163+ def mock_send_command_failed ():
134164 """Mock the command reply."""
135- value = {"cmd" : "OK" , "ret" : "$NK^21" }
136- requests_mock .post (
137- TEST_URL_RAPI ,
138- text = json .dumps (value ),
139- )
165+ with aioresponses () as client_mock :
166+ value = {"cmd" : "OK" , "ret" : "$NK^21" }
167+ client_mock .post (
168+ TEST_URL_RAPI ,
169+ status = 200 ,
170+ body = json .dumps (value ),
171+ )
172+ yield client_mock
140173
141174
142175@pytest .fixture
0 commit comments