<s> from urllib import urlencode <EOL> from pyquery import PyQuery as pq <EOL> from olympia import amo <EOL> from olympia . amo . urlresolvers import reverse <EOL> from olympia . devhub . models import RssKey <EOL> from olympia . devhub . tests . test_views import HubTest <EOL> from olympia . bandwagon . models import Collection <EOL> from olympia . reviews . models import Review <EOL> from olympia . tags . models import Tag <EOL> from olympia . versions . models import Version <EOL> class TestActivity ( HubTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestActivity , self ) . setUp ( ) <EOL> self . clone_addon ( <NUM_LIT:2> ) <EOL> amo . set_user ( self . user_profile ) <EOL> self . addon , self . addon2 = list ( self . user_profile . addons . all ( ) ) <EOL> def log_creates ( self , num , addon = None ) : <EOL> if not addon : <EOL> addon = self . addon <EOL> for i in xrange ( num ) : <EOL> amo . log ( amo . LOG . CREATE_ADDON , addon ) <EOL> def log_updates ( self , num , version_string = '<STR_LIT:1>' ) : <EOL> version = Version . objects . create ( version = version_string , <EOL> addon = self . addon ) <EOL> for i in xrange ( num ) : <EOL> amo . log ( amo . LOG . ADD_VERSION , self . addon , version ) <EOL> def log_status ( self , num ) : <EOL> for i in xrange ( num ) : <EOL> amo . log ( amo . LOG . USER_DISABLE , self . addon ) <EOL> def log_collection ( self , num , prefix = '<STR_LIT:foo>' ) : <EOL> for i in xrange ( num ) : <EOL> c = Collection . objects . create ( name = '<STR_LIT>' % ( prefix , i ) ) <EOL> amo . log ( amo . LOG . ADD_TO_COLLECTION , self . addon , c ) <EOL> def log_tag ( self , num , prefix = '<STR_LIT:foo>' ) : <EOL> for i in xrange ( num ) : <EOL> t = Tag . objects . create ( tag_text = '<STR_LIT>' % ( prefix , i ) ) <EOL> amo . log ( amo . LOG . ADD_TAG , self . addon , t ) <EOL> def log_review ( self , num ) : <EOL> r = Review ( addon = self . addon ) <EOL> for i in xrange ( num ) : <EOL> amo . log ( amo . LOG . ADD_REVIEW , self . addon , r ) <EOL> def get_response ( self , ** kwargs ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in kwargs : <EOL> url = reverse ( '<STR_LIT>' , args = ( kwargs [ '<STR_LIT>' ] , ) ) <EOL> if kwargs : <EOL> url += '<STR_LIT:?>' + urlencode ( kwargs ) <EOL> return self . client . get ( url , follow = True ) <EOL> def get_pq ( self , ** kwargs ) : <EOL> return pq ( self . get_response ( ** kwargs ) . content ) <EOL> def test_dashboard ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> doc = pq ( r . content ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:4> <EOL> assert doc ( '<STR_LIT>' ) . attr ( '<STR_LIT>' ) [ : - <NUM_LIT:32> ] == ( <EOL> reverse ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> def test_items ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:10> <EOL> def test_filter_persistence ( self ) : <EOL> doc = self . get_pq ( action = '<STR_LIT:status>' ) <EOL> assert '<STR_LIT>' in ( doc ( '<STR_LIT>' ) . eq ( <NUM_LIT:0> ) ( '<STR_LIT:a>' ) . eq ( <NUM_LIT:1> ) <EOL> . attr ( '<STR_LIT>' ) ) <EOL> def test_filter_updates ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> self . log_updates ( <NUM_LIT:10> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:20> <EOL> doc = self . get_pq ( action = '<STR_LIT>' ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:10> <EOL> def test_filter_status ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> self . log_status ( <NUM_LIT:5> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:15> <EOL> doc = self . get_pq ( action = '<STR_LIT:status>' ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:5> <EOL> def test_filter_collections ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> self . log_collection ( <NUM_LIT:3> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT> <EOL> doc = self . get_pq ( action = '<STR_LIT>' ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:3> <EOL> def test_filter_reviews ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> self . log_review ( <NUM_LIT:10> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:20> <EOL> doc = self . get_pq ( action = '<STR_LIT>' ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:10> <EOL> def test_pagination ( self ) : <EOL> self . log_review ( <NUM_LIT> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:20> <EOL> doc = self . get_pq ( page = <NUM_LIT:2> ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert doc ( '<STR_LIT>' ) <EOL> def test_no_pagination ( self ) : <EOL> doc = self . get_pq ( ) <EOL> assert not doc ( '<STR_LIT>' ) <EOL> def test_filter_addon ( self ) : <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> self . log_creates ( <NUM_LIT> , self . addon2 ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:20> <EOL> doc = self . get_pq ( addon = self . addon . id ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:10> <EOL> doc = self . get_pq ( addon = self . addon2 . id ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT> <EOL> def test_filter_addon_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> assert self . client . login ( username = '<STR_LIT>' , <EOL> password = '<STR_LIT:password>' ) <EOL> r = self . get_response ( addon = self . addon . id ) <EOL> assert r . status_code == <NUM_LIT:200> <EOL> def test_filter_addon_otherguy ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log_creates ( <NUM_LIT:10> ) <EOL> assert self . client . login ( username = '<STR_LIT>' , <EOL> password = '<STR_LIT:password>' ) <EOL> r = self . get_response ( addon = self . addon . id ) <EOL> assert r . status_code == <NUM_LIT> <EOL> def test_rss ( self ) : <EOL> self . log_creates ( <NUM_LIT:5> ) <EOL> r = self . get_response ( ) <EOL> key = RssKey . objects . get ( ) <EOL> r = self . get_response ( privaterss = key . key ) <EOL> assert r [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert '<STR_LIT>' in r . content <EOL> def test_rss_single ( self ) : <EOL> self . log_creates ( <NUM_LIT:5> ) <EOL> self . log_creates ( <NUM_LIT> , self . addon2 ) <EOL> r = self . get_response ( addon = self . addon . id ) <EOL> key = RssKey . objects . get ( ) <EOL> r = self . get_response ( privaterss = key . key ) <EOL> assert r [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert len ( pq ( r . content ) ( '<STR_LIT>' ) ) == <NUM_LIT:5> <EOL> assert '<STR_LIT>' % self . addon in r . content <EOL> def test_rss_unlisted_addon ( self ) : <EOL> """<STR_LIT>""" <EOL> self . addon . update ( is_listed = False ) <EOL> self . log_creates ( <NUM_LIT:5> ) <EOL> self . get_response ( addon = self . addon . id ) <EOL> key = RssKey . objects . get ( ) <EOL> response = self . get_response ( privaterss = key . key ) <EOL> assert len ( pq ( response . content ) ( '<STR_LIT>' ) ) == <NUM_LIT:5> <EOL> def test_logged_out ( self ) : <EOL> self . client . logout ( ) <EOL> r = self . get_response ( ) <EOL> assert r . redirect_chain [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> def test_xss_addon ( self ) : <EOL> self . addon . name = ( "<STR_LIT>" <EOL> '<STR_LIT>' ) <EOL> self . addon . save ( ) <EOL> self . log_creates ( <NUM_LIT:1> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ) , '<STR_LIT>' <EOL> def test_xss_unlisted_addon ( self ) : <EOL> self . addon . name = ( "<STR_LIT>" <EOL> '<STR_LIT>' ) <EOL> self . addon . is_listed = False <EOL> self . addon . save ( ) <EOL> self . log_creates ( <NUM_LIT:1> ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ) , '<STR_LIT>' <EOL> def test_xss_collections ( self ) : <EOL> self . log_collection ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ) , '<STR_LIT>' <EOL> def test_xss_collections_unlisted_addon ( self ) : <EOL> self . addon . update ( is_listed = False ) <EOL> self . log_collection ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ) , '<STR_LIT>' <EOL> def test_xss_tags ( self ) : <EOL> self . log_tag ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> def test_xss_tags_unlisted_addon ( self ) : <EOL> self . addon . update ( is_listed = False ) <EOL> self . log_tag ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:1> <EOL> assert '<STR_LIT>' not in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> def test_xss_versions ( self ) : <EOL> self . log_updates ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:2> <EOL> assert '<STR_LIT>' not in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> def test_xss_versions_unlisted_addon ( self ) : <EOL> self . addon . update ( is_listed = False ) <EOL> self . log_updates ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> doc = self . get_pq ( ) <EOL> assert len ( doc ( '<STR_LIT>' ) ) == <NUM_LIT:2> <EOL> assert '<STR_LIT>' not in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> assert '<STR_LIT>' in unicode ( doc ( '<STR_LIT>' ) ) , '<STR_LIT>' <EOL> def test_hidden ( self ) : <EOL> version = Version . objects . create ( addon = self . addon ) <EOL> amo . log ( amo . LOG . COMMENT_VERSION , self . addon , version ) <EOL> res = self . get_response ( addon = self . addon . id ) <EOL> key = RssKey . objects . get ( ) <EOL> res = self . get_response ( privaterss = key . key ) <EOL> assert "<STR_LIT>" not in res . content <EOL> def test_no_guid ( self ) : <EOL> self . log_creates ( <NUM_LIT:1> ) <EOL> self . get_response ( addon = self . addon . id ) <EOL> key = RssKey . objects . get ( ) <EOL> res = self . get_response ( privaterss = key . key ) <EOL> assert "<STR_LIT>" not in res . content </s>
