#NEWLINE# def test_update_non_editable_attributes( self ) : #NEWLINE# #INDENT# metadata = [ { #NEWLINE# #INDENT# 'name' : 'foo' , #NEWLINE# 'label' : 'foo' , #NEWLINE# 'type' : 'object' , #NEWLINE# 'fields' : [ { #NEWLINE# #INDENT# 'name' : 'foo_field_name' , #NEWLINE# 'label' : 'foo_field_name' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'availability_zones' , #NEWLINE# 'label' : 'availability_zones' , #NEWLINE# 'type' : 'array' , #NEWLINE# 'fields' : [ { #NEWLINE# #INDENT# 'name' : 'az_name' , #NEWLINE# 'label' : 'az_name' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'nova_computes' , #NEWLINE# 'type' : 'array' , #NEWLINE# 'fields' : [ { #NEWLINE# #INDENT# 'name' : 'vsphere_cluster' , #NEWLINE# 'label' : 'vsphere_cluster' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'target_node' , #NEWLINE# 'label' : 'target_node' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'vcenter_host' , #NEWLINE# 'label' : 'vcenter_host' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ] #NEWLINE# db_attributes_value = { #NEWLINE# #INDENT# 'availability_zones' : [ { #NEWLINE# #INDENT# 'az_name' : 'az_1' , #NEWLINE# 'vcenter_host' : '127.0.0.1' , #NEWLINE# 'nova_computes' : [ { #NEWLINE# #INDENT# 'vsphere_cluster' : 'Cluster1' , #NEWLINE# 'target_node' : { #NEWLINE# #INDENT# 'current' : { #NEWLINE# #INDENT# 'id' : 'node-1' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'foo' : { #NEWLINE# #INDENT# 'foo_field_name' : 'foo_field_value' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# instance = objects . VmwareAttributes . create ( { #NEWLINE# #INDENT# 'editable' : { #NEWLINE# #INDENT# 'metadata' : metadata , #NEWLINE# 'value' : db_attributes_value , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# new_attributes = deepcopy ( db_attributes_value ) #NEWLINE# new_attributes [ 'foo' ] = [ 'foo_field_name' ] #NEWLINE# msg = "Value type of 'foo_field_name' attribute couldn't be changed." #NEWLINE# with self . assertRaisesRegexp ( errors . InvalidData , msg ) : #NEWLINE# #INDENT# VmwareAttributesValidator . _validate_updated_attributes ( { #NEWLINE# #INDENT# 'editable' : { #NEWLINE# #INDENT# 'value' : new_attributes , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , instance ) #NEWLINE# #UNINDENT# new_attributes = deepcopy ( db_attributes_value ) #NEWLINE# new_attributes [ 'foo' ] [ 'foo_field_name' ] = 'new_foo_field_value' #NEWLINE# msg = "Value of 'foo_field_name' attribute couldn't be changed." #NEWLINE# with self . assertRaisesRegexp ( errors . InvalidData , msg ) : #NEWLINE# #INDENT# VmwareAttributesValidator . _validate_updated_attributes ( { #NEWLINE# #INDENT# 'editable' : { #NEWLINE# #INDENT# 'value' : new_attributes , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , instance ) #NEWLINE# #UNINDENT# new_attributes = deepcopy ( db_attributes_value ) #NEWLINE# new_attributes [ 'availability_zones' ] . append ( { #NEWLINE# #INDENT# 'az_name' : 'az_2' , #NEWLINE# 'vcenter_host' : '127.0.0.1' , #NEWLINE# 'nova_computes' : [ ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# msg = "Value of 'availability_zones' attribute couldn't be changed." #NEWLINE# with self . assertRaisesRegexp ( errors . InvalidData , msg ) : #NEWLINE# #INDENT# VmwareAttributesValidator . _validate_updated_attributes ( { #NEWLINE# #INDENT# 'editable' : { #NEWLINE# #INDENT# 'value' : new_attributes , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , instance ) #NEWLINE# #UNINDENT# new_attributes = deepcopy ( db_attributes_value ) #NEWLINE# new_attributes [ 'availability_zones' ] [ 0 ] [ 'nova_computes' ] [ 0 ] . update ( { #NEWLINE# #INDENT# 'target_node' : { #NEWLINE# #INDENT# 'current' : { #NEWLINE# #INDENT# 'id' : 'node-2' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# msg = "Value of 'target_node' attribute couldn't be changed." #NEWLINE# with self . assertRaisesRegexp ( errors . InvalidData , msg ) : #NEWLINE# #INDENT# VmwareAttributesValidator . _validate_updated_attributes ( { #NEWLINE# #INDENT# 'editable' : { #NEWLINE# #INDENT# 'value' : new_attributes , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , instance )