Skip to content

Commit 5432d29

Browse files
Use is/is not for same-enum identity comparisons (tests) (#171689)
1 parent 8098f4f commit 5432d29

98 files changed

Lines changed: 733 additions & 733 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/auth/mfa_modules/test_insecure_example.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,37 +102,37 @@ async def test_login(hass: HomeAssistant) -> None:
102102

103103
provider = hass.auth.auth_providers[0]
104104
result = await hass.auth.login_flow.async_init((provider.type, provider.id))
105-
assert result["type"] == data_entry_flow.FlowResultType.FORM
105+
assert result["type"] is data_entry_flow.FlowResultType.FORM
106106

107107
result = await hass.auth.login_flow.async_configure(
108108
result["flow_id"], {"username": "incorrect-user", "password": "test-pass"}
109109
)
110-
assert result["type"] == data_entry_flow.FlowResultType.FORM
110+
assert result["type"] is data_entry_flow.FlowResultType.FORM
111111
assert result["errors"]["base"] == "invalid_auth"
112112

113113
result = await hass.auth.login_flow.async_configure(
114114
result["flow_id"], {"username": "test-user", "password": "incorrect-pass"}
115115
)
116-
assert result["type"] == data_entry_flow.FlowResultType.FORM
116+
assert result["type"] is data_entry_flow.FlowResultType.FORM
117117
assert result["errors"]["base"] == "invalid_auth"
118118

119119
result = await hass.auth.login_flow.async_configure(
120120
result["flow_id"], {"username": "test-user", "password": "test-pass"}
121121
)
122-
assert result["type"] == data_entry_flow.FlowResultType.FORM
122+
assert result["type"] is data_entry_flow.FlowResultType.FORM
123123
assert result["step_id"] == "mfa"
124124
assert result["data_schema"].schema.get("pin") is str
125125

126126
result = await hass.auth.login_flow.async_configure(
127127
result["flow_id"], {"pin": "invalid-code"}
128128
)
129-
assert result["type"] == data_entry_flow.FlowResultType.FORM
129+
assert result["type"] is data_entry_flow.FlowResultType.FORM
130130
assert result["errors"]["base"] == "invalid_code"
131131

132132
result = await hass.auth.login_flow.async_configure(
133133
result["flow_id"], {"pin": "123456"}
134134
)
135-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
135+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
136136
assert result["data"].id == "mock-id"
137137

138138

@@ -149,9 +149,9 @@ async def test_setup_flow(hass: HomeAssistant) -> None:
149149
flow = await auth_module.async_setup_flow("new-user")
150150

151151
result = await flow.async_step_init()
152-
assert result["type"] == data_entry_flow.FlowResultType.FORM
152+
assert result["type"] is data_entry_flow.FlowResultType.FORM
153153

154154
result = await flow.async_step_init({"pin": "abcdefg"})
155-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
155+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
156156
assert auth_module._data[1]["user_id"] == "new-user"
157157
assert auth_module._data[1]["pin"] == "abcdefg"

tests/auth/mfa_modules/test_notify.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,25 @@ async def test_login_flow_validates_mfa(hass: HomeAssistant) -> None:
137137
provider = hass.auth.auth_providers[0]
138138

139139
result = await hass.auth.login_flow.async_init((provider.type, provider.id))
140-
assert result["type"] == data_entry_flow.FlowResultType.FORM
140+
assert result["type"] is data_entry_flow.FlowResultType.FORM
141141

142142
result = await hass.auth.login_flow.async_configure(
143143
result["flow_id"], {"username": "incorrect-user", "password": "test-pass"}
144144
)
145-
assert result["type"] == data_entry_flow.FlowResultType.FORM
145+
assert result["type"] is data_entry_flow.FlowResultType.FORM
146146
assert result["errors"]["base"] == "invalid_auth"
147147

148148
result = await hass.auth.login_flow.async_configure(
149149
result["flow_id"], {"username": "test-user", "password": "incorrect-pass"}
150150
)
151-
assert result["type"] == data_entry_flow.FlowResultType.FORM
151+
assert result["type"] is data_entry_flow.FlowResultType.FORM
152152
assert result["errors"]["base"] == "invalid_auth"
153153

154154
with patch("pyotp.HOTP.at", return_value=MOCK_CODE):
155155
result = await hass.auth.login_flow.async_configure(
156156
result["flow_id"], {"username": "test-user", "password": "test-pass"}
157157
)
158-
assert result["type"] == data_entry_flow.FlowResultType.FORM
158+
assert result["type"] is data_entry_flow.FlowResultType.FORM
159159
assert result["step_id"] == "mfa"
160160
assert result["data_schema"].schema.get("code") is str
161161

@@ -173,7 +173,7 @@ async def test_login_flow_validates_mfa(hass: HomeAssistant) -> None:
173173
result = await hass.auth.login_flow.async_configure(
174174
result["flow_id"], {"code": "invalid-code"}
175175
)
176-
assert result["type"] == data_entry_flow.FlowResultType.FORM
176+
assert result["type"] is data_entry_flow.FlowResultType.FORM
177177
assert result["step_id"] == "mfa"
178178
assert result["errors"]["base"] == "invalid_code"
179179

@@ -191,29 +191,29 @@ async def test_login_flow_validates_mfa(hass: HomeAssistant) -> None:
191191
result = await hass.auth.login_flow.async_configure(
192192
result["flow_id"], {"code": "invalid-code"}
193193
)
194-
assert result["type"] == data_entry_flow.FlowResultType.FORM
194+
assert result["type"] is data_entry_flow.FlowResultType.FORM
195195
assert result["step_id"] == "mfa"
196196
assert result["errors"]["base"] == "invalid_code"
197197

198198
# after the 3rd failure, flow abort
199199
result = await hass.auth.login_flow.async_configure(
200200
result["flow_id"], {"code": "invalid-code"}
201201
)
202-
assert result["type"] == data_entry_flow.FlowResultType.ABORT
202+
assert result["type"] is data_entry_flow.FlowResultType.ABORT
203203
assert result["reason"] == "too_many_retry"
204204

205205
# wait service call finished
206206
await hass.async_block_till_done()
207207

208208
# restart login
209209
result = await hass.auth.login_flow.async_init((provider.type, provider.id))
210-
assert result["type"] == data_entry_flow.FlowResultType.FORM
210+
assert result["type"] is data_entry_flow.FlowResultType.FORM
211211

212212
with patch("pyotp.HOTP.at", return_value=MOCK_CODE):
213213
result = await hass.auth.login_flow.async_configure(
214214
result["flow_id"], {"username": "test-user", "password": "test-pass"}
215215
)
216-
assert result["type"] == data_entry_flow.FlowResultType.FORM
216+
assert result["type"] is data_entry_flow.FlowResultType.FORM
217217
assert result["step_id"] == "mfa"
218218
assert result["data_schema"].schema.get("code") is str
219219

@@ -231,7 +231,7 @@ async def test_login_flow_validates_mfa(hass: HomeAssistant) -> None:
231231
result = await hass.auth.login_flow.async_configure(
232232
result["flow_id"], {"code": MOCK_CODE}
233233
)
234-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
234+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
235235
assert result["data"].id == "mock-id"
236236

237237

@@ -246,7 +246,7 @@ async def test_setup_user_notify_service(hass: HomeAssistant) -> None:
246246

247247
flow = await notify_auth_module.async_setup_flow("test-user")
248248
step = await flow.async_step_init()
249-
assert step["type"] == data_entry_flow.FlowResultType.FORM
249+
assert step["type"] is data_entry_flow.FlowResultType.FORM
250250
assert step["step_id"] == "init"
251251
schema = step["data_schema"]
252252
schema({"notify_service": "test2"})
@@ -277,7 +277,7 @@ async def test_setup_user_notify_service(hass: HomeAssistant) -> None:
277277

278278
with patch("pyotp.HOTP.at", return_value=MOCK_CODE):
279279
step = await flow.async_step_init({"notify_service": "test1"})
280-
assert step["type"] == data_entry_flow.FlowResultType.FORM
280+
assert step["type"] is data_entry_flow.FlowResultType.FORM
281281
assert step["step_id"] == "setup"
282282

283283
# wait service call finished
@@ -357,7 +357,7 @@ async def test_setup_user_no_notify_service(hass: HomeAssistant) -> None:
357357

358358
flow = await notify_auth_module.async_setup_flow("test-user")
359359
step = await flow.async_step_init()
360-
assert step["type"] == data_entry_flow.FlowResultType.ABORT
360+
assert step["type"] is data_entry_flow.FlowResultType.ABORT
361361
assert step["reason"] == "no_available_service"
362362

363363

@@ -394,13 +394,13 @@ async def test_not_raise_exception_when_service_not_exist(hass: HomeAssistant) -
394394
provider = hass.auth.auth_providers[0]
395395

396396
result = await hass.auth.login_flow.async_init((provider.type, provider.id))
397-
assert result["type"] == data_entry_flow.FlowResultType.FORM
397+
assert result["type"] is data_entry_flow.FlowResultType.FORM
398398

399399
with patch("pyotp.HOTP.at", return_value=MOCK_CODE):
400400
result = await hass.auth.login_flow.async_configure(
401401
result["flow_id"], {"username": "test-user", "password": "test-pass"}
402402
)
403-
assert result["type"] == data_entry_flow.FlowResultType.ABORT
403+
assert result["type"] is data_entry_flow.FlowResultType.ABORT
404404
assert result["reason"] == "unknown_error"
405405

406406
# wait service call finished

tests/auth/mfa_modules/test_totp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,40 @@ async def test_login_flow_validates_mfa(hass: HomeAssistant) -> None:
9595
provider = hass.auth.auth_providers[0]
9696

9797
result = await hass.auth.login_flow.async_init((provider.type, provider.id))
98-
assert result["type"] == data_entry_flow.FlowResultType.FORM
98+
assert result["type"] is data_entry_flow.FlowResultType.FORM
9999

100100
result = await hass.auth.login_flow.async_configure(
101101
result["flow_id"], {"username": "incorrect-user", "password": "test-pass"}
102102
)
103-
assert result["type"] == data_entry_flow.FlowResultType.FORM
103+
assert result["type"] is data_entry_flow.FlowResultType.FORM
104104
assert result["errors"]["base"] == "invalid_auth"
105105

106106
result = await hass.auth.login_flow.async_configure(
107107
result["flow_id"], {"username": "test-user", "password": "incorrect-pass"}
108108
)
109-
assert result["type"] == data_entry_flow.FlowResultType.FORM
109+
assert result["type"] is data_entry_flow.FlowResultType.FORM
110110
assert result["errors"]["base"] == "invalid_auth"
111111

112112
result = await hass.auth.login_flow.async_configure(
113113
result["flow_id"], {"username": "test-user", "password": "test-pass"}
114114
)
115-
assert result["type"] == data_entry_flow.FlowResultType.FORM
115+
assert result["type"] is data_entry_flow.FlowResultType.FORM
116116
assert result["step_id"] == "mfa"
117117
assert result["data_schema"].schema.get("code") is str
118118

119119
with patch("pyotp.TOTP.verify", return_value=False):
120120
result = await hass.auth.login_flow.async_configure(
121121
result["flow_id"], {"code": "invalid-code"}
122122
)
123-
assert result["type"] == data_entry_flow.FlowResultType.FORM
123+
assert result["type"] is data_entry_flow.FlowResultType.FORM
124124
assert result["step_id"] == "mfa"
125125
assert result["errors"]["base"] == "invalid_code"
126126

127127
with patch("pyotp.TOTP.verify", return_value=True):
128128
result = await hass.auth.login_flow.async_configure(
129129
result["flow_id"], {"code": MOCK_CODE}
130130
)
131-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
131+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
132132
assert result["data"].id == "mock-id"
133133

134134

tests/auth/providers/test_command_line.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ async def test_login_flow_validates(
139139
"""Test login flow."""
140140
flow = await provider.async_login_flow({})
141141
result = await flow.async_step_init()
142-
assert result["type"] == data_entry_flow.FlowResultType.FORM
142+
assert result["type"] is data_entry_flow.FlowResultType.FORM
143143

144144
result = await flow.async_step_init(
145145
{"username": "bad-user", "password": "bad-pass"}
146146
)
147-
assert result["type"] == data_entry_flow.FlowResultType.FORM
147+
assert result["type"] is data_entry_flow.FlowResultType.FORM
148148
assert result["errors"]["base"] == "invalid_auth"
149149

150150
result = await flow.async_step_init(
151151
{"username": "good-user", "password": "good-pass"}
152152
)
153-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
153+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
154154
assert result["data"]["username"] == "good-user"
155155

156156

@@ -160,5 +160,5 @@ async def test_strip_username(provider: command_line.CommandLineAuthProvider) ->
160160
result = await flow.async_step_init(
161161
{"username": "\t\ngood-user ", "password": "good-pass"}
162162
)
163-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
163+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
164164
assert result["data"]["username"] == "good-user"

tests/auth/providers/test_homeassistant.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,24 @@ async def test_login_flow_validates(data: hass_auth.Data, hass: HomeAssistant) -
161161
)
162162
flow = await provider.async_login_flow({})
163163
result = await flow.async_step_init()
164-
assert result["type"] == data_entry_flow.FlowResultType.FORM
164+
assert result["type"] is data_entry_flow.FlowResultType.FORM
165165

166166
result = await flow.async_step_init(
167167
{"username": "incorrect-user", "password": "test-pass"}
168168
)
169-
assert result["type"] == data_entry_flow.FlowResultType.FORM
169+
assert result["type"] is data_entry_flow.FlowResultType.FORM
170170
assert result["errors"]["base"] == "invalid_auth"
171171

172172
result = await flow.async_step_init(
173173
{"username": "TEST-user ", "password": "incorrect-pass"}
174174
)
175-
assert result["type"] == data_entry_flow.FlowResultType.FORM
175+
assert result["type"] is data_entry_flow.FlowResultType.FORM
176176
assert result["errors"]["base"] == "invalid_auth"
177177

178178
result = await flow.async_step_init(
179179
{"username": "test-USER", "password": "test-pass"}
180180
)
181-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
181+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
182182
assert result["data"]["username"] == "test-USER"
183183

184184

@@ -260,24 +260,24 @@ async def test_legacy_login_flow_validates(
260260
)
261261
flow = await provider.async_login_flow({})
262262
result = await flow.async_step_init()
263-
assert result["type"] == data_entry_flow.FlowResultType.FORM
263+
assert result["type"] is data_entry_flow.FlowResultType.FORM
264264

265265
result = await flow.async_step_init(
266266
{"username": "incorrect-user", "password": "test-pass"}
267267
)
268-
assert result["type"] == data_entry_flow.FlowResultType.FORM
268+
assert result["type"] is data_entry_flow.FlowResultType.FORM
269269
assert result["errors"]["base"] == "invalid_auth"
270270

271271
result = await flow.async_step_init(
272272
{"username": "test-user", "password": "incorrect-pass"}
273273
)
274-
assert result["type"] == data_entry_flow.FlowResultType.FORM
274+
assert result["type"] is data_entry_flow.FlowResultType.FORM
275275
assert result["errors"]["base"] == "invalid_auth"
276276

277277
result = await flow.async_step_init(
278278
{"username": "test-user", "password": "test-pass"}
279279
)
280-
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
280+
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
281281
assert result["data"]["username"] == "test-user"
282282

283283

0 commit comments

Comments
 (0)