@ -13,6 +13,7 @@ class TestOnchangeHelper(common.TransactionCase):
self . Category = self . env [ " test_onchange_helper.category " ]
self . Category = self . env [ " test_onchange_helper.category " ]
self . Message = self . env [ " test_onchange_helper.message " ]
self . Message = self . env [ " test_onchange_helper.message " ]
self . Discussion = self . env [ " test_onchange_helper.discussion " ]
self . Discussion = self . env [ " test_onchange_helper.discussion " ]
self . maxDiff = None
@contextmanager
@contextmanager
def assertNoOrmWrite ( self , model ) :
def assertNoOrmWrite ( self , model ) :
@ -38,7 +39,7 @@ class TestOnchangeHelper(common.TransactionCase):
def test_play_onchanges_many2one_new_record ( self ) :
def test_play_onchanges_many2one_new_record ( self ) :
root = self . Category . create ( { " name " : " root " } )
root = self . Category . create ( { " name " : " root " } )
values = { " name " : " test " , " parent " : root . id , " root_categ " : False }
values = { " name " : " test " , " parent " : root . id }
self . env . invalidate_all ( )
self . env . invalidate_all ( )
with self . assertNoOrmWrite ( self . Category ) :
with self . assertNoOrmWrite ( self . Category ) :
@ -46,20 +47,10 @@ class TestOnchangeHelper(common.TransactionCase):
self . assertIn ( " root_categ " , result )
self . assertIn ( " root_categ " , result )
self . assertEqual ( result [ " root_categ " ] , root . id )
self . assertEqual ( result [ " root_categ " ] , root . id )
values . update ( result )
values [ " parent " ] = False
self . env . invalidate_all ( )
with self . assertNoOrmWrite ( self . Category ) :
result = self . Category . play_onchanges ( values , " parent " )
# since the root_categ is already False into values the field is not
# changed by the onchange
self . assertNotIn ( " root_categ " , result )
def test_play_onchanges_many2one_existing_record ( self ) :
def test_play_onchanges_many2one_existing_record ( self ) :
root = self . Category . create ( { " name " : " root " } )
root = self . Category . create ( { " name " : " root " } )
values = { " name " : " test " , " parent " : root . id , " root_categ " : False }
values = { " name " : " test " , " parent " : root . id }
self . env . invalidate_all ( )
self . env . invalidate_all ( )
with self . assertNoOrmWrite ( self . Category ) :
with self . assertNoOrmWrite ( self . Category ) :
@ -275,15 +266,13 @@ class TestOnchangeHelper(common.TransactionCase):
values = {
values = {
" name " : discussion . name ,
" name " : discussion . name ,
" moderator " : demo . id ,
" moderator " : demo . id ,
" categories " : [ ( 4 , cat . id ) for cat in discussion . categories ] ,
" messages " : [ ( 4 , msg . id ) for msg in discussion . messages ] ,
" participants " : [ ( 4 , usr . id ) for usr in discussion . participants ] ,
}
}
self . env . invalidate_all ( )
self . env . invalidate_all ( )
with self . assertNoOrmWrite ( discussion ) :
with self . assertNoOrmWrite ( discussion ) :
result = discussion . play_onchanges ( values , " moderator " )
result = discussion . play_onchanges ( values , " moderator " )
self . assertIn ( " participants " , result )
self . assertIn ( " participants " , result )
self . assertTrue ( discussion . participants )
self . assertItemsEqual (
self . assertItemsEqual (
result [ " participants " ] ,
result [ " participants " ] ,
[ ( 5 , ) ] + [ ( 4 , user . id ) for user in discussion . participants + demo ] ,
[ ( 5 , ) ] + [ ( 4 , user . id ) for user in discussion . participants + demo ] ,
@ -304,7 +293,6 @@ class TestOnchangeHelper(common.TransactionCase):
" categories " : [ ( 4 , cat . id ) for cat in discussion . categories ] ,
" categories " : [ ( 4 , cat . id ) for cat in discussion . categories ] ,
" messages " : messages ,
" messages " : messages ,
" participants " : [ ( 4 , usr . id ) for usr in discussion . participants ] ,
" participants " : [ ( 4 , usr . id ) for usr in discussion . participants ] ,
" message_concat " : False ,
}
}
with self . assertNoOrmWrite ( discussion ) :
with self . assertNoOrmWrite ( discussion ) :
result = discussion . play_onchanges ( values , " messages " )
result = discussion . play_onchanges ( values , " messages " )