43
43
_LOGGER = logging .getLogger (__name__ )
44
44
45
45
46
+ @pytest .mark .parametrize ("config" , [{}])
46
47
async def test_entry_setup_and_unload (
47
48
hass : HomeAssistant ,
49
+ setup_lovelace_ui ,
48
50
mock_lock_config_entry ,
49
51
lock_code_manager_config_entry ,
50
52
):
@@ -202,13 +204,15 @@ async def test_reauth(hass: HomeAssistant, lock_code_manager_config_entry):
202
204
)
203
205
204
206
205
- async def test_resource_already_loaded (
207
+ @pytest .mark .parametrize ("config" , [{}])
208
+ async def test_resource_already_loaded_ui (
206
209
hass : HomeAssistant ,
210
+ setup_lovelace_ui ,
207
211
mock_lock_config_entry ,
208
212
caplog : pytest .LogCaptureFixture ,
209
213
monkeypatch : pytest .MonkeyPatch ,
210
214
):
211
- """Test when strategy resource is already loaded."""
215
+ """Test when strategy resource is already loaded in UI mode ."""
212
216
resources = hass .data [LL_DOMAIN ].get ("resources" )
213
217
assert resources
214
218
await resources .async_load ()
@@ -231,3 +235,61 @@ async def test_resource_already_loaded(
231
235
assert "already registered" in caplog .text
232
236
233
237
await hass .config_entries .async_unload (config_entry .entry_id )
238
+
239
+
240
+ @pytest .mark .parametrize (
241
+ "config" ,
242
+ [{"mode" : "yaml" , "resources" : [{"type" : "module" , "url" : STRATEGY_PATH }]}],
243
+ )
244
+ async def test_resource_already_loaded_yaml (
245
+ hass : HomeAssistant ,
246
+ setup_lovelace_ui ,
247
+ mock_lock_config_entry ,
248
+ monkeypatch : pytest .MonkeyPatch ,
249
+ caplog : pytest .LogCaptureFixture ,
250
+ ):
251
+ """Test when strategy resource is already loaded in YAML mode."""
252
+ monkeypatch .setattr (
253
+ "custom_components.lock_code_manager.helpers.INTEGRATIONS_CLASS_MAP" ,
254
+ {"test" : MockLCMLock },
255
+ )
256
+
257
+ config_entry = MockConfigEntry (
258
+ domain = DOMAIN , data = BASE_CONFIG , unique_id = "Mock Title"
259
+ )
260
+ config_entry .add_to_hass (hass )
261
+ await hass .config_entries .async_setup (config_entry .entry_id )
262
+ await hass .async_block_till_done ()
263
+
264
+ assert "already registered" in caplog .text
265
+
266
+ await hass .config_entries .async_unload (config_entry .entry_id )
267
+
268
+
269
+ @pytest .mark .parametrize (
270
+ "config" ,
271
+ [{"mode" : "yaml" , "resources" : [{"type" : "module" , "url" : "fake_module.js" }]}],
272
+ )
273
+ async def test_resource_not_loaded_yaml (
274
+ hass : HomeAssistant ,
275
+ setup_lovelace_ui ,
276
+ mock_lock_config_entry ,
277
+ monkeypatch : pytest .MonkeyPatch ,
278
+ caplog : pytest .LogCaptureFixture ,
279
+ ):
280
+ """Test when strategy resource is not loaded in YAML mode."""
281
+ monkeypatch .setattr (
282
+ "custom_components.lock_code_manager.helpers.INTEGRATIONS_CLASS_MAP" ,
283
+ {"test" : MockLCMLock },
284
+ )
285
+
286
+ config_entry = MockConfigEntry (
287
+ domain = DOMAIN , data = BASE_CONFIG , unique_id = "Mock Title"
288
+ )
289
+ config_entry .add_to_hass (hass )
290
+ await hass .config_entries .async_setup (config_entry .entry_id )
291
+ await hass .async_block_till_done ()
292
+
293
+ assert "module can't automatically be registered" in caplog .text
294
+
295
+ await hass .config_entries .async_unload (config_entry .entry_id )
0 commit comments