11import unittest
22
33from netjsonconfig import OpenWrt
4+ from netjsonconfig .exceptions import ValidationError
45from netjsonconfig .utils import _TabsMixin
56
67
@@ -217,37 +218,28 @@ def test_render_rule_wrong(self):
217218 "in" : "eth0" ,
218219 "out" : "eth1" ,
219220 "src" : "wrong" ,
220- "dest" : "wrong " ,
221+ "dest" : "wrong1 " ,
221222 "tos" : 2 ,
222- "action" : "blackhole"
223+ "action" : "blackhole" ,
223224 }
224225 ]
225226 }
226227 o = OpenWrt (rule )
227- try :
228+ with self . assertRaisesRegex ( ValidationError , "'wrong' is not a 'cidr'" ) :
228229 o .validate ()
229- except ValidationError as e :
230- # check error message
231- pass
232- else :
233- self .fail ('ValidationError not raised' )
234- # fix 'src' and expect wrong 'dest' to fail
235- rule ['src' ] = '192.168.1.1/24'
230+ rule ['ip_rules' ][0 ]['src' ] = '192.168.1.0/24'
236231 o = OpenWrt (rule )
237- try :
232+ with self . assertRaisesRegexp ( ValidationError , "'wrong1' is not a 'cidr'" ) :
238233 o .validate ()
239- except ValidationError as e :
240- # check error message
241- pass
242- else :
243- self .fail ('ValidationError not raised' )
244234 # fix 'dest' and expect no ValidationError raised
245- rule ['src' ] = '192.168.1.1 /24'
235+ rule ['ip_rules' ][ 0 ][ 'dest' ] = '192.168.1.0 /24'
246236 o = OpenWrt (rule )
247237 o .validate ()
248238
249239 def test_parse_rules_zone (self ):
250- o = OpenWrt (native = """package network
240+ with self .assertRaisesRegexp (ValidationError , "'wrong' is not a 'cidr'" ):
241+ OpenWrt (
242+ native = """package network
251243
252244config rule 'rule1'
253245 option action 'blackhole'
@@ -256,14 +248,8 @@ def test_parse_rules_zone(self):
256248 option out 'eth1'
257249 option src 'wrong'
258250 option tos '2'
259- """ )
260- try :
261- o .validate ()
262- except ValidationError as e :
263- # check error message
264- pass
265- else :
266- self .fail ('ValidationError not raised' )
251+ """
252+ )
267253
268254 _switch_netjson = {
269255 "switch" : [
0 commit comments