@@ -1553,70 +1553,70 @@ def test_device_detail_api_change_config(self):
15531553
15541554 def test_multiple_vpn_templates_same_vpn (self ):
15551555 """
1556- Ensure that assigning multiple templates of type 'vpn' referencing the same VPN
1557- to a device's config does not create duplicate VpnClient objects .
1556+ Assigning multiple templates of type 'vpn' referencing the same VPN
1557+ to a device's config raises error .
15581558 """
15591559 org = self ._get_org ()
15601560 vpn = self ._create_vpn (organization = org )
15611561 # Create two templates of type 'vpn' referencing the same VPN
15621562 vpn_template1 = self ._create_template (
1563- type = ' vpn' , vpn = vpn , organization = org , name = ' VPN Client 1'
1563+ type = " vpn" , vpn = vpn , organization = org , name = " VPN Client 1"
15641564 )
15651565 vpn_template2 = self ._create_template (
1566- type = ' vpn' , vpn = vpn , organization = org , name = ' VPN Client 2'
1566+ type = " vpn" , vpn = vpn , organization = org , name = " VPN Client 2"
15671567 )
15681568 device = self ._create_device (organization = org )
15691569 config = self ._create_config (device = device )
1570- path = reverse (' config_api:device_detail' , args = [device .pk ])
1570+ path = reverse (" config_api:device_detail" , args = [device .pk ])
15711571 data = {
1572- ' name' : device .name ,
1573- ' organization' : str (org .id ),
1574- ' mac_address' : device .mac_address ,
1575- ' config' : {
1576- ' backend' : ' netjsonconfig.OpenWrt' ,
1577- ' context' : {' lan_ip' : ' 192.168.1.1' },
1578- ' config' : {' interfaces' : [{' name' : ' wlan0' , ' type' : ' wireless' }]},
1572+ " name" : device .name ,
1573+ " organization" : str (org .id ),
1574+ " mac_address" : device .mac_address ,
1575+ " config" : {
1576+ " backend" : " netjsonconfig.OpenWrt" ,
1577+ " context" : {" lan_ip" : " 192.168.1.1" },
1578+ " config" : {" interfaces" : [{" name" : " wlan0" , " type" : " wireless" }]},
15791579 },
15801580 }
15811581 expected_error_message = (
1582- ' You cannot select multiple VPN client templates related'
1583- ' to the same VPN server.\n '
1582+ " You cannot select multiple VPN client templates related"
1583+ " to the same VPN server.\n "
15841584 'The templates "VPN Client 1" and "VPN Client 2" are all '
15851585 'linked to the same VPN server: "test".'
15861586 )
15871587
1588- with self .subTest (' Add both templates at once' ):
1589- data [' config' ][ ' templates' ] = [str (vpn_template1 .pk ), str (vpn_template2 .pk )]
1590- response = self .client .put (path , data , content_type = ' application/json' )
1588+ with self .subTest (" Add both templates at once" ):
1589+ data [" config" ][ " templates" ] = [str (vpn_template1 .pk ), str (vpn_template2 .pk )]
1590+ response = self .client .put (path , data , content_type = " application/json" )
15911591 self .assertEqual (response .status_code , 400 )
15921592 self .assertEqual (
1593- str (response .data [' config' ][0 ]),
1593+ str (response .data [" config" ][0 ]),
15941594 expected_error_message ,
15951595 )
15961596 self .assertEqual (config .templates .count (), 0 )
15971597 self .assertEqual (config .vpnclient_set .count (), 0 )
15981598
1599- with self .subTest (' Add one template at a time' ):
1600- data [' config' ][ ' templates' ] = [str (vpn_template1 .pk )]
1601- response = self .client .put (path , data , content_type = ' application/json' )
1599+ with self .subTest (" Add one template at a time" ):
1600+ data [" config" ][ " templates" ] = [str (vpn_template1 .pk )]
1601+ response = self .client .put (path , data , content_type = " application/json" )
16021602 self .assertEqual (response .status_code , 200 )
16031603 self .assertEqual (config .templates .count (), 1 )
16041604 self .assertEqual (config .vpnclient_set .count (), 1 )
16051605
16061606 # Now add the second template
1607- data [' config' ][ ' templates' ] = [str (vpn_template1 .pk ), str (vpn_template2 .pk )]
1608- response = self .client .put (path , data , content_type = ' application/json' )
1607+ data [" config" ][ " templates" ] = [str (vpn_template1 .pk ), str (vpn_template2 .pk )]
1608+ response = self .client .put (path , data , content_type = " application/json" )
16091609 self .assertEqual (response .status_code , 400 )
16101610 self .assertEqual (
1611- str (response .data [' config' ][0 ]),
1611+ str (response .data [" config" ][0 ]),
16121612 expected_error_message ,
16131613 )
16141614 self .assertEqual (config .templates .filter (id = vpn_template1 .id ).count (), 1 )
16151615 self .assertEqual (config .vpnclient_set .count (), 1 )
16161616
1617- with self .subTest (' Change existing template with another' ):
1618- data [' config' ][ ' templates' ] = [str (vpn_template2 .pk )]
1619- response = self .client .put (path , data , content_type = ' application/json' )
1617+ with self .subTest (" Change existing template with another" ):
1618+ data [" config" ][ " templates" ] = [str (vpn_template2 .pk )]
1619+ response = self .client .put (path , data , content_type = " application/json" )
16201620 self .assertEqual (response .status_code , 200 )
16211621 self .assertEqual (config .templates .filter (id = vpn_template2 .id ).count (), 1 )
16221622 self .assertEqual (config .vpnclient_set .count (), 1 )
0 commit comments