Ticket #17737: django_trunk_patch.diff

File django_trunk_patch.diff, 4.7 KB (added by Maciej Wiśniowski, 13 years ago)

Tests and patch against current trunk

  • tests/regressiontests/staticfiles_tests/tests.py

     
    286286        super(TestCollectionDryRun, self).run_collectstatic(dry_run=True)
    287287
    288288
     289class TestCollectionFilesOverride(CollectionTestCase):
     290    """
     291    Test overriding duplicated files by ``collectstatic`` management command.
     292    Check for proper handling of apps order in INSTALLED_APPS even if file modification
     293    dates are in different order:
     294        'regressiontests.staticfiles_tests.apps.test',
     295        'regressiontests.staticfiles_tests.apps.no_label',
     296    """
     297    def setUp(self):
     298        self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt')
     299        # get modification and access times for no_label/static/file2.txt
     300        self.orig_mtime = os.path.getmtime(self.orig_path)
     301        self.orig_atime = os.path.getatime(self.orig_path)
     302
     303        # prepare duplicate of file2.txt from no_label app
     304        # this file will have modification time older than no_label/static/file2.txt
     305        # anyway it should be taken to STATIC_ROOT because 'test' app is before
     306        # 'no_label' app in INSTALLED_APPS
     307        self.testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
     308        with open(self.testfile_path, 'w+') as f:
     309            f.write('duplicate of file2.txt')
     310        os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
     311        super(TestCollectionFilesOverride, self).setUp()
     312
     313    def tearDown(self):
     314        testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt')
     315        if os.path.exists(testfile_path):
     316            os.unlink(testfile_path)
     317        # set back original modification time
     318        os.utime(self.orig_path, (self.orig_atime, self.orig_mtime))
     319
     320    def test_ordering_override(self):
     321        """ Test if collectstatic takes files in proper order - accorting to INSTALLED_APPS
     322        """
     323        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     324
     325        # run collectstatic again
     326        self.run_collectstatic()
     327
     328        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     329
     330        # and now change modification time of no_label/static/file2.txt
     331        # test app is first in INSTALLED_APPS so file2.txt should remain unmodified
     332        mtime = os.path.getmtime(self.testfile_path)
     333        atime = os.path.getatime(self.testfile_path)
     334        os.utime(self.orig_path, (mtime + 1, atime + 1))
     335
     336        # run collectstatic again
     337        self.run_collectstatic()
     338
     339        self.assertFileContains('file2.txt', 'duplicate of file2.txt')
     340
     341
    289342class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
    290343    """
    291344    Tests for #15035
     
    314367                                "does/not/exist.png",
    315368                                "/static/does/not/exist.png")
    316369        self.assertStaticRenders("test/file.txt",
    317                                  "/static/test/file.ea5bccaf16d5.txt")
     370                                 "/static/test/file.dad0999e4f8f.txt")
    318371        self.assertStaticRenders("cached/styles.css",
    319372                                 "/static/cached/styles.93b1147e8552.css")
    320373        self.assertStaticRenders("path/",
  • django/contrib/staticfiles/management/commands/collectstatic.py

     
    107107                    prefixed_path = os.path.join(storage.prefix, path)
    108108                else:
    109109                    prefixed_path = path
    110                 found_files[prefixed_path] = (storage, path)
    111                 handler(path, prefixed_path, storage)
    112110
     111                if prefixed_path not in found_files:
     112                    found_files[prefixed_path] = (storage, path)
     113                    handler(path, prefixed_path, storage)
     114
    113115        # Here we check if the storage backend has a post_process
    114116        # method and pass it the list of modified files.
    115117        if self.post_process and hasattr(self.storage, 'post_process'):
     
    207209            self.clear_dir(os.path.join(path, d))
    208210
    209211    def delete_file(self, path, prefixed_path, source_storage):
    210         # Checks if the target file should be deleted if it already exists
     212        """
     213        Checks if the target file should be deleted if it already exists
     214        """
    211215        if self.storage.exists(prefixed_path):
    212216            try:
    213217                # When was the target file modified last time?
Back to Top