#NEWLINE# def test_constraints( site ) : #NEWLINE# #INDENT# default = models . Attribute . objects . create ( resource_name = 'Network' , site = site , name = 'default' ) #NEWLINE# allow_empty = models . Attribute . objects . create ( resource_name = 'Network' , site = site , name = 'allow_empty' , constraints = { #NEWLINE# #INDENT# 'allow_empty' : True , #NEWLINE# #UNINDENT# } ) #NEWLINE# pattern = models . Attribute . objects . create ( resource_name = 'Network' , site = site , name = 'pattern' , constraints = { #NEWLINE# #INDENT# 'pattern' : '\\d\\d\\d+' , #NEWLINE# #UNINDENT# } ) #NEWLINE# valid = models . Attribute . objects . create ( resource_name = 'Network' , site = site , name = 'valid' , constraints = { #NEWLINE# #INDENT# 'valid_values' : [ 'foo' , 'bar' , 'baz' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# models . Attribute . objects . create ( resource_name = 'Network' , site = site , name = 'invalid' , constraints = [ 'foo' , 'bar' , 'baz' ] ) #NEWLINE# #UNINDENT# network = models . Network . objects . create ( site = site , cidr = '10.0.0.0/8' ) #NEWLINE# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'default' : '' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'allow_empty' : '' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'pattern' : '' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'pattern' : 'foo' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'pattern' : '10' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'pattern' : '100' , #NEWLINE# #UNINDENT# } ) #NEWLINE# network . set_attributes ( { #NEWLINE# #INDENT# 'pattern' : '1000000' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with pytest . raises ( exc . ValidationError ) : #NEWLINE# #INDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'valid' : 'hello' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# network . set_attributes ( { #NEWLINE# #INDENT# 'valid' : 'foo' , #NEWLINE# #UNINDENT# } )