| 289 | class 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 | |