Ticket #17737: django_1.3.1_patch.diff

File django_1.3.1_patch.diff, 4.8 KB (added by Maciej Wiśniowski, 13 years ago)

Tests and patch against 1.3.1 tag

  • django/contrib/staticfiles/management/commands/collectstatic.py

     
    7676            if confirm != 'yes':
    7777                raise CommandError("Collecting static files cancelled.")
    7878
     79        processed_files = []
    7980        for finder in finders.get_finders():
    8081            for path, storage in finder.list(ignore_patterns):
    8182                # Prefix the relative path if the source storage contains it
     
    8384                    prefixed_path = os.path.join(storage.prefix, path)
    8485                else:
    8586                    prefixed_path = path
    86                 if symlink:
    87                     self.link_file(path, prefixed_path, storage, **options)
    88                 else:
    89                     self.copy_file(path, prefixed_path, storage, **options)
     87                if prefixed_path not in processed_files:
     88                    if symlink:
     89                        self.link_file(path, prefixed_path, storage, **options)
     90                    else:
     91                        self.copy_file(path, prefixed_path, storage, **options)
     92                    processed_files.append(prefixed_path)
    9093
    9194        actual_count = len(self.copied_files) + len(self.symlinked_files)
    9295        unmodified_count = len(self.unmodified_files)
     
    195198                try:
    196199                    os.makedirs(os.path.dirname(full_path))
    197200                except OSError:
    198                     pass
    199                 shutil.copy2(source_path, full_path)
    200             else:
    201                 source_file = source_storage.open(path)
    202                 self.storage.save(prefixed_path, source_file)
     201                    pass               
     202            source_file = source_storage.open(path)
     203            self.storage.save(prefixed_path, source_file)
    203204        if not prefixed_path in self.copied_files:
    204205            self.copied_files.append(prefixed_path)
  • tests/regressiontests/staticfiles_tests/tests.py

     
    245245        self.assertFileContains('test/CVS', 'should be ignored')
    246246
    247247
     248class TestCollectionFilesOverride(BuildStaticTestCase):
     249    """
     250    Test overriding duplicated files by ``collectstatic`` management command.
     251    Check for proper handling of apps order in INSTALLED_APPS even if file modification
     252    dates are in different order:
     253        'regressiontests.staticfiles_tests.apps.test',
     254        'regressiontests.staticfiles_tests.apps.no_label',
     255    """
     256    def setUp(self):
     257        self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt')
     258        # get modification and access times for no_label/static/file2.txt
     259        self.orig_mtime = os.path.getmtime(self.orig_path)
     260        self.orig_atime = os.path.getatime(self.orig_path)
     261
     262        # prepare duplicate of file2.txt from no_label app
     263        # this file will have modification time older than no_label/static/file2.txt
     264        # anyway it should be taken to STATIC_ROOT because 'test' app is before
     265        # 'no_label' app in INSTALLED_APPS
     266        self.testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
     267        f = open(self.testfile_path, 'w+')
     268        f.write('duplicate of file2.txt')
     269        f.close()
     270        os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
     271        super(TestCollectionFilesOverride, self).setUp()
     272
     273    def tearDown(self):
     274        testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
     275        if os.path.exists(testfile_path):
     276            os.unlink(testfile_path)
     277        # set back original modification time
     278        os.utime(self.orig_path, (self.orig_atime, self.orig_mtime))
     279
     280    def test_override(self):
     281        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     282
     283        # run collectstatic again
     284        self.run_collectstatic()
     285
     286        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     287
     288        # and now change modification time of no_label/static/file2.txt
     289        # test app is first in INSTALLED_APPS so file2.txt should remain unmodified
     290        mtime = os.path.getmtime(self.testfile_path)
     291        atime = os.path.getatime(self.testfile_path)
     292        os.utime(self.orig_path, (mtime + 1, atime + 1))
     293
     294        # run collectstatic again
     295        self.run_collectstatic()
     296
     297        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     298
     299
    248300class TestNoFilesCreated(object):
    249301
    250302    def test_no_files_created(self):
Back to Top