<s> from django . test import TestCase <EOL> from django . core . exceptions import FieldError <EOL> from models import User , Poll , Choice <EOL> class ReverseLookupTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> john = User . objects . create ( name = "<STR_LIT>" ) <EOL> jim = User . objects . create ( name = "<STR_LIT>" ) <EOL> first_poll = Poll . objects . create ( <EOL> question = "<STR_LIT>" , <EOL> creator = john <EOL> ) <EOL> second_poll = Poll . objects . create ( <EOL> question = "<STR_LIT>" , <EOL> creator = jim <EOL> ) <EOL> new_choice = Choice . objects . create ( <EOL> poll = first_poll , <EOL> related_poll = second_poll , <EOL> name = "<STR_LIT>" <EOL> ) <EOL> def test_reverse_by_field ( self ) : <EOL> u1 = User . objects . get ( <EOL> poll__question__exact = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( u1 . name , "<STR_LIT>" ) <EOL> u2 = User . objects . get ( <EOL> poll__question__exact = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( u2 . name , "<STR_LIT>" ) <EOL> def test_reverse_by_related_name ( self ) : <EOL> p1 = Poll . objects . get ( poll_choice__name__exact = "<STR_LIT>" ) <EOL> self . assertEqual ( p1 . question , "<STR_LIT>" ) <EOL> p2 = Poll . objects . get ( <EOL> related_choice__name__exact = "<STR_LIT>" ) <EOL> self . assertEqual ( p2 . question , "<STR_LIT>" ) <EOL> def test_reverse_field_name_disallowed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( FieldError , Poll . objects . get , <EOL> choice__name__exact = "<STR_LIT>" ) </s>
