summaryrefslogtreecommitdiff
path: root/odoo/addons/base/tests/test_ormcache.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2016-09-02 15:58:39 +0200
committerRaphael Collet <rco@openerp.com>2016-09-02 17:28:12 +0200
commit9e64f9f9514194d74e166b032add8511182f2677 (patch)
tree5086710c04c6b923be18a6d1d97b3f0f3a2a9c4a /odoo/addons/base/tests/test_ormcache.py
parent11812b0b9e82b2b1b9041d8250ce01e7b4a5f7ee (diff)
[REF] openerp: move `openerp` to `odoo`
Diffstat (limited to 'odoo/addons/base/tests/test_ormcache.py')
-rw-r--r--odoo/addons/base/tests/test_ormcache.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/odoo/addons/base/tests/test_ormcache.py b/odoo/addons/base/tests/test_ormcache.py
new file mode 100644
index 00000000000..3f281cb5582
--- /dev/null
+++ b/odoo/addons/base/tests/test_ormcache.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests.common import TransactionCase
+from odoo.tools import get_cache_key_counter
+
+
+class TestOrmcache(TransactionCase):
+ def test_ormcache(self):
+ """ Test the effectiveness of the ormcache() decorator. """
+ IMD = self.env['ir.model.data']
+ XMLID = 'base.group_no_one'
+
+ # retrieve the cache, its key and stat counter
+ cache, key, counter = get_cache_key_counter(IMD.xmlid_lookup, XMLID)
+ hit = counter.hit
+ miss = counter.miss
+
+ # clear the cache of ir.model.data.xmlid_lookup, retrieve its key and
+ IMD.xmlid_lookup.clear_cache(IMD)
+ self.assertNotIn(key, cache)
+
+ # lookup some reference
+ self.env.ref(XMLID)
+ self.assertEqual(counter.hit, hit)
+ self.assertEqual(counter.miss, miss + 1)
+ self.assertIn(key, cache)
+
+ # lookup again
+ self.env.ref(XMLID)
+ self.assertEqual(counter.hit, hit + 1)
+ self.assertEqual(counter.miss, miss + 1)
+ self.assertIn(key, cache)
+
+ # lookup again
+ self.env.ref(XMLID)
+ self.assertEqual(counter.hit, hit + 2)
+ self.assertEqual(counter.miss, miss + 1)
+ self.assertIn(key, cache)