2626
2727from tests .common import MockConfigEntry
2828
29- MOCK_SETTINGS = {
30- "name" : "Test name" ,
31- "device" : {"mac" : "test-mac" , "hostname" : "test-host" , "type" : "SHSW-1" },
32- }
3329DISCOVERY_INFO = zeroconf .ZeroconfServiceInfo (
3430 host = "1.1.1.1" ,
3531 addresses = ["1.1.1.1" ],
4844 properties = {zeroconf .ATTR_PROPERTIES_ID : "shelly1pm-AABBCCDDEEFF" },
4945 type = "mock_type" ,
5046)
51- MOCK_CONFIG = {
52- "sys" : {
53- "device" : {"name" : "Test name" },
54- },
55- }
5647
5748
5849@pytest .mark .parametrize (
6253 (2 , "SNSW-002P16EU" ),
6354 ],
6455)
65- async def test_form (hass , mock_block_device , mock_rpc_device , gen , model ):
56+ async def test_form (hass , gen , model , mock_block_device , mock_rpc_device ):
6657 """Test we get the form."""
67- 6858 result = await hass .config_entries .flow .async_init (
6959 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
7060 )
@@ -99,7 +89,7 @@ async def test_form(hass, mock_block_device, mock_rpc_device, gen, model):
9989
10090
10191@pytest .mark .parametrize (
102- "test_data " ,
92+ "gen, model, user_input, username " ,
10393 [
10494 (
10595 1 ,
@@ -115,9 +105,10 @@ async def test_form(hass, mock_block_device, mock_rpc_device, gen, model):
115105 ),
116106 ],
117107)
118- async def test_form_auth (hass , test_data , mock_block_device , mock_rpc_device ):
108+ async def test_form_auth (
109+ hass , gen , model , user_input , username , mock_block_device , mock_rpc_device
110+ ):
119111 """Test manual configuration if auth is required."""
120- gen , model , user_input , username = test_data
121112 result = await hass .config_entries .flow .async_init (
122113 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
123114 )
@@ -162,11 +153,14 @@ async def test_form_auth(hass, test_data, mock_block_device, mock_rpc_device):
162153
163154
164155@pytest .mark .parametrize (
165- "error" , [(DeviceConnectionError , "cannot_connect" ), (ValueError , "unknown" )]
156+ "exc, base_error" ,
157+ [
158+ (DeviceConnectionError , "cannot_connect" ),
159+ (ValueError , "unknown" ),
160+ ],
166161)
167- async def test_form_errors_get_info (hass , error ):
162+ async def test_form_errors_get_info (hass , exc , base_error ):
168163 """Test we handle errors."""
169- exc , base_error = error
170164 result = await hass .config_entries .flow .async_init (
171165 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
172166 )
@@ -254,11 +248,14 @@ async def test_form_missing_model_key_zeroconf(
254248
255249
256250@pytest .mark .parametrize (
257- "error" , [(DeviceConnectionError , "cannot_connect" ), (ValueError , "unknown" )]
251+ "exc, base_error" ,
252+ [
253+ (DeviceConnectionError , "cannot_connect" ),
254+ (ValueError , "unknown" ),
255+ ],
258256)
259- async def test_form_errors_test_connection (hass , error ):
257+ async def test_form_errors_test_connection (hass , exc , base_error ):
260258 """Test we handle errors."""
261- exc , base_error = error
262259 result = await hass .config_entries .flow .async_init (
263260 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
264261 )
@@ -364,16 +361,15 @@ async def test_form_firmware_unsupported(hass):
364361
365362
366363@pytest .mark .parametrize (
367- "error " ,
364+ "exc, base_error " ,
368365 [
369366 (InvalidAuthError , "invalid_auth" ),
370367 (DeviceConnectionError , "cannot_connect" ),
371368 (ValueError , "unknown" ),
372369 ],
373370)
374- async def test_form_auth_errors_test_connection_gen1 (hass , error ):
371+ async def test_form_auth_errors_test_connection_gen1 (hass , exc , base_error ):
375372 """Test we handle errors in Gen1 authenticated devices."""
376- exc , base_error = error
377373 result = await hass .config_entries .flow .async_init (
378374 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
379375 )
@@ -400,16 +396,15 @@ async def test_form_auth_errors_test_connection_gen1(hass, error):
400396
401397
402398@pytest .mark .parametrize (
403- "error " ,
399+ "exc, base_error " ,
404400 [
405401 (DeviceConnectionError , "cannot_connect" ),
406402 (InvalidAuthError , "invalid_auth" ),
407403 (ValueError , "unknown" ),
408404 ],
409405)
410- async def test_form_auth_errors_test_connection_gen2 (hass , error ):
406+ async def test_form_auth_errors_test_connection_gen2 (hass , exc , base_error ):
411407 """Test we handle errors in Gen2 authenticated devices."""
412- exc , base_error = error
413408 result = await hass .config_entries .flow .async_init (
414409 DOMAIN , context = {"source" : config_entries .SOURCE_USER }
415410 )
@@ -714,15 +709,16 @@ async def test_zeroconf_require_auth(hass, mock_block_device):
714709
715710
716711@pytest .mark .parametrize (
717- "test_data " ,
712+ "gen, user_input " ,
718713 [
719714 (1 , {"username" : "test user" , "password" : "test1 password" }),
720715 (2 , {"password" : "test2 password" }),
721716 ],
722717)
723- async def test_reauth_successful (hass , test_data , mock_block_device , mock_rpc_device ):
718+ async def test_reauth_successful (
719+ hass , gen , user_input , mock_block_device , mock_rpc_device
720+ ):
724721 """Test starting a reauthentication flow."""
725- gen , user_input = test_data
726722 entry = MockConfigEntry (
727723 domain = "shelly" , unique_id = "test-mac" , data = {"host" : "0.0.0.0" , "gen" : gen }
728724 )
@@ -751,15 +747,14 @@ async def test_reauth_successful(hass, test_data, mock_block_device, mock_rpc_de
751747
752748
753749@pytest .mark .parametrize (
754- "test_data " ,
750+ "gen, user_input " ,
755751 [
756752 (1 , {"username" : "test user" , "password" : "test1 password" }),
757753 (2 , {"password" : "test2 password" }),
758754 ],
759755)
760- async def test_reauth_unsuccessful (hass , test_data ):
756+ async def test_reauth_unsuccessful (hass , gen , user_input ):
761757 """Test reauthentication flow failed."""
762- gen , user_input = test_data
763758 entry = MockConfigEntry (
764759 domain = "shelly" , unique_id = "test-mac" , data = {"host" : "0.0.0.0" , "gen" : gen }
765760 )
0 commit comments