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