[FIX] test_performance: adapt new test to new api

This commit is contained in:
Christophe Simonis
2018-04-23 19:13:23 +02:00
parent e8bf128318
commit 7113b70762
@@ -75,20 +75,26 @@ class TestPerformance(TransactionCase):
'tag_ids': [(0, 0, {'name': val}) for val in range(10)],
})
@queryCount(admin=5, demo=5)
@users('admin', 'demo')
@warmup
def test_several_prefetch(self):
initial_records = self.env['test_performance.base'].search([])
self.assertEqual(len(initial_records), 5)
for i in range(8):
self.env.cr.execute('insert into test_performance_base(value) select value from test_performance_base')
for _i in range(8):
self.env.cr.execute(
'insert into test_performance_base(value) select value from test_performance_base'
)
records = self.env['test_performance.base'].search([])
self.assertEqual(len(records), 1280)
self.resetQueryCount()
# should only cause 2 queries thanks to prefetching
records.mapped('value')
records.invalidate_cache(['value'])
# should only cause 2 queries thanks to prefetching
with self.env.do_in_onchange():
with self.assertQueryCount(admin=2, demo=2):
records.mapped('value')
self.env.cr.execute('delete from test_performance_base where id not in %s', (tuple(initial_records.ids),))
records.invalidate_cache(['value'])
with self.assertQueryCount(admin=2, demo=2):
with self.env.do_in_onchange():
records.mapped('value')
self.env.cr.execute(
'delete from test_performance_base where id not in %s',
(tuple(initial_records.ids),)
)