Opened 13 years ago

Closed 13 years ago

#17462 closed Bug (fixed)

TestCollectionCachedStorage errors & failure on Windows

Reported by: Karen Tracey Owned by: Karen Tracey
Component: contrib.staticfiles Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm getting 10 errors running the staticfiles_tests on Windows. They're all related to the new CachedStaticFilesStorage backend, and in fact all the same error (collectstatic called by setUp is failing), here's one example:

======================================================================
ERROR: test_cache_invalidation (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\regressiontests\staticfiles_tests\tests.py", line 104, in setUp
    self.run_collectstatic()
  File "C:\Users\kmtracey\django\trunk\tests\regressiontests\staticfiles_tests\tests.py", line 115, in run_collectstatic
    ignore_patterns=['*.ignoreme'], **kwargs)
  File "C:\Users\kmtracey\django\trunk\django\core\management\__init__.py", line 146, in call_command
    return klass.execute(*args, **defaults)
  File "C:\Users\kmtracey\django\trunk\django\core\management\base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:\Users\kmtracey\django\trunk\django\core\management\base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "C:\Users\kmtracey\django\trunk\django\contrib\staticfiles\management\commands\collectstatic.py", line 131, in handle_noargs
    post_processed = self.storage.post_process(found_files, **options)
  File "C:\Users\kmtracey\django\trunk\django\contrib\staticfiles\storage.py", line 179, in post_process
    content = pattern.sub(converter, content)
  File "C:\Users\kmtracey\django\trunk\django\contrib\staticfiles\storage.py", line 142, in converter
    hashed_url = self.url(unquote(joined_result), force=True)
  File "C:\Users\kmtracey\django\trunk\django\contrib\staticfiles\storage.py", line 105, in url
    hashed_name = self.hashed_name(name)
  File "C:\Users\kmtracey\django\trunk\django\contrib\staticfiles\storage.py", line 74, in hashed_name
    (clean_name, self))
ValueError: The file 'img/window.png' could not be found with django.contrib.staticfiles.storage.CachedStaticFilesStorage object at 0x00000000039F83C8>.

This error can be fixed by splitting the file name passed to url_converter converter on os.sep instead of '/'.

However there is then still a failure:

test_cache_invalidation (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... FAIL
test_path_with_fragment (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_path_with_querystring (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_absolute (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_deep_relative (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_denorm (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_relative (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_return (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_simple_content (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok
test_template_tag_url (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage) ... ok

======================================================================
FAIL: test_cache_invalidation (regressiontests.staticfiles_tests.tests.TestCollectionCachedStorage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\kmtracey\django\trunk\tests\regressiontests\staticfiles_tests\tests.py", line 382, in test_cache_invali
dation
    self.assertEqual(self.cached_file_path(name), cached_name)
AssertionError: u'cached/styles.93b1147e8552.css' != u'cached\\styles.93b1147e8552.css'
- cached/styles.93b1147e8552.css
?       ^
+ cached\styles.93b1147e8552.css
?       ^


----------------------------------------------------------------------
Ran 10 tests in 4.152s

FAILED (failures=1)
Destroying test database for alias 'default' (':memory:')...
Destroying test database for alias 'other' (':memory:')...

This one is fixed by replacing backslashes with slashes in the hashed_name passed to cache.set in the url method of CachedFilesMixin. (This is consistent with what is done in the post_process method.)

I'm going to check these fixes in but am opening this ticket as well so as to have a record of why they were made, and to have something to re-open if the fixes turn out not to be quite right. Setting as a release blocker since it seems the new function doesn't yet work properly on Windows.

Change History (1)

comment:1 by Karen Tracey, 13 years ago

Resolution: fixed
Status: newclosed

In [17276]:

Fixed #17462: Adjusted staticfiles CachedFilesMixin code so its tests pass on Windows.

Note: See TracTickets for help on using tickets.
Back to Top