Added safer mirror check (bug 692178)
- Guards against mirror path being None - Changes `is_public` to be a more explicit `is_mirrorable`, which is what the template is really asking.
This commit is contained in:
Родитель
d2432ab63c
Коммит
151f67d9d0
|
@ -78,11 +78,15 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase):
|
|||
else:
|
||||
return True
|
||||
|
||||
def is_public(self):
|
||||
return self.status == amo.STATUS_PUBLIC
|
||||
def is_mirrorable(self):
|
||||
if self.version.addon.is_premium():
|
||||
return False
|
||||
return self.status in amo.MIRROR_STATUSES
|
||||
|
||||
def has_been_copied(self):
|
||||
"""Checks if file has been copied to mirror"""
|
||||
if not self.mirror_file_path:
|
||||
return False
|
||||
return os.path.isfile(self.mirror_file_path)
|
||||
|
||||
def can_be_perf_tested(self):
|
||||
|
|
|
@ -271,6 +271,18 @@ class TestFile(amo.tests.TestCase, amo.tests.AMOPaths):
|
|||
f.version.addon.update(type=amo.ADDON_WEBAPP)
|
||||
eq_(f.can_be_perf_tested(), False)
|
||||
|
||||
def test_file_is_mirrorable(self):
|
||||
f = File.objects.get(pk=67442)
|
||||
eq_(f.is_mirrorable(), True)
|
||||
|
||||
f.update(status=amo.STATUS_DISABLED)
|
||||
eq_(f.is_mirrorable(), False)
|
||||
|
||||
def test_premium_addon_not_mirrorable(self):
|
||||
f = File.objects.get(pk=67442)
|
||||
f.version.addon.premium_type = amo.ADDON_PREMIUM
|
||||
eq_(f.is_mirrorable(), False)
|
||||
|
||||
|
||||
class TestParseXpi(amo.tests.TestCase):
|
||||
fixtures = ['base/apps']
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
</td>
|
||||
<td><a href="/admin/addons/hash/{{ addon.id }}/{{ file.id }}" title="{{ file.hash }}">Recalc Hash</a></td>
|
||||
<td>
|
||||
{% if file.is_public() %}
|
||||
{% if file.is_mirrorable() %}
|
||||
{{ "Copied" if file.has_been_copied() else "Not Copied" }}
|
||||
{% endif %}
|
||||
</td>
|
||||
|
|
Загрузка…
Ссылка в новой задаче