Fix mirroring when disabling/enabling file (bug 726811)

This commit is contained in:
Kumar McMillan 2012-04-25 14:57:57 -05:00
Родитель 6f39486238
Коммит ce741d7bfd
2 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -325,6 +325,14 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase):
return
src, dst = self.guarded_file_path, self.file_path
self.mv(src, dst, 'Moving undisabled file: %s => %s')
# Put files back on the mirrors if necessary.
destinations = [self.version.path_prefix]
if self.status in amo.MIRROR_STATUSES:
destinations.append(self.version.mirror_path_prefix)
for dest in destinations:
dest = os.path.join(dest, nfd_str(self.filename))
log.info('Re-mirroring disabled/enabled file to %s' % dest)
copy_stored_file(self.file_path, dest)
def copy_to_mirror(self):
if not self.filename:

Просмотреть файл

@ -12,6 +12,7 @@ from xml.parsers import expat
import zipfile
from django import forms
from django.core.files.storage import default_storage as storage
from django.conf import settings
from django.utils.encoding import smart_str
@ -155,6 +156,28 @@ class TestFile(amo.tests.TestCase, amo.tests.AMOPaths):
f.save()
assert unhide_mock.called
def test_unhide_disabled_file_mirroring(self):
tmp = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp))
with mock.patch.object(settings, 'MIRROR_STAGE_PATH', tmp):
fo = File.objects.get(pk=67442)
with storage.open(fo.file_path, 'wb') as fp:
fp.write('<pretend this is an xpi>')
with storage.open(fo.mirror_file_path, 'wb') as fp:
fp.write('<pretend this is an xpi>')
fo.status = amo.STATUS_DISABLED
fo.save()
assert not os.path.exists(fo.file_path), 'file not hidden'
assert not os.path.exists(fo.mirror_file_path), (
'file not removed from mirror')
fo = File.objects.get(pk=67442)
fo.status = amo.STATUS_PUBLIC
fo.save()
assert os.path.exists(fo.file_path), 'file not un-hidden'
assert os.path.exists(fo.mirror_file_path), (
'file not copied back to mirror')
@mock.patch('files.models.File.copy_to_mirror')
def test_copy_to_mirror_on_status_change(self, copy_mock):