<s> import unittest <EOL> from django . test import TestCase <EOL> from django . test . client import Client , ClientHandler <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . cache import cache <EOL> from models import Chat <EOL> class ClientTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> fixtures = [ '<STR_LIT>' , ] <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_start_chat ( self ) : <EOL> login = self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp2 = self . client . get ( resp [ '<STR_LIT:location>' ] ) <EOL> self . assertEqual ( resp2 . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( resp2 . context [ '<STR_LIT>' ] . hash_key in resp [ '<STR_LIT:location>' ] ) <EOL> def test_leave_message ( self ) : <EOL> cache . set ( '<STR_LIT>' , None ) <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_get_messages_prompts_login ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , resp [ '<STR_LIT:location>' ] ) <EOL> def test_get_messages_with_hash_key_returns_messages ( self ) : <EOL> chat = Chat . objects . create ( name = '<STR_LIT>' , details = '<STR_LIT>' ) <EOL> chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' , args = [ chat . hash_key ] ) ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content ) <EOL> def test_get_latest_message ( self ) : <EOL> chat = Chat . objects . create ( name = '<STR_LIT>' , details = '<STR_LIT>' ) <EOL> message1 = chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> message2 = chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' , args = [ chat . hash_key ] ) <EOL> resp = self . client . get ( '<STR_LIT>' % ( url , chat . id , message1 . id ) ) <EOL> self . assertIn ( '<STR_LIT>' , resp . content ) <EOL> self . assertNotIn ( '<STR_LIT>' , resp . content ) <EOL> class AdminTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> fixtures = [ '<STR_LIT>' , ] <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_get_all_messages ( self ) : <EOL> login = self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> chat = Chat . objects . create ( name = '<STR_LIT>' , details = '<STR_LIT>' ) <EOL> chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' % ( url , chat . id ) ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content ) <EOL> def test_getting_messages_with_invalid_args ( self ) : <EOL> login = self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> chat = Chat . objects . create ( name = '<STR_LIT>' , details = '<STR_LIT>' ) <EOL> message1 = chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> message2 = chat . messages . create ( name = chat . name , message = '<STR_LIT>' ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' % ( url , chat . id , message1 . id ) ) <EOL> self . assertIn ( '<STR_LIT>' , resp . content ) <EOL> self . assertNotIn ( '<STR_LIT>' , resp . content ) <EOL> def test_send_admin_message ( self ) : <EOL> login = self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> chat = Chat . objects . create ( name = '<STR_LIT>' , details = '<STR_LIT>' ) <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' , args = [ chat . id ] ) , <EOL> { '<STR_LIT:message>' : '<STR_LIT>' } , <EOL> ** { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertIn ( '<STR_LIT>' , resp . content ) </s>
