55import openevsehttp
66from tests .common import load_fixture
77
8+ from aioresponses import aioresponses
9+
10+ TEST_URL_STATUS = "http://openevse.test.tld/status"
11+ TEST_URL_CONFIG = "http://openevse.test.tld/config"
12+ TEST_URL_RAPI = "http://openevse.test.tld/r"
13+ TEST_TLD = "openevse.test.tld"
14+
815
916@pytest .fixture (name = "test_charger_auth" )
1017def test_charger_auth (status_mock , config_mock ):
1118 """Load the charger data."""
12- return openevsehttp .OpenEVSE (
13- "openevse.test.tld" , user = "testuser" , pwd = "fakepassword"
14- )
19+ return openevsehttp .OpenEVSE (TEST_TLD , user = "testuser" , pwd = "fakepassword" )
1520
1621
1722@pytest .fixture (name = "test_charger_auth_err" )
1823def test_charger_auth_err (status_mock_err , config_mock_err ):
1924 """Load the charger data."""
20- return openevsehttp .OpenEVSE (
21- "openevse.test.tld" , user = "testuser" , pwd = "fakepassword"
22- )
25+ return openevsehttp .OpenEVSE (TEST_TLD , user = "testuser" , pwd = "fakepassword" )
2326
2427
2528@pytest .fixture (name = "status_mock_err" )
2629def mock_status_err (requests_mock ):
2730 """Mock the status reply."""
2831 requests_mock .get (
29- "http://openevse.test.tld/status" ,
32+ TEST_URL_STATUS ,
3033 status_code = 401 ,
3134 )
3235
@@ -35,28 +38,28 @@ def mock_status_err(requests_mock):
3538def mock_config_err (requests_mock ):
3639 """Mock the config reply."""
3740 requests_mock .get (
38- "http://openevse.test.tld/config" ,
41+ TEST_URL_CONFIG ,
3942 status_code = 401 ,
4043 )
4144
4245
4346@pytest .fixture (name = "test_charger" )
4447def test_charger (status_mock , config_mock ):
4548 """Load the charger data."""
46- return openevsehttp .OpenEVSE ("openevse.test.tld" )
49+ return openevsehttp .OpenEVSE (TEST_TLD )
4750
4851
4952@pytest .fixture (name = "test_charger_v2" )
5053def test_charger_v2 (status_mock_v2 , config_mock_v2 ):
5154 """Load the charger data."""
52- return openevsehttp .OpenEVSE ("openevse.test.tld" )
55+ return openevsehttp .OpenEVSE (TEST_TLD )
5356
5457
5558@pytest .fixture (name = "status_mock" )
5659def mock_status (requests_mock ):
5760 """Mock the status reply."""
5861 requests_mock .get (
59- "http://openevse.test.tld/status" ,
62+ TEST_URL_STATUS ,
6063 text = load_fixture ("v4_json/status.json" ),
6164 )
6265
@@ -65,7 +68,7 @@ def mock_status(requests_mock):
6568def mock_config (requests_mock ):
6669 """Mock the config reply."""
6770 requests_mock .get (
68- "http://openevse.test.tld/config" ,
71+ TEST_URL_CONFIG ,
6972 text = load_fixture ("v4_json/config.json" ),
7073 )
7174
@@ -74,7 +77,7 @@ def mock_config(requests_mock):
7477def mock_status_v2 (requests_mock ):
7578 """Mock the status reply."""
7679 requests_mock .get (
77- "http://openevse.test.tld/status" ,
80+ TEST_URL_STATUS ,
7881 text = load_fixture ("v2_json/status.json" ),
7982 )
8083
@@ -83,7 +86,7 @@ def mock_status_v2(requests_mock):
8386def mock_config_v2 (requests_mock ):
8487 """Mock the config reply."""
8588 requests_mock .get (
86- "http://openevse.test.tld/config" ,
89+ TEST_URL_CONFIG ,
8790 text = load_fixture ("v2_json/config.json" ),
8891 )
8992
@@ -93,7 +96,7 @@ def mock_send_command(requests_mock):
9396 """Mock the command reply."""
9497 value = {"cmd" : "OK" , "ret" : "$OK^20" }
9598 requests_mock .post (
96- "http://openevse.test.tld/r" ,
99+ TEST_URL_RAPI ,
97100 text = json .dumps (value ),
98101 )
99102
@@ -102,7 +105,7 @@ def mock_send_command(requests_mock):
102105def mock_send_command_parse_err (requests_mock ):
103106 """Mock the command reply parse err."""
104107 requests_mock .post (
105- "http://openevse.test.tld/r" ,
108+ TEST_URL_RAPI ,
106109 status_code = 400 ,
107110 )
108111
@@ -111,7 +114,7 @@ def mock_send_command_parse_err(requests_mock):
111114def mock_send_command_auth_err (requests_mock ):
112115 """Mock the command reply auth err."""
113116 requests_mock .post (
114- "http://openevse.test.tld/r" ,
117+ TEST_URL_RAPI ,
115118 status_code = 401 ,
116119 )
117120
@@ -121,7 +124,7 @@ def mock_send_command_missing(requests_mock):
121124 """Mock the command reply."""
122125 value = {"cmd" : "OK" , "what" : "$NK^21" }
123126 requests_mock .post (
124- "http://openevse.test.tld/r" ,
127+ TEST_URL_RAPI ,
125128 text = json .dumps (value ),
126129 )
127130
@@ -131,6 +134,21 @@ def mock_send_command_failed(requests_mock):
131134 """Mock the command reply."""
132135 value = {"cmd" : "OK" , "ret" : "$NK^21" }
133136 requests_mock .post (
134- "http://openevse.test.tld/r" ,
137+ TEST_URL_RAPI ,
135138 text = json .dumps (value ),
136139 )
140+
141+
142+ @pytest .fixture
143+ def aioclient_mock ():
144+ """Fixture to mock aioclient calls."""
145+ with aioresponses () as mock_aiohttp :
146+ mock_headers = {"content-type" : "application/json" }
147+ mock_aiohttp .get (
148+ "ws://openevse.test.tld/ws" ,
149+ status = 200 ,
150+ headers = mock_headers ,
151+ body = {},
152+ )
153+
154+ yield mock_aiohttp
0 commit comments