def test_change_mutable_default():
 class MutableTester(XBlock, ):
  'Test class with mutable fields.'
  list_field = List()
 field_data_a = DictFieldData({})
 mutable_test_a = MutableTester(TestRuntime(services={'field-data': field_data_a}), scope_ids=Mock(spec=ScopeIds))
 field_data_b = DictFieldData({})
 mutable_test_b = MutableTester(TestRuntime(services={'field-data': field_data_b}), scope_ids=Mock(spec=ScopeIds))
 mutable_test_a.list_field
 mutable_test_a.save()
 with assert_raises(KeyError):
  field_data_a.get(mutable_test_a, 'list_field')
 mutable_test_a.list_field.append(1)
 mutable_test_a.save()
 assert_equals([1], field_data_a.get(mutable_test_a, 'list_field'))
 with assert_raises(KeyError):
  field_data_b.get(mutable_test_b, 'list_field')

def test_change_mutable_default ( ) : class MutableTester ( XBlock , ) : list_field = List ( ) field_data_a = DictFieldData ( { } ) mutable_test_a = MutableTester ( TestRuntime ( services = { 'field-data' : field_data_a } ) , scope_ids = Mock ( spec = ScopeIds ) ) field_data_b = DictFieldData ( { } ) mutable_test_b = MutableTester ( TestRuntime ( services = { 'field-data' : field_data_b } ) , scope_ids = Mock ( spec = ScopeIds ) ) mutable_test_a . list_field mutable_test_a . save ( ) with assert_raises ( KeyError ) : field_data_a . get ( mutable_test_a , 'list_field' ) mutable_test_a . list_field . append ( 1 ) mutable_test_a . save ( ) assert_equals ( [ 1 ] , field_data_a . get ( mutable_test_a , 'list_field' ) ) with assert_raises ( KeyError ) : field_data_b . get ( mutable_test_b , 'list_field' )
ensure that mutating the default value for a field causes the changes to be saved .