mention the override type in the xml output (bug 692971)
This commit is contained in:
Родитель
89b88737d3
Коммит
7ae2bbca09
|
@ -61,6 +61,8 @@ class FrozenAddonAdmin(admin.ModelAdmin):
|
|||
|
||||
class CompatOverrideRangeInline(admin.TabularInline):
|
||||
model = models.CompatOverrideRange
|
||||
# Exclude type since firefox only supports blocking right now.
|
||||
exclude = ('type',)
|
||||
|
||||
|
||||
class CompatOverrideAdmin(admin.ModelAdmin):
|
||||
|
|
|
@ -1582,11 +1582,12 @@ class CompatOverride(amo.models.ModelBase):
|
|||
Range = collections.namedtuple('Range', 'type min max apps')
|
||||
AppRange = collections.namedtuple('AppRange', 'app min max')
|
||||
rv = []
|
||||
sort_key = lambda x: (x.min_version, x.max_version)
|
||||
sort_key = lambda x: (x.min_version, x.max_version, x.type)
|
||||
for key, compats in sorted_groupby(self.compat_ranges, key=sort_key):
|
||||
compats = list(compats)
|
||||
first = compats[0]
|
||||
item = Range(first.type, first.min_version, first.max_version, [])
|
||||
item = Range(first.override_type(), first.min_version,
|
||||
first.max_version, [])
|
||||
for compat in compats:
|
||||
app = AppRange(amo.APP_IDS[compat.app_id],
|
||||
compat.min_app_version, compat.max_app_version)
|
||||
|
@ -1614,6 +1615,10 @@ class CompatOverrideRange(amo.models.ModelBase):
|
|||
class Meta:
|
||||
db_table = 'compat_override_range'
|
||||
|
||||
def override_type(self):
|
||||
"""This is what Firefox wants to see in the XML output."""
|
||||
return {0: 'compatible', 1: 'incompatible'}[self.type]
|
||||
|
||||
|
||||
# webapps.models imports addons.models to get Addon, so we need to keep the
|
||||
# Webapp import down here.
|
||||
|
|
|
@ -1775,6 +1775,16 @@ class TestCompatOverride(amo.tests.TestCase):
|
|||
c = CompatOverride.objects.create(guid='b')
|
||||
assert c.is_hosted()
|
||||
|
||||
def test_override_type(self):
|
||||
one = CompatOverride.objects.get(guid='one')
|
||||
|
||||
# The default is incompatible.
|
||||
c = CompatOverrideRange.objects.create(compat=one, app_id=1)
|
||||
eq_(c.override_type(), 'incompatible')
|
||||
|
||||
c = CompatOverrideRange.objects.create(compat=one, app_id=1, type=0)
|
||||
eq_(c.override_type(), 'compatible')
|
||||
|
||||
def test_guid_match(self):
|
||||
# We hook up the add-on automatically if we see a matching guid.
|
||||
addon = Addon.objects.create(id=1, guid='oh yeah', type=1)
|
||||
|
@ -1801,7 +1811,7 @@ class TestCompatOverride(amo.tests.TestCase):
|
|||
|
||||
eq_(len(r), 1)
|
||||
compat_range = r[0]
|
||||
self.check(compat_range, type=1, min='*', max='*')
|
||||
self.check(compat_range, type='incompatible', min='*', max='*')
|
||||
|
||||
eq_(len(compat_range.apps), 1)
|
||||
self.check(compat_range.apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
|
@ -1816,21 +1826,52 @@ class TestCompatOverride(amo.tests.TestCase):
|
|||
|
||||
eq_(len(r), 2)
|
||||
|
||||
self.check(r[0], type=1, min='*', max='*')
|
||||
self.check(r[0], type='incompatible', min='*', max='*')
|
||||
eq_(len(r[0].apps), 1)
|
||||
self.check(r[0].apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
|
||||
self.check(r[1], type=1, min='1', max='2')
|
||||
self.check(r[1], type='incompatible', min='1', max='2')
|
||||
eq_(len(r[1].apps), 1)
|
||||
self.check(r[1].apps[0], app=amo.FIREFOX, min='3', max='3.*')
|
||||
|
||||
def test_collapsed_ranges_different_types(self):
|
||||
# If the override ranges have different types they should be separate
|
||||
# entries.
|
||||
c = CompatOverride.objects.get(guid='one')
|
||||
CompatOverrideRange.objects.create(compat=c, app_id=1, type=0,
|
||||
min_app_version='3',
|
||||
max_app_version='3.*')
|
||||
r = c.collapsed_ranges()
|
||||
|
||||
eq_(len(r), 2)
|
||||
|
||||
self.check(r[0], type='compatible', min='*', max='*')
|
||||
eq_(len(r[0].apps), 1)
|
||||
self.check(r[0].apps[0], app=amo.FIREFOX, min='3', max='3.*')
|
||||
|
||||
self.check(r[1], type='incompatible', min='*', max='*')
|
||||
eq_(len(r[1].apps), 1)
|
||||
self.check(r[1].apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
|
||||
def test_collapsed_ranges_multiple_apps(self):
|
||||
c = CompatOverride.objects.get(guid='two')
|
||||
r = c.collapsed_ranges()
|
||||
|
||||
eq_(len(r), 1)
|
||||
compat_range = r[0]
|
||||
self.check(compat_range, type=1, min='1', max='2')
|
||||
self.check(compat_range, type='incompatible', min='1', max='2')
|
||||
|
||||
eq_(len(compat_range.apps), 2)
|
||||
self.check(compat_range.apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
self.check(compat_range.apps[1], app=amo.FIREFOX, min='3', max='4')
|
||||
|
||||
def test_collapsed_ranges_multiple_apps(self):
|
||||
c = CompatOverride.objects.get(guid='two')
|
||||
r = c.collapsed_ranges()
|
||||
|
||||
eq_(len(r), 1)
|
||||
compat_range = r[0]
|
||||
self.check(compat_range, type='incompatible', min='1', max='2')
|
||||
|
||||
eq_(len(compat_range.apps), 2)
|
||||
self.check(compat_range.apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
|
@ -1843,12 +1884,12 @@ class TestCompatOverride(amo.tests.TestCase):
|
|||
r = c.collapsed_ranges()
|
||||
|
||||
eq_(len(r), 2)
|
||||
self.check(r[0], type=1, min='1', max='2')
|
||||
self.check(r[0], type='incompatible', min='1', max='2')
|
||||
|
||||
eq_(len(r[0].apps), 2)
|
||||
self.check(r[0].apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
self.check(r[0].apps[1], app=amo.FIREFOX, min='3', max='4')
|
||||
|
||||
self.check(r[1], type=1, min='5', max='6')
|
||||
self.check(r[1], type='incompatible', min='5', max='6')
|
||||
eq_(len(r[1].apps), 1)
|
||||
self.check(r[1].apps[0], app=amo.FIREFOX, min='*', max='*')
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<name>{{ c.name }}</name>
|
||||
<version_ranges>
|
||||
{% for vr in c.collapsed_ranges() %}
|
||||
<version_range>
|
||||
<version_range type="{{ vr.type }}">
|
||||
<min_version>{{ vr.min }}</min_version>
|
||||
<max_version>{{ vr.max }}</max_version>
|
||||
<compatible_applications>
|
||||
|
|
|
@ -693,6 +693,7 @@ class TestGuidSearch(TestCase):
|
|||
eq_(dom('addon_compatibility > name').text(), c.name)
|
||||
|
||||
cr = c.compat_ranges[0]
|
||||
eq_(dom('version_range')[0].attrib['type'], cr.override_type())
|
||||
eq_(dom('version_range > min_version').text(), cr.min_version)
|
||||
eq_(dom('version_range > max_version').text(), cr.max_version)
|
||||
eq_(dom('application name').text(), amo.FIREFOX.pretty)
|
||||
|
|
Загрузка…
Ссылка в новой задаче