<s> import os <EOL> from django . utils import simplejson <EOL> from django . core . urlresolvers import reverse <EOL> from django . core import serializers <EOL> from django . test . client import Client <EOL> from django . utils import simplejson as json <EOL> from transifex . languages . models import Language <EOL> from transifex . resources . models import Resource , Translation , Template , SourceEntity <EOL> from transifex . txcommon . tests import base , utils <EOL> class CoreViewsTest ( base . BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_resource_details ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . client [ '<STR_LIT>' ] . get ( self . urls [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertTrue ( self . team . language . name . encode ( '<STR_LIT:utf-8>' ) in resp . content ) <EOL> def test_resource_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> slug = self . resource . slug <EOL> resp = self . client [ '<STR_LIT>' ] . post ( reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , self . resource . slug ] ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Resource . objects . filter ( slug = slug , <EOL> project__slug = self . project . slug ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_resource_actions ( self ) : <EOL> """<STR_LIT>""" <EOL> url = self . urls [ '<STR_LIT>' ] <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> url_lock = reverse ( '<STR_LIT>' , args = [ self . project . slug , self . resource . slug , self . language . code ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url_lock ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> def test_project_resources ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . client [ '<STR_LIT>' ] . get ( reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> for r in Resource . objects . filter ( project = self . project ) [ <NUM_LIT:0> : <NUM_LIT:4> ] : <EOL> self . assertTrue ( r . name in resp . content ) <EOL> def test_clone_language ( self ) : <EOL> url = reverse ( <EOL> '<STR_LIT>' , args = [ <EOL> self . project . slug , self . resource . slug , self . language_ar . code , <EOL> self . language . code <EOL> ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url , follow = True ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> [ i . string for i in Translation . objects . filter ( <EOL> source_entity__resource = self . resource , language = self . language_ar <EOL> ) ] , <EOL> [ i . string for i in Translation . objects . filter ( <EOL> source_entity__resource = self . resource , language = self . language <EOL> ) ] <EOL> ) <EOL> def test_push_translation ( self ) : <EOL> """<STR_LIT>""" <EOL> source_trans = Translation ( <EOL> source_entity = self . source_entity , <EOL> language = self . language , <EOL> string = "<STR_LIT>" , <EOL> resource = self . resource <EOL> ) <EOL> source_trans . save ( ) <EOL> trans_lang = '<STR_LIT>' <EOL> trans = "<STR_LIT:foo>" <EOL> new_trans = "<STR_LIT>" <EOL> resp = self . client [ '<STR_LIT>' ] . post ( reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , trans_lang ] ) , <EOL> json . dumps ( { '<STR_LIT>' : [ { '<STR_LIT:id>' : source_trans . id , '<STR_LIT>' : { '<STR_LIT>' : trans } } ] } ) , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( Translation . objects . filter ( source_entity__resource = self . resource , <EOL> language__code = trans_lang , string = trans ) . count ( ) , <NUM_LIT:1> ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , trans_lang ] ) , <EOL> json . dumps ( { '<STR_LIT>' : [ { '<STR_LIT:id>' : source_trans . id , <EOL> '<STR_LIT>' : { '<STR_LIT>' : new_trans } } ] } ) , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> translations = Translation . objects . filter ( source_entity__resource = self . resource , <EOL> language__code = trans_lang , string = new_trans ) <EOL> self . assertEqual ( translations . count ( ) , <NUM_LIT:1> ) <EOL> source_trans . delete ( ) <EOL> translations . delete ( ) <EOL> def test_delete_resource_translations ( self ) : <EOL> """<STR_LIT>""" <EOL> source_trans = Translation ( <EOL> source_entity = self . source_entity , language = self . language , <EOL> string = "<STR_LIT>" , resource = self . resource <EOL> ) <EOL> source_trans . save ( ) <EOL> trans_lang = '<STR_LIT>' <EOL> trans = "<STR_LIT:foo>" <EOL> resp = self . client [ '<STR_LIT>' ] . post ( reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , trans_lang ] ) , <EOL> json . dumps ( { '<STR_LIT>' : [ { '<STR_LIT:id>' : source_trans . id , <EOL> '<STR_LIT>' : { '<STR_LIT>' : trans } } ] } ) , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( Translation . objects . filter ( source_entity__resource = self . resource , <EOL> language__code = trans_lang , string = trans ) . count ( ) , <NUM_LIT:1> ) <EOL> delete_url = reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , self . resource . slug , self . language . code ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( delete_url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( delete_url , follow = True ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( Translation . objects . filter ( source_entity__resource = self . resource , <EOL> language = self . language ) . count ( ) , <NUM_LIT:0> ) <EOL> delete_url_el = reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , self . resource . slug , trans_lang ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( delete_url_el ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( delete_url_el , follow = True ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( Translation . objects . filter ( source_entity__resource = self . resource , <EOL> language__code = trans_lang ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_resource_edit ( self , file_handler = None , bad = False ) : <EOL> """<STR_LIT>""" <EOL> if file_handler : <EOL> fh = file_handler <EOL> else : <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> url = reverse ( '<STR_LIT>' , args = [ self . project . slug , self . resource . slug ] ) <EOL> DATA = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : fh , '<STR_LIT>' : '<STR_LIT>' , } <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url , DATA , follow = True ) <EOL> if file_handler : <EOL> return resp <EOL> else : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_get_pot_file ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_resource_edit ( ) <EOL> url = reverse ( '<STR_LIT>' , args = [ self . project . slug , self . resource . slug ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url , follow = True ) <EOL> self . assertContains ( resp , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> def test_get_translation_file ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_resource_edit ( ) <EOL> url = reverse ( '<STR_LIT>' , args = [ self . project . slug , self . resource . slug , self . language . code ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp [ '<STR_LIT>' ] ) <EOL> def test_lock_and_get_translation_file ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_resource_edit ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ self . project . slug , self . resource . slug , self . language . code ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> json = simplejson . loads ( resp . content ) <EOL> self . assertEqual ( json [ '<STR_LIT:status>' ] , '<STR_LIT:OK>' ) <EOL> self . assertEqual ( json [ '<STR_LIT>' ] , '<STR_LIT>' <EOL> % ( self . project . slug , self . resource . slug , self . language . code ) ) <EOL> def test_different_resource_formats ( self ) : <EOL> """<STR_LIT>""" <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> resp = self . test_resource_edit ( fh ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( SourceEntity . objects . filter ( resource = self . resource ) . count ( ) , <NUM_LIT> ) <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> resp = self . test_resource_edit ( fh ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( SourceEntity . objects . filter ( resource = self . resource ) . count ( ) , <NUM_LIT> ) <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> resp = self . test_resource_edit ( fh ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( SourceEntity . objects . filter ( resource = self . resource ) . count ( ) , <NUM_LIT:1> ) <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> resp = self . test_resource_edit ( fh ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> self . assertEqual ( SourceEntity . objects . filter ( resource = self . resource ) . count ( ) , <NUM_LIT:2> ) <EOL> fh = open ( '<STR_LIT>' % os . path . split ( __file__ ) [ <NUM_LIT:0> ] , ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> resp = self . test_resource_edit ( fh ) <EOL> self . assertContains ( resp , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . assertEqual ( SourceEntity . objects . filter ( resource = self . resource ) . count ( ) , <NUM_LIT:2> ) <EOL> self . resource . i18n_method = '<STR_LIT>' <EOL> self . resource . save ( ) <EOL> class ResourceAutofetchTests ( base . BaseTestCase ) : <EOL> def setUp ( self , * args , ** kwargs ) : <EOL> super ( ResourceAutofetchTests , self ) . setUp ( * args , ** kwargs ) <EOL> self . SFILE = "<STR_LIT>" <EOL> self . url_edit = reverse ( '<STR_LIT>' , args = [ self . project . slug , self . resource . slug ] ) <EOL> def test_save_form_url ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . client [ '<STR_LIT>' ] . post ( self . url_edit , { <EOL> '<STR_LIT>' : self . SFILE , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . resource . slug , '<STR_LIT:name>' : self . resource . name , } ) <EOL> self . assertEquals ( self . resource . url_info . source_file_url , self . SFILE ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( self . url_edit ) <EOL> self . assertContains ( resp , self . SFILE ) <EOL> def test_save_form_remove_url ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_save_form_url ( ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( self . url_edit , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : self . resource . slug , <EOL> '<STR_LIT:name>' : self . resource . name , } ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( self . url_edit ) <EOL> self . assertNotContains ( resp , self . SFILE ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( self . urls [ '<STR_LIT>' ] ) <EOL> self . assertNotContains ( resp , self . SFILE ) <EOL> def test_save_form_url_nourl ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . client [ '<STR_LIT>' ] . post ( self . url_edit , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : self . resource . slug , <EOL> '<STR_LIT:name>' : self . resource . name , } ) <EOL> self . assertContains ( resp , "<STR_LIT>" ) <EOL> class ReleasesViewsTest ( base . BaseTestCase ) : <EOL> def setUp ( self , * args , ** kwargs ) : <EOL> super ( ReleasesViewsTest , self ) . setUp ( * args , ** kwargs ) <EOL> self . release = self . project . releases . create ( slug = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> self . release . resources . add ( self . resource ) <EOL> def test_release_detail_page ( self ) : <EOL> resp = self . client [ '<STR_LIT>' ] . get ( self . urls [ '<STR_LIT>' ] ) <EOL> self . assertContains ( resp , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> self . assertContains ( resp , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> class ResourcesLookupsTests ( base . BaseTestCase ) : <EOL> def test_private_resources_ajax_lookup ( self ) : <EOL> """<STR_LIT>""" <EOL> public_project = "<STR_LIT>" <EOL> private_project = "<STR_LIT>" <EOL> self . assertTrue ( self . user [ '<STR_LIT>' ] not in self . project_private . maintainers . all ( ) ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { '<STR_LIT:q>' : '<STR_LIT:r>' , '<STR_LIT>' : '<STR_LIT>' , } ) <EOL> self . assertContains ( resp , public_project , status_code = <NUM_LIT:200> ) <EOL> self . assertNotContains ( resp , private_project , status_code = <NUM_LIT:200> ) <EOL> self . assertTrue ( self . user [ '<STR_LIT>' ] in self . project_private . maintainers . all ( ) ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { '<STR_LIT:q>' : '<STR_LIT:r>' , '<STR_LIT>' : '<STR_LIT>' , } ) <EOL> self . assertContains ( resp , public_project , status_code = <NUM_LIT:200> ) <EOL> self . assertContains ( resp , private_project , status_code = <NUM_LIT:200> ) <EOL> self . assertTrue ( self . user [ '<STR_LIT>' ] in self . team_private . members . all ( ) ) <EOL> self . assertFalse ( self . user [ '<STR_LIT>' ] in self . project_private . maintainers . all ( ) ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { '<STR_LIT:q>' : '<STR_LIT:r>' , '<STR_LIT>' : '<STR_LIT>' , } ) <EOL> self . assertContains ( resp , public_project , status_code = <NUM_LIT:200> ) <EOL> self . assertContains ( resp , private_project , status_code = <NUM_LIT:200> ) </s>
