@@ -1047,6 +1047,72 @@ def test_replace_record_references_batch__uniqueness(self):
10471047 self .assertEqual (count , 1 )
10481048
10491049
1050+ class TestEditView (UnitTestCase ):
1051+ @parametrize (
1052+ [
1053+ (True , True , True ),
1054+ (False , True , False ),
1055+ ]
1056+ )
1057+ def test_active_auto (self , initial_value , by_xmlid , by_view_id ):
1058+ cr = self .env .cr
1059+ xmlid = "base.view_view_form"
1060+ view_id = util .ref (cr , xmlid )
1061+
1062+ cr .execute ("UPDATE ir_ui_view SET active = %s WHERE id = %s" , [initial_value , view_id ])
1063+
1064+ # call by xmlid
1065+ with util .edit_view (cr , xmlid = xmlid , skip_if_not_noupdate = False , active = "auto" ):
1066+ pass
1067+
1068+ cr .execute ("SELECT active FROM ir_ui_view WHERE id = %s" , [view_id ])
1069+ self .assertEqual (cr .fetchone ()[0 ], by_xmlid )
1070+
1071+ # reset value
1072+ cr .execute ("UPDATE ir_ui_view SET active = %s WHERE id = %s" , [initial_value , view_id ])
1073+
1074+ # call by view_id
1075+ with util .edit_view (cr , view_id = view_id , active = "auto" ):
1076+ pass
1077+
1078+ cr .execute ("SELECT active FROM ir_ui_view WHERE id = %s" , [view_id ])
1079+ self .assertEqual (cr .fetchone ()[0 ], by_view_id )
1080+
1081+ @parametrize (
1082+ [
1083+ (True , True , True ),
1084+ (True , False , False ),
1085+ (True , None , True ),
1086+ (False , True , True ),
1087+ (False , False , False ),
1088+ (False , None , False ),
1089+ ]
1090+ )
1091+ def test_active_explicit (self , initial_value , value , expected_value ):
1092+ cr = self .env .cr
1093+ xmlid = "base.view_view_form"
1094+ view_id = util .ref (cr , xmlid )
1095+
1096+ cr .execute ("UPDATE ir_ui_view SET active = %s WHERE id = %s" , [initial_value , view_id ])
1097+
1098+ # call by xmlid
1099+ with util .edit_view (cr , xmlid = xmlid , skip_if_not_noupdate = False , active = value ):
1100+ pass
1101+
1102+ cr .execute ("SELECT active FROM ir_ui_view WHERE id = %s" , [view_id ])
1103+ self .assertEqual (cr .fetchone ()[0 ], expected_value )
1104+
1105+ # reset value
1106+ cr .execute ("UPDATE ir_ui_view SET active = %s WHERE id = %s" , [initial_value , view_id ])
1107+
1108+ # call by view_id
1109+ with util .edit_view (cr , view_id = view_id , active = value ):
1110+ pass
1111+
1112+ cr .execute ("SELECT active FROM ir_ui_view WHERE id = %s" , [view_id ])
1113+ self .assertEqual (cr .fetchone ()[0 ], expected_value )
1114+
1115+
10501116class TestMisc (UnitTestCase ):
10511117 @parametrize (
10521118 [
0 commit comments