<s> import json <EOL> import mock <EOL> from pyquery import PyQuery as pq <EOL> from olympia import amo <EOL> from olympia . amo . tests import TestCase <EOL> from olympia . amo . urlresolvers import reverse <EOL> from olympia . addons . models import Addon <EOL> from olympia . compat . indexers import AppCompatIndexer <EOL> from olympia . compat . models import CompatReport <EOL> incoming_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ [ '<STR_LIT>' , '<STR_LIT>' ] ] , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> class TestCompatReportModel ( TestCase ) : <EOL> def test_none ( self ) : <EOL> assert CompatReport . get_counts ( '<STR_LIT>' ) == { '<STR_LIT:success>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> def test_some ( self ) : <EOL> guid = '<STR_LIT>' <EOL> CompatReport . objects . create ( guid = guid , works_properly = True ) <EOL> CompatReport . objects . create ( guid = guid , works_properly = True ) <EOL> CompatReport . objects . create ( guid = guid , works_properly = False ) <EOL> CompatReport . objects . create ( guid = '<STR_LIT>' , works_properly = True ) <EOL> CompatReport . objects . create ( guid = '<STR_LIT>' , works_properly = False ) <EOL> assert CompatReport . get_counts ( guid ) == { '<STR_LIT:success>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:1> } <EOL> class TestIncoming ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestIncoming , self ) . setUp ( ) <EOL> self . url = reverse ( '<STR_LIT>' ) <EOL> self . data = dict ( incoming_data ) <EOL> self . json = json . dumps ( self . data ) <EOL> def test_success ( self ) : <EOL> count = CompatReport . objects . count ( ) <EOL> r = self . client . post ( self . url , self . json , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> assert r . status_code == <NUM_LIT> <EOL> assert CompatReport . objects . count ( ) == count + <NUM_LIT:1> <EOL> cr = CompatReport . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> assert cr . app_build == incoming_data [ '<STR_LIT>' ] <EOL> assert cr . app_guid == incoming_data [ '<STR_LIT>' ] <EOL> assert cr . works_properly == incoming_data [ '<STR_LIT>' ] <EOL> assert cr . comments == incoming_data [ '<STR_LIT>' ] <EOL> assert cr . client_ip == '<STR_LIT:127.0.0.1>' <EOL> vals = CompatReport . objects . filter ( id = cr . id ) . values ( '<STR_LIT>' ) <EOL> assert vals [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == ( <EOL> json . dumps ( incoming_data [ '<STR_LIT>' ] , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) ) ) <EOL> def test_bad_json ( self ) : <EOL> r = self . client . post ( self . url , '<STR_LIT>' , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> assert r . status_code == <NUM_LIT> <EOL> def test_bad_field ( self ) : <EOL> self . data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> js = json . dumps ( self . data ) <EOL> r = self . client . post ( self . url , js , content_type = '<STR_LIT:application/json>' ) <EOL> assert r . status_code == <NUM_LIT> <EOL> class TestReporter ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> super ( TestReporter , self ) . setUp ( ) <EOL> self . addon = Addon . objects . get ( pk = <NUM_LIT> ) <EOL> self . url = reverse ( '<STR_LIT>' ) + '<STR_LIT>' <EOL> def test_success ( self ) : <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> assert r . status_code == <NUM_LIT:200> <EOL> def test_redirect ( self ) : <EOL> CompatReport . objects . create ( guid = self . addon . guid , <EOL> app_guid = amo . FIREFOX . guid ) <EOL> expected = reverse ( '<STR_LIT>' , args = [ self . addon . guid ] ) <EOL> self . assert3xx ( <EOL> self . client . get ( self . url . format ( self . addon . id ) ) , expected ) <EOL> self . assert3xx ( <EOL> self . client . get ( self . url . format ( self . addon . slug ) ) , expected ) <EOL> self . assert3xx ( <EOL> self . client . get ( self . url . format ( self . addon . guid ) ) , expected ) <EOL> self . assert3xx ( <EOL> self . client . get ( self . url . format ( self . addon . guid [ : <NUM_LIT:5> ] ) ) , expected ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> lambda r , a : True ) <EOL> def test_unlisted_addon_redirect_for_authorized ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> self . test_redirect ( ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> lambda r , a : False ) <EOL> def test_unlisted_addon_no_redirect_for_unauthorized ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> CompatReport . objects . create ( guid = self . addon . guid , <EOL> app_guid = amo . FIREFOX . guid ) <EOL> assert self . client . get ( <EOL> self . url . format ( self . addon . id ) ) . status_code == <NUM_LIT:200> <EOL> assert self . client . get ( <EOL> self . url . format ( self . addon . slug ) ) . status_code == <NUM_LIT:200> <EOL> assert self . client . get ( <EOL> self . url . format ( self . addon . guid ) ) . status_code == <NUM_LIT:200> <EOL> assert self . client . get ( <EOL> self . url . format ( self . addon . guid [ : <NUM_LIT:5> ] ) ) . status_code == <NUM_LIT:200> <EOL> def test_unlisted_addons_listed_in_left_sidebar ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> assert self . addon in response . context [ '<STR_LIT>' ] <EOL> class TestReporterDetail ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> super ( TestReporterDetail , self ) . setUp ( ) <EOL> self . addon = Addon . objects . get ( id = <NUM_LIT> ) <EOL> self . url = reverse ( '<STR_LIT>' , args = [ self . addon . guid ] ) <EOL> self . reports = [ ] <EOL> def _generate ( self ) : <EOL> apps = [ <EOL> ( amo . FIREFOX . guid , '<STR_LIT>' , True ) , <EOL> ( amo . FIREFOX . guid , '<STR_LIT>' , True ) , <EOL> ( amo . FIREFOX . guid , '<STR_LIT>' , False ) , <EOL> ( amo . FIREFOX . guid , '<STR_LIT>' , False ) , <EOL> ( amo . THUNDERBIRD . guid , '<STR_LIT>' , True ) , <EOL> ( amo . THUNDERBIRD . guid , '<STR_LIT>' , False ) , <EOL> ( amo . THUNDERBIRD . guid , '<STR_LIT>' , False ) , <EOL> ( amo . SEAMONKEY . guid , '<STR_LIT>' , False ) , <EOL> ( amo . SEAMONKEY . guid , '<STR_LIT>' , False ) , <EOL> ( amo . SEAMONKEY . guid , '<STR_LIT>' , False ) , <EOL> ] <EOL> for app_guid , app_version , works_properly in apps : <EOL> report = CompatReport . objects . create ( guid = self . addon . guid , <EOL> app_guid = app_guid , <EOL> app_version = app_version , <EOL> works_properly = works_properly ) <EOL> self . reports . append ( report . pk ) <EOL> def check_table ( self , data = { } , good = <NUM_LIT:0> , bad = <NUM_LIT:0> , appver = None , report_pks = [ ] ) : <EOL> r = self . client . get ( self . url , data ) <EOL> assert r . status_code == <NUM_LIT:200> <EOL> assert sorted ( r . id for r in r . context [ '<STR_LIT>' ] . object_list ) == ( <EOL> sorted ( self . reports [ pk ] for pk in report_pks ) ) <EOL> doc = pq ( r . content ) <EOL> assert doc ( '<STR_LIT>' ) . length == good + bad <EOL> reports = doc ( '<STR_LIT>' ) <EOL> if good == <NUM_LIT:0> and bad == <NUM_LIT:0> : <EOL> assert reports . find ( '<STR_LIT>' ) . length == <NUM_LIT:0> <EOL> assert doc ( '<STR_LIT>' ) . length == <NUM_LIT:1> <EOL> else : <EOL> assert reports . find ( '<STR_LIT>' ) . text ( ) . split ( ) [ <NUM_LIT:0> ] == str ( good ) <EOL> assert reports . find ( '<STR_LIT>' ) . text ( ) . split ( ) [ <NUM_LIT:0> ] == str ( bad ) <EOL> option = doc ( '<STR_LIT>' ) <EOL> assert option . val ( ) == appver <EOL> return r <EOL> def test_appver_all ( self ) : <EOL> self . _generate ( ) <EOL> self . check_table ( <EOL> good = <NUM_LIT:3> , bad = <NUM_LIT:7> , appver = '<STR_LIT>' , <EOL> report_pks = [ idx for idx , val in enumerate ( self . reports ) ] ) <EOL> def test_firefox_single ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . FIREFOX . id , '<STR_LIT>' ) <EOL> self . check_table ( data = { '<STR_LIT>' : appver } , good = <NUM_LIT:0> , bad = <NUM_LIT:1> , appver = appver , <EOL> report_pks = [ <NUM_LIT:3> ] ) <EOL> def test_firefox_multiple ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . FIREFOX . id , '<STR_LIT>' ) <EOL> self . check_table ( data = { '<STR_LIT>' : appver } , good = <NUM_LIT:2> , bad = <NUM_LIT:1> , appver = appver , <EOL> report_pks = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_firefox_empty ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . FIREFOX . id , <EOL> amo . COMPAT [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> self . check_table ( data = { '<STR_LIT>' : appver } , good = <NUM_LIT:0> , bad = <NUM_LIT:0> , appver = appver , <EOL> report_pks = [ ] ) <EOL> def test_firefox_unknown ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . FIREFOX . id , '<STR_LIT>' ) <EOL> self . check_table ( <EOL> data = { '<STR_LIT>' : appver } , good = <NUM_LIT:3> , bad = <NUM_LIT:7> , <EOL> report_pks = [ idx for idx , val in enumerate ( self . reports ) ] ) <EOL> def test_thunderbird_multiple ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . THUNDERBIRD . id , '<STR_LIT>' ) <EOL> self . check_table ( data = { '<STR_LIT>' : appver } , good = <NUM_LIT:0> , bad = <NUM_LIT:2> , appver = appver , <EOL> report_pks = [ <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> def test_thunderbird_unknown ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . THUNDERBIRD . id , '<STR_LIT>' ) <EOL> self . check_table ( <EOL> data = { '<STR_LIT>' : appver } , good = <NUM_LIT:3> , bad = <NUM_LIT:7> , <EOL> report_pks = [ idx for idx , val in enumerate ( self . reports ) ] ) <EOL> def test_seamonkey_multiple ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . SEAMONKEY . id , '<STR_LIT>' ) <EOL> self . check_table ( data = { '<STR_LIT>' : appver } , good = <NUM_LIT:0> , bad = <NUM_LIT:3> , appver = appver , <EOL> report_pks = [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] ) <EOL> def test_seamonkey_unknown ( self ) : <EOL> self . _generate ( ) <EOL> appver = '<STR_LIT>' % ( amo . SEAMONKEY . id , '<STR_LIT>' ) <EOL> self . check_table ( <EOL> data = { '<STR_LIT>' : appver } , good = <NUM_LIT:3> , bad = <NUM_LIT:7> , <EOL> report_pks = [ idx for idx , val in enumerate ( self . reports ) ] ) <EOL> def test_app_unknown ( self ) : <EOL> app_guid = '<STR_LIT>' <EOL> report = CompatReport . objects . create ( <EOL> guid = self . addon . guid , app_guid = app_guid , app_version = '<STR_LIT>' , <EOL> works_properly = True ) <EOL> self . reports . append ( report . pk ) <EOL> r = self . check_table ( good = <NUM_LIT:1> , bad = <NUM_LIT:0> , appver = '<STR_LIT>' , report_pks = [ <NUM_LIT:0> ] ) <EOL> msg = '<STR_LIT>' % app_guid <EOL> assert msg in r . content , '<STR_LIT>' % msg <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> lambda r , a : True ) <EOL> def test_unlisted_addon_details_for_authorized ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> self . _generate ( ) <EOL> self . check_table ( <EOL> good = <NUM_LIT:3> , bad = <NUM_LIT:7> , appver = '<STR_LIT>' , <EOL> report_pks = [ idx for idx , val in enumerate ( self . reports ) ] ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> lambda r , a : False ) <EOL> def test_unlisted_addon_no_details_for_unauthorized ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> self . _generate ( ) <EOL> self . check_table ( <EOL> good = <NUM_LIT:0> , bad = <NUM_LIT:0> , appver = '<STR_LIT>' , <EOL> report_pks = [ ] ) <EOL> class TestAppCompatIndexer ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . indexer = AppCompatIndexer ( ) <EOL> def test_mapping ( self ) : <EOL> doc_name = self . indexer . get_doctype_name ( ) <EOL> assert doc_name <EOL> mapping_properties = self . indexer . get_mapping ( ) [ doc_name ] [ '<STR_LIT>' ] <EOL> assert '<STR_LIT>' not in mapping_properties <EOL> assert '<STR_LIT>' in mapping_properties <EOL> def test_no_extract ( self ) : <EOL> assert not hasattr ( self . indexer , '<STR_LIT>' ) </s>
