summaryrefslogtreecommitdiff
path: root/odoo/addons/test_assetsbundle
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-09-28 11:56:23 +0200
committerChristophe Simonis <chs@odoo.com>2017-09-28 11:56:23 +0200
commit89df681b458df5b2fd21b738409a90dd53e33c9a (patch)
treebc270b4b26ed3b604c4b181b0e1b96c9990be68d /odoo/addons/test_assetsbundle
parent8cbd29f696632d53e57cb5ef890ad27f149bd8a9 (diff)
parentda15615c45adbc65d0e9d0784bb0a93f926c801a (diff)
[MERGE] forward port branch saas-15 up to da15615c45a
Diffstat (limited to 'odoo/addons/test_assetsbundle')
-rw-r--r--odoo/addons/test_assetsbundle/tests/test_assetsbundle.py44
1 files changed, 32 insertions, 12 deletions
diff --git a/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py b/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py
index c8ed48a33b1..86c878b35e2 100644
--- a/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py
+++ b/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py
@@ -2,6 +2,8 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import Counter
+import datetime
+import errno
from os import utime
import time
@@ -12,6 +14,21 @@ from odoo.tests import HttpCase
from odoo.tests.common import TransactionCase
+def _touch(filepath, asset, t=None):
+ try:
+ utime(filepath, (t, t) if t else None)
+ except OSError as e:
+ if e.errno in [errno.EPERM, errno.EACCES, errno.EROFS]:
+ # Permission denied when touching the asset file, possibly read-only filesystem.
+ # We alter the asset last modified time to simulate a change in the file
+ now = datetime.datetime.now()
+ asset.last_modified = now
+ for sheet in asset.stylesheets:
+ sheet.last_modified = now
+ else:
+ raise
+
+
class TestJavascriptAssetsBundle(TransactionCase):
def setUp(self):
super(TestJavascriptAssetsBundle, self).setUp()
@@ -82,9 +99,9 @@ class TestJavascriptAssetsBundle(TransactionCase):
version0 = bundle0.version
path = get_resource_path('test_assetsbundle', 'static', 'src', 'js', 'test_jsfile1.js')
- utime(path, None) # touch
-
bundle1 = self._get_asset(self.jsbundle_xmlid)
+ _touch(path, bundle1)
+
bundle1.js()
last_modified1 = bundle1.last_modified
version1 = bundle1.version
@@ -210,9 +227,9 @@ class TestJavascriptAssetsBundle(TransactionCase):
version0 = bundle0.version
path = get_resource_path('test_assetsbundle', 'static', 'src', 'css', 'test_cssfile1.css')
- utime(path, None) # touch
-
bundle1 = self._get_asset(self.cssbundle_xmlid, env=self.env(context={'max_css_rules': 1}))
+ _touch(path, bundle1)
+
bundle1.css()
last_modified1 = bundle1.last_modified
version1 = bundle1.version
@@ -362,10 +379,12 @@ class TestAssetsBundleWithIRAMock(TransactionCase):
self.env['ir.attachment']._patch_method('unlink', unlink)
self.addCleanup(self.env['ir.attachment']._revert_method, 'unlink')
- def _bundle(self, should_create, should_unlink):
- self.counter.clear()
+ def _get_asset(self):
files, remains = self.env['ir.qweb']._get_asset_content(self.lessbundle_xmlid, {})
- asset = AssetsBundle(self.lessbundle_xmlid, files, remains, env=self.env)
+ return AssetsBundle(self.lessbundle_xmlid, files, remains, env=self.env)
+
+ def _bundle(self, asset, should_create, should_unlink):
+ self.counter.clear()
asset.to_html(debug='assets')
self.assertEquals(self.counter['create'], int(should_create))
self.assertEquals(self.counter['unlink'], int(should_unlink))
@@ -375,16 +394,17 @@ class TestAssetsBundleWithIRAMock(TransactionCase):
are correctly invalidated.
"""
# Compile for the first time
- self._bundle(True, False)
+ self._bundle(self._get_asset(), True, False)
# Compile a second time, without changes
- self._bundle(False, False)
+ self._bundle(self._get_asset(), False, False)
# Touch the file and compile a third time
path = get_resource_path('test_assetsbundle', 'static', 'src', 'less', 'test_lessfile1.less')
t = time.time() + 5
- utime(path, (t, t)) # touch
- self._bundle(True, True)
+ asset = self._get_asset()
+ _touch(path, asset, t=t)
+ self._bundle(asset, True, True)
# Because we are in the same transaction since the beginning of the test, the first asset
# created and the second one have the same write_date, but the file's last modified date
@@ -394,4 +414,4 @@ class TestAssetsBundleWithIRAMock(TransactionCase):
self.cr.execute("update ir_attachment set write_date=clock_timestamp() + interval '10 seconds' where id = (select max(id) from ir_attachment)")
# Compile a fourth time, without changes
- self._bundle(False, False)
+ self._bundle(self._get_asset(), False, False)