<s> from django . db import IntegrityError <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils import simplejson as json <EOL> from transifex . txcommon . tests . base import BaseTestCase <EOL> class SuggestionsViewsTests ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SuggestionsViewsTests , self ) . setUp ( ) <EOL> self . entity = self . resource . entities [ <NUM_LIT:0> ] <EOL> self . URL_PREFIX = '<STR_LIT>' % ( self . entity . id , <EOL> self . language . code ) <EOL> def testAnonymousPagesStatusCode ( self ) : <EOL> pages = { <NUM_LIT> : [ ( self . URL_PREFIX + '<STR_LIT>' ) , ] , <EOL> <NUM_LIT> : [ ( self . URL_PREFIX + '<STR_LIT>' ) , ] } <EOL> self . assert_url_statuses ( pages , self . client [ "<STR_LIT>" ] ) <EOL> def _create_entity_suggestion ( self ) : <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ self . entity . id , self . language . code ] , ) <EOL> post_vars = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url , data = post_vars ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> suggestion = self . entity . suggestions . filter ( language = self . language ) . latest ( ) <EOL> return suggestion <EOL> def test_create_entitysuggestion ( self ) : <EOL> suggestion = self . _create_entity_suggestion ( ) <EOL> self . assertTrue ( suggestion . string == '<STR_LIT>' ) <EOL> def test_get_snippet ( self ) : <EOL> suggestion = self . _create_entity_suggestion ( ) <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ self . entity . id , self . language . code ] ) <EOL> resp = self . client [ '<STR_LIT>' ] . get ( url ) <EOL> self . assertContains ( resp , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> def _vote_up ( self , suggestion ) : <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ self . entity . id , self . language . code , suggestion . id ] , ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> return resp <EOL> def _vote_down ( self , suggestion ) : <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ self . entity . id , self . language . code , suggestion . id ] , ) <EOL> resp = self . client [ '<STR_LIT>' ] . post ( url ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> return resp <EOL> def test_votes ( self ) : <EOL> latest_sug = self . entity . suggestions . filter ( language = self . language ) . latest <EOL> self . _create_entity_suggestion ( ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> self . _vote_up ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:1> ) <EOL> self . _vote_up ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:1> ) <EOL> self . _vote_down ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> self . _vote_down ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , - <NUM_LIT:1> ) <EOL> self . _vote_down ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , - <NUM_LIT:1> ) <EOL> self . _vote_up ( s ) <EOL> s = latest_sug ( ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> class SuggestionsModelsTests ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SuggestionsModelsTests , self ) . setUp ( ) <EOL> self . entity = self . resource . entities [ <NUM_LIT:0> ] <EOL> self . suggestion = self . entity . suggestions . create ( <EOL> language = self . language , string = "<STR_LIT>" , user = self . user [ "<STR_LIT>" ] ) <EOL> def test_votes ( self ) : <EOL> u = self . user [ "<STR_LIT>" ] <EOL> s = self . suggestion <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> s . vote_up ( u ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:1> ) <EOL> s . vote_up ( u ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:1> ) <EOL> s . vote_down ( u ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> s . vote_down ( u ) <EOL> self . assertEqual ( s . score_rounded , - <NUM_LIT:1> ) <EOL> s . vote_down ( u ) <EOL> self . assertEqual ( s . score_rounded , - <NUM_LIT:1> ) <EOL> s . vote_up ( u ) <EOL> self . assertEqual ( s . score_rounded , <NUM_LIT:0> ) <EOL> def _create_suggestion ( self ) : <EOL> suggestion = self . entity . suggestions . create ( <EOL> language = self . language , string = "<STR_LIT>" , user = self . user [ "<STR_LIT>" ] ) <EOL> def test_double_suggestion ( self ) : <EOL> self . assertRaises ( IntegrityError , self . _create_suggestion ) </s>
