summaryrefslogtreecommitdiff
path: root/tests/test_scss.py
diff options
context:
space:
mode:
authorRocky Meza <rocky@fusionbox.com>2014-10-01 03:30:15 -0600
committerRocky Meza <rocky@fusionbox.com>2014-10-01 20:24:45 -0600
commit03a3a10704ae4ad7d45d00da508ccaf62e2d0cc3 (patch)
tree3e46528ae30e2c60c0a4ab235fdf6f833ec10d89 /tests/test_scss.py
parent138310db10995ee33c4e114d0bcab77d8deb21a5 (diff)
downloaddjango-pyscss-double_create_assets.tar.gz
Fix #23, don't error if ASSETS_ROOT already existsdouble_create_assets
Diffstat (limited to 'tests/test_scss.py')
-rw-r--r--tests/test_scss.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_scss.py b/tests/test_scss.py
index 78cd46e..6864be1 100644
--- a/tests/test_scss.py
+++ b/tests/test_scss.py
@@ -1,9 +1,12 @@
import os
+import mock
+import tempfile
from django.test import TestCase
from django.test.utils import override_settings
from django.conf import settings
+from scss import config
from django_pyscss.scss import DjangoScss
from tests.utils import clean_css, CollectStaticTestCase
@@ -141,3 +144,28 @@ class AssetsTest(CompilerTestMixin, TestCase):
# pyScss puts a cachebuster query string on the end of the URLs, lets
# just check that it made the file that we expected.
self.assertIn('KUZdBAnPCdlG5qfocw9GYw.png', actual)
+
+ def test_mkdir_race_condition(self):
+ """
+ There is a race condition when different instances of DjangoScss are
+ instantiated in different threads.
+
+ See https://github.com/fusionbox/django-pyscss/issues/23
+
+ We simulate the race condition by mocking the return of os.path.exists.
+ """
+ old_assets_root = config.ASSETS_ROOT
+ try:
+ new_assets_root = tempfile.mkdtemp()
+ config.ASSETS_ROOT = new_assets_root
+
+ def return_false_once(*args, **kwargs):
+ patch.stop()
+ return False
+
+ patch = mock.patch('os.path.exists', new=return_false_once)
+ patch.start()
+ self.compiler.compile(scss_string=".test { color: red; }")
+ finally:
+ config.ASSETS_ROOT = old_assets_root
+ os.rmdir(new_assets_root)