Skip to content

Commit 40500e6

Browse files
committed
[IMP] base/tests
Don't rename the `noupdate` flag in tests, as this column is expected to be used by the upgrade functions. Part-of: #139 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 79f3d71 commit 40500e6

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/base/tests/test_util.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -815,28 +815,31 @@ def test_invert_boolean_field(self):
815815
with self.assertRaises(ValueError):
816816
util.invert_boolean_field(cr, "res.partner", "name", "nom")
817817

818+
model, old_name, new_name = "ir.model.access", "perm_unlink", "perm_delete"
819+
table = util.table_of_model(cr, model)
820+
818821
fltr = self.env["ir.filters"].create(
819-
{"name": "test", "model_id": "ir.model.data", "domain": "[('noupdate', '=', True)]"}
822+
{"name": "test", "model_id": model, "domain": str([(old_name, "=", True)])}
820823
)
821824

822825
query = """
823-
SELECT {0}, count(*)
824-
FROM ir_model_data
825-
GROUP BY {0}
826+
SELECT {1}, count(*)
827+
FROM {0}
828+
GROUP BY {1}
826829
"""
827830

828-
cr.execute(util.format_query(cr, query, "noupdate"))
831+
cr.execute(util.format_query(cr, query, table, old_name))
829832
initial_repartition = dict(cr.fetchall())
830833

831834
# util.parallel_execute will `commit` the cursor and create new ones
832835
# as we are in a test, we should not commit as we are in a subtransaction
833836
with mock.patch.object(cr, "commit", lambda: ...):
834-
util.invert_boolean_field(cr, "ir.model.data", "noupdate", "yesupdate")
837+
util.invert_boolean_field(cr, model, old_name, new_name)
835838

836839
util.invalidate(fltr)
837-
self.assertEqual(literal_eval(fltr.domain), ["!", ("yesupdate", "=", True)])
840+
self.assertEqual(literal_eval(fltr.domain), ["!", (new_name, "=", True)])
838841

839-
cr.execute(util.format_query(cr, query, "yesupdate"))
842+
cr.execute(util.format_query(cr, query, table, new_name))
840843
inverted_repartition = dict(cr.fetchall())
841844

842845
self.assertEqual(inverted_repartition[False], initial_repartition[True])
@@ -845,19 +848,19 @@ def test_invert_boolean_field(self):
845848

846849
# rename back
847850
with mock.patch.object(cr, "commit", lambda: ...):
848-
util.rename_field(cr, "ir.model.data", "yesupdate", "noupdate")
851+
util.rename_field(cr, model, new_name, old_name)
849852

850853
util.invalidate(fltr)
851-
self.assertEqual(literal_eval(fltr.domain), ["!", ("noupdate", "=", True)])
854+
self.assertEqual(literal_eval(fltr.domain), ["!", (old_name, "=", True)])
852855

853856
# invert with same name; will invert domains and data
854857
with mock.patch.object(cr, "commit", lambda: ...):
855-
util.invert_boolean_field(cr, "ir.model.data", "noupdate", "noupdate")
858+
util.invert_boolean_field(cr, model, old_name, old_name)
856859

857860
util.invalidate(fltr)
858-
self.assertEqual(literal_eval(fltr.domain), ["!", "!", ("noupdate", "=", True)])
861+
self.assertEqual(literal_eval(fltr.domain), ["!", "!", (old_name, "=", True)])
859862

860-
cr.execute(util.format_query(cr, query, "noupdate"))
863+
cr.execute(util.format_query(cr, query, table, old_name))
861864
back_repartition = dict(cr.fetchall())
862865

863866
# merge None into False in the initial repartition

0 commit comments

Comments
 (0)