<s> from nose . tools import eq_ <EOL> from pyquery import PyQuery as pq <EOL> from kitsune . messages . models import OutboxMessage <EOL> from kitsune . sumo . templatetags . jinja_helpers import urlparams <EOL> from kitsune . sumo . tests import TestCase <EOL> from kitsune . sumo . urlresolvers import reverse <EOL> from kitsune . users . tests import UserFactory <EOL> class SendMessageTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SendMessageTestCase , self ) . setUp ( ) <EOL> self . user1 = UserFactory ( ) <EOL> self . user2 = UserFactory ( ) <EOL> self . user3 = UserFactory ( ) <EOL> self . client . login ( username = self . user1 . username , password = '<STR_LIT>' ) <EOL> def test_send_message_page ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , follow = True ) <EOL> eq_ ( <NUM_LIT:200> , response . status_code ) <EOL> assert len ( pq ( response . content ) ( '<STR_LIT>' ) ) <EOL> def _test_send_message_to ( self , to ) : <EOL> data = { '<STR_LIT:to>' : to , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' , locale = '<STR_LIT>' ) , <EOL> data , follow = True ) <EOL> eq_ ( <NUM_LIT:200> , response . status_code ) <EOL> eq_ ( '<STR_LIT>' , <EOL> pq ( response . content ) ( '<STR_LIT>' ) . text ( ) ) <EOL> eq_ ( <NUM_LIT:1> , OutboxMessage . objects . filter ( sender = self . user1 ) . count ( ) ) <EOL> return response <EOL> def test_send_message_to_one ( self ) : <EOL> self . _test_send_message_to ( self . user2 . username ) <EOL> def test_send_message_to_two ( self ) : <EOL> to = '<STR_LIT:U+002CU+0020>' . join ( [ self . user2 . username , self . user3 . username ] ) <EOL> self . _test_send_message_to ( to ) <EOL> def test_send_message_trailing_comma ( self ) : <EOL> self . _test_send_message_to ( self . user2 . username + '<STR_LIT:U+002C>' ) <EOL> def test_send_message_two_commas ( self ) : <EOL> self . _test_send_message_to ( self . user2 . username + '<STR_LIT>' + <EOL> self . user3 . username ) <EOL> def test_send_message_to_prefilled ( self ) : <EOL> url = urlparams ( reverse ( '<STR_LIT>' ) , to = self . user2 . username ) <EOL> response = self . client . get ( url , follow = True ) <EOL> eq_ ( <NUM_LIT:200> , response . status_code ) <EOL> eq_ ( self . user2 . username , <EOL> pq ( response . content ) ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . attrib [ '<STR_LIT:value>' ] ) <EOL> def test_send_message_ratelimited ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT> ) : <EOL> self . client . post ( <EOL> reverse ( '<STR_LIT>' , locale = '<STR_LIT>' ) , <EOL> { '<STR_LIT:to>' : self . user2 . username , '<STR_LIT:message>' : '<STR_LIT>' % i } ) <EOL> eq_ ( <NUM_LIT:50> , OutboxMessage . objects . filter ( sender = self . user1 ) . count ( ) ) <EOL> class MessagePreviewTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( MessagePreviewTests , self ) . setUp ( ) <EOL> self . user = UserFactory ( ) <EOL> self . client . login ( username = self . user . username , password = '<STR_LIT>' ) <EOL> def test_preview ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' , locale = '<STR_LIT>' ) , <EOL> { '<STR_LIT:content>' : '<STR_LIT>' } , follow = True ) <EOL> eq_ ( <NUM_LIT:200> , response . status_code ) <EOL> doc = pq ( response . content ) <EOL> eq_ ( '<STR_LIT>' , doc ( '<STR_LIT>' ) . text ( ) ) </s>
