@@ -115,7 +115,7 @@ def test_parse_defaults_2(self):
115115
116116 config defaults 'defaults'
117117
118- config rule 'rule_Allow_MLD '
118+ config rule 'Allow_MLD '
119119 option name 'Allow-MLD'
120120 option src 'wan'
121121 option src_ip 'fe80::/10'
@@ -161,7 +161,7 @@ def test_parse_rule_1(self):
161161
162162 config defaults 'defaults'
163163
164- config rule 'rule_Allow_DHCPv6 '
164+ config rule 'Allow_DHCPv6 '
165165 option name 'Allow-DHCPv6'
166166 option src 'wan'
167167 option src_ip 'fc00::/6'
@@ -204,7 +204,7 @@ def test_parse_rule_2(self):
204204
205205 config defaults 'defaults'
206206
207- config rule 'rule_Allow_Ping '
207+ config rule 'Allow_Ping '
208208 option name 'Allow-Ping'
209209 option src 'wan'
210210 option proto 'icmp'
@@ -244,7 +244,7 @@ def test_parse_rule_3(self):
244244
245245 config defaults 'defaults'
246246
247- config rule 'rule_Allow_Isolated_DHCP '
247+ config rule 'Allow_Isolated_DHCP '
248248 option name 'Allow-Isolated-DHCP'
249249 option src 'isolated'
250250 option proto 'udp'
@@ -284,7 +284,7 @@ def test_parse_rule_4(self):
284284
285285 config defaults 'defaults'
286286
287- config rule 'rule_Allow_Isolated_DHCP '
287+ config rule 'Allow_Isolated_DHCP '
288288 option name 'Allow-Isolated-DHCP'
289289 option src_ip '10.10.10.10'
290290 option src_mac 'fc:aa:14:18:12:98'
@@ -341,7 +341,7 @@ def test_parse_rule_5(self):
341341
342342 config defaults 'defaults'
343343
344- config rule 'rule_Allow_Isolated_DHCP '
344+ config rule 'Allow_Isolated_DHCP '
345345 option name 'Allow-Isolated-DHCP'
346346 option src_ip '10.10.10.10'
347347 option src_mac 'fc:aa:14:18:12:98'
@@ -399,7 +399,7 @@ def test_parse_rule_6(self):
399399
400400 config defaults 'defaults'
401401
402- config zone 'zone_lan '
402+ config zone 'lan '
403403 option name 'lan'
404404 option input 'ACCEPT'
405405 option output 'ACCEPT'
@@ -440,7 +440,7 @@ def test_parse_zone_1(self):
440440
441441 config defaults 'defaults'
442442
443- config zone 'zone_wan '
443+ config zone 'wan '
444444 option name 'wan'
445445 option input 'DROP'
446446 option output 'ACCEPT'
@@ -460,7 +460,7 @@ def test_parse_zone_1(self):
460460
461461 config defaults 'defaults'
462462
463- config zone 'zone_wan '
463+ config zone 'wan '
464464 option name 'wan'
465465 option input 'DROP'
466466 option output 'ACCEPT'
@@ -485,7 +485,9 @@ def test_parse_zone_3(self):
485485 self .assertEqual (o .config , self ._zone_2_netjson )
486486
487487 _forwarding_1_netjson = {
488- "firewall" : {"forwardings" : [{"src" : "isolated" , "dest" : "wan" }]}
488+ "firewall" : {
489+ "forwardings" : [{"name" : "isolated-wan" , "src" : "isolated" , "dest" : "wan" }]
490+ }
489491 }
490492
491493 _forwarding_1_uci = textwrap .dedent (
@@ -494,7 +496,8 @@ def test_parse_zone_3(self):
494496
495497 config defaults 'defaults'
496498
497- config forwarding 'forwarding_isolated_wan'
499+ config forwarding 'isolated_wan'
500+ option name 'isolated-wan'
498501 option src 'isolated'
499502 option dest 'wan'
500503 """
@@ -511,7 +514,14 @@ def test_parse_forwarding_1(self):
511514
512515 _forwarding_2_netjson = {
513516 "firewall" : {
514- "forwardings" : [{"src" : "isolated" , "dest" : "wan" , "family" : "ipv4" }]
517+ "forwardings" : [
518+ {
519+ "name" : "isolated-wan-ipv4" ,
520+ "src" : "isolated" ,
521+ "dest" : "wan" ,
522+ "family" : "ipv4" ,
523+ }
524+ ]
515525 }
516526 }
517527
@@ -521,7 +531,8 @@ def test_parse_forwarding_1(self):
521531
522532 config defaults 'defaults'
523533
524- config forwarding 'forwarding_isolated_wan_ipv4'
534+ config forwarding 'isolated_wan_ipv4'
535+ option name 'isolated-wan-ipv4'
525536 option src 'isolated'
526537 option dest 'wan'
527538 option family 'ipv4'
@@ -538,7 +549,11 @@ def test_parse_forwarding_2(self):
538549 self .assertEqual (o .config , self ._forwarding_2_netjson )
539550
540551 _forwarding_3_netjson = {
541- "firewall" : {"forwardings" : [{"src" : "lan" , "dest" : "wan" , "family" : "any" }]}
552+ "firewall" : {
553+ "forwardings" : [
554+ {"name" : "lan-wan-any" , "src" : "lan" , "dest" : "wan" , "family" : "any" }
555+ ]
556+ }
542557 }
543558
544559 _forwarding_3_uci = textwrap .dedent (
@@ -547,7 +562,8 @@ def test_parse_forwarding_2(self):
547562
548563 config defaults 'defaults'
549564
550- config forwarding 'forwarding_lan_wan_any'
565+ config forwarding 'lan_wan_any'
566+ option name 'lan-wan-any'
551567 option src 'lan'
552568 option dest 'wan'
553569 option family 'any'
@@ -563,6 +579,45 @@ def test_parse_forwarding_3(self):
563579 o = OpenWrt (native = self ._forwarding_3_uci )
564580 self .assertEqual (o .config , self ._forwarding_3_netjson )
565581
582+ _forwarding_4_netjson = {
583+ "firewall" : {
584+ "forwardings" : [
585+ {
586+ "name" : "forward_name" ,
587+ "src" : "lan" ,
588+ "dest" : "wan" ,
589+ "family" : "any" ,
590+ "enabled" : False ,
591+ }
592+ ]
593+ }
594+ }
595+
596+ _forwarding_4_uci = textwrap .dedent (
597+ """\
598+ package firewall
599+
600+ config defaults 'defaults'
601+
602+ config forwarding 'forward_name'
603+ option name 'forward_name'
604+ option src 'lan'
605+ option dest 'wan'
606+ option family 'any'
607+ option enabled '0'
608+ """
609+ )
610+
611+ def test_render_forwarding_4 (self ):
612+ o = OpenWrt (self ._forwarding_4_netjson )
613+ expected = self ._tabs (self ._forwarding_4_uci )
614+ self .assertEqual (o .render (), expected )
615+
616+ def test_parse_forwarding_4 (self ):
617+ o = OpenWrt (native = self ._forwarding_4_uci )
618+ print (o .config )
619+ self .assertEqual (o .config , self ._forwarding_4_netjson )
620+
566621 def test_forwarding_validation_error (self ):
567622 o = OpenWrt (
568623 {
@@ -595,7 +650,7 @@ def test_forwarding_validation_error(self):
595650
596651 config defaults 'defaults'
597652
598- config redirect 'redirect_Adblock DNS, port 53'
653+ config redirect 'Adblock DNS, port 53'
599654 option name 'Adblock DNS, port 53'
600655 option src 'lan'
601656 option proto 'tcpudp'
@@ -638,7 +693,7 @@ def test_parse_redirect_1(self):
638693
639694 config defaults 'defaults'
640695
641- config redirect 'redirect_Adblock DNS, port 53'
696+ config redirect 'Adblock DNS, port 53'
642697 option name 'Adblock DNS, port 53'
643698 option src 'lan'
644699 option proto 'tcpudp'
@@ -691,7 +746,7 @@ def test_redirect_monthdays_validation_error_2(self):
691746
692747 config defaults 'defaults'
693748
694- config redirect 'redirect_Adblock DNS, port 53'
749+ config redirect 'Adblock DNS, port 53'
695750 option name 'Adblock DNS, port 53'
696751 option src 'lan'
697752 option proto 'tcpudp'
@@ -757,7 +812,7 @@ def test_parse_redirect_3(self):
757812
758813 config defaults 'defaults'
759814
760- config redirect 'redirect_Adblock DNS, port 53'
815+ config redirect 'Adblock DNS, port 53'
761816 option name 'Adblock DNS, port 53'
762817 option src 'lan'
763818 option proto 'tcpudp'
0 commit comments