5
5
import openevsehttp
6
6
from tests .common import load_fixture
7
7
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
+
8
15
9
16
@pytest .fixture (name = "test_charger_auth" )
10
17
def test_charger_auth (status_mock , config_mock ):
11
18
"""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" )
15
20
16
21
17
22
@pytest .fixture (name = "test_charger_auth_err" )
18
23
def test_charger_auth_err (status_mock_err , config_mock_err ):
19
24
"""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" )
23
26
24
27
25
28
@pytest .fixture (name = "status_mock_err" )
26
29
def mock_status_err (requests_mock ):
27
30
"""Mock the status reply."""
28
31
requests_mock .get (
29
- "http://openevse.test.tld/status" ,
32
+ TEST_URL_STATUS ,
30
33
status_code = 401 ,
31
34
)
32
35
@@ -35,28 +38,28 @@ def mock_status_err(requests_mock):
35
38
def mock_config_err (requests_mock ):
36
39
"""Mock the config reply."""
37
40
requests_mock .get (
38
- "http://openevse.test.tld/config" ,
41
+ TEST_URL_CONFIG ,
39
42
status_code = 401 ,
40
43
)
41
44
42
45
43
46
@pytest .fixture (name = "test_charger" )
44
47
def test_charger (status_mock , config_mock ):
45
48
"""Load the charger data."""
46
- return openevsehttp .OpenEVSE ("openevse.test.tld" )
49
+ return openevsehttp .OpenEVSE (TEST_TLD )
47
50
48
51
49
52
@pytest .fixture (name = "test_charger_v2" )
50
53
def test_charger_v2 (status_mock_v2 , config_mock_v2 ):
51
54
"""Load the charger data."""
52
- return openevsehttp .OpenEVSE ("openevse.test.tld" )
55
+ return openevsehttp .OpenEVSE (TEST_TLD )
53
56
54
57
55
58
@pytest .fixture (name = "status_mock" )
56
59
def mock_status (requests_mock ):
57
60
"""Mock the status reply."""
58
61
requests_mock .get (
59
- "http://openevse.test.tld/status" ,
62
+ TEST_URL_STATUS ,
60
63
text = load_fixture ("v4_json/status.json" ),
61
64
)
62
65
@@ -65,7 +68,7 @@ def mock_status(requests_mock):
65
68
def mock_config (requests_mock ):
66
69
"""Mock the config reply."""
67
70
requests_mock .get (
68
- "http://openevse.test.tld/config" ,
71
+ TEST_URL_CONFIG ,
69
72
text = load_fixture ("v4_json/config.json" ),
70
73
)
71
74
@@ -74,7 +77,7 @@ def mock_config(requests_mock):
74
77
def mock_status_v2 (requests_mock ):
75
78
"""Mock the status reply."""
76
79
requests_mock .get (
77
- "http://openevse.test.tld/status" ,
80
+ TEST_URL_STATUS ,
78
81
text = load_fixture ("v2_json/status.json" ),
79
82
)
80
83
@@ -83,7 +86,7 @@ def mock_status_v2(requests_mock):
83
86
def mock_config_v2 (requests_mock ):
84
87
"""Mock the config reply."""
85
88
requests_mock .get (
86
- "http://openevse.test.tld/config" ,
89
+ TEST_URL_CONFIG ,
87
90
text = load_fixture ("v2_json/config.json" ),
88
91
)
89
92
@@ -93,7 +96,7 @@ def mock_send_command(requests_mock):
93
96
"""Mock the command reply."""
94
97
value = {"cmd" : "OK" , "ret" : "$OK^20" }
95
98
requests_mock .post (
96
- "http://openevse.test.tld/r" ,
99
+ TEST_URL_RAPI ,
97
100
text = json .dumps (value ),
98
101
)
99
102
@@ -102,7 +105,7 @@ def mock_send_command(requests_mock):
102
105
def mock_send_command_parse_err (requests_mock ):
103
106
"""Mock the command reply parse err."""
104
107
requests_mock .post (
105
- "http://openevse.test.tld/r" ,
108
+ TEST_URL_RAPI ,
106
109
status_code = 400 ,
107
110
)
108
111
@@ -111,7 +114,7 @@ def mock_send_command_parse_err(requests_mock):
111
114
def mock_send_command_auth_err (requests_mock ):
112
115
"""Mock the command reply auth err."""
113
116
requests_mock .post (
114
- "http://openevse.test.tld/r" ,
117
+ TEST_URL_RAPI ,
115
118
status_code = 401 ,
116
119
)
117
120
@@ -121,7 +124,7 @@ def mock_send_command_missing(requests_mock):
121
124
"""Mock the command reply."""
122
125
value = {"cmd" : "OK" , "what" : "$NK^21" }
123
126
requests_mock .post (
124
- "http://openevse.test.tld/r" ,
127
+ TEST_URL_RAPI ,
125
128
text = json .dumps (value ),
126
129
)
127
130
@@ -131,6 +134,21 @@ def mock_send_command_failed(requests_mock):
131
134
"""Mock the command reply."""
132
135
value = {"cmd" : "OK" , "ret" : "$NK^21" }
133
136
requests_mock .post (
134
- "http://openevse.test.tld/r" ,
137
+ TEST_URL_RAPI ,
135
138
text = json .dumps (value ),
136
139
)
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