1919from amo .tests import (formset , initial , close_to_now , assert_required ,
2020 assert_no_validation_errors )
2121from amo .urlresolvers import reverse
22- from addons .models import Addon
22+ from addons .models import Addon , CompatOverride , CompatOverrideRange
2323from applications .models import AppVersion
2424from bandwagon .models import FeaturedCollection , MonthlyPick
2525from compat .cron import compatibility_report
@@ -1495,6 +1495,11 @@ def generate_reports(self, addon, good, bad, app, app_version):
14951495 for x in xrange (bad ):
14961496 CompatReport .objects .create (works_properly = False , ** defaults )
14971497
1498+ def get_pq (self , ** kw ):
1499+ r = self .client .get (self .url , kw )
1500+ eq_ (r .status_code , 200 )
1501+ return pq (r .content )('#compat-results' )
1502+
14981503 def test_defaults (self ):
14991504 r = self .client .get (self .url )
15001505 eq_ (r .status_code , 200 )
@@ -1532,6 +1537,8 @@ def check_row(self, tr, addon, good, bad, percentage, app, app_version):
15321537 eq_ (form .attr ('action' ), reverse ('admin:addons_compatoverride_add' ))
15331538 self .check_field (form , '_compat_ranges-TOTAL_FORMS' , '1' )
15341539 self .check_field (form , '_compat_ranges-INITIAL_FORMS' , '0' )
1540+ self .check_field (form , '_continue' , '1' )
1541+ self .check_field (form , '_confirm' , '1' )
15351542 self .check_field (form , 'addon' , str (addon .id ))
15361543 self .check_field (form , 'guid' , addon .guid )
15371544
@@ -1541,7 +1548,8 @@ def check_row(self, tr, addon, good, bad, percentage, app, app_version):
15411548 self .check_field (form , compat_field % 'app' , str (app .id ))
15421549 self .check_field (form , compat_field % 'min_app_version' ,
15431550 app_version + 'a1' )
1544- self .check_field (form , compat_field % 'max_app_version' , '*' )
1551+ self .check_field (form , compat_field % 'max_app_version' ,
1552+ app_version + '*' )
15451553
15461554 def check_field (self , form , name , val ):
15471555 eq_ (form .find ('input[name="%s"]' % name ).val (), val )
@@ -1552,23 +1560,28 @@ def test_firefox_hosted(self):
15521560 app_version = self .app_version )
15531561 self .update ()
15541562
1555- r = self .client .get (self .url )
1556- eq_ (r .status_code , 200 )
1557- table = pq (r .content )('#compat-results tbody' )
1558- tr = table .find ('tr[data-addonid=%s]' % addon .id )
1563+ tr = self .get_pq ().find ('tr[data-addonid=%s]' % addon .id )
15591564 self .check_row (tr , addon , good = 0 , bad = 11 , percentage = '100.0' ,
15601565 app = self .app , app_version = self .app_version )
15611566
1567+ # Add an override for this current app version.
1568+ compat = CompatOverride .objects .create (addon = addon , guid = addon .guid )
1569+ CompatOverrideRange .objects .create (compat = compat ,
1570+ app_id = amo .FIREFOX .id , min_app_version = self .app_version + 'a1' ,
1571+ max_app_version = self .app_version + '*' )
1572+
1573+ # Check that there is an override for this current app version.
1574+ tr = self .get_pq ().find ('tr[data-addonid=%s]' % addon .id )
1575+ eq_ (tr .find ('.overrides a' ).attr ('href' ),
1576+ reverse ('admin:addons_compatoverride_change' , args = [compat .id ]))
1577+
15621578 def test_self_hosted (self ):
15631579 addon = self .populate (guid = 'yyy' , status = amo .STATUS_LISTED )
15641580 self .generate_reports (addon , good = 2 , bad = 18 , app = self .app ,
15651581 app_version = self .app_version )
15661582 self .update ()
15671583
1568- r = self .client .get (self .url )
1569- eq_ (r .status_code , 200 )
1570- table = pq (r .content )('#compat-results tbody' )
1571- tr = table .find ('tr[data-addonid=%s]' % addon .id )
1584+ tr = self .get_pq ().find ('tr[data-addonid=%s]' % addon .id )
15721585 eq_ (tr .length , 1 )
15731586
15741587 eq_ (tr .find ('.maxver' ).text (), 'Self Hosted' )
@@ -1589,9 +1602,7 @@ def test_non_default_version(self):
15891602 app_version = app_version )
15901603 self .update ()
15911604
1592- r = self .client .get (self .url )
1593- eq_ (r .status_code , 200 )
1594- table = pq (r .content )('#compat-results tbody' )
1605+ table = self .get_pq ()
15951606 eq_ (table .find ('tr[data-addonid=%s]' % addon .id ).length , 0 )
15961607
15971608 r = self .client .get (self .url ,
@@ -1601,3 +1612,20 @@ def test_non_default_version(self):
16011612 tr = table .find ('tr[data-addonid=%s]' % addon .id )
16021613 self .check_row (tr , addon , good = 0 , bad = 11 , percentage = '100.0' ,
16031614 app = self .app , app_version = app_version )
1615+
1616+ def test_ratio (self ):
1617+ addon = self .populate (guid = 'aaa' )
1618+ self .generate_reports (addon , good = 11 , bad = 11 , app = self .app ,
1619+ app_version = self .app_version )
1620+ self .update ()
1621+
1622+ # Should not show up for > 80%.
1623+ eq_ (self .get_pq ().find ('tr[data-addonid=%s]' % addon .id ).length , 0 )
1624+
1625+ # Should not show up for > 50%.
1626+ tr = self .get_pq (ratio = .5 ).find ('tr[data-addonid=%s]' % addon .id )
1627+ eq_ (tr .length , 0 )
1628+
1629+ # Should show up for > 40%.
1630+ tr = self .get_pq (ratio = .4 ).find ('tr[data-addonid=%s]' % addon .id )
1631+ eq_ (tr .length , 1 )
0 commit comments