<s> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from django . core import management <EOL> from django . contrib . auth . models import User <EOL> from django . test import TestCase <EOL> from models import ( Person , Group , Membership , UserMembership , <EOL> Car , Driver , CarDriver ) <EOL> class M2MThroughTestCase ( TestCase ) : <EOL> def test_everything ( self ) : <EOL> bob = Person . objects . create ( name = "<STR_LIT>" ) <EOL> jim = Person . objects . create ( name = "<STR_LIT>" ) <EOL> rock = Group . objects . create ( name = "<STR_LIT>" ) <EOL> roll = Group . objects . create ( name = "<STR_LIT>" ) <EOL> frank = User . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> jane = User . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> Membership . objects . create ( person = bob , group = rock ) <EOL> Membership . objects . create ( person = bob , group = roll ) <EOL> Membership . objects . create ( person = jim , group = rock ) <EOL> self . assertQuerysetEqual ( <EOL> bob . group_set . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> roll . members . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertRaises ( AttributeError , setattr , bob , "<STR_LIT>" , [ ] ) <EOL> self . assertRaises ( AttributeError , setattr , roll , "<STR_LIT>" , [ ] ) <EOL> self . assertRaises ( AttributeError , rock . members . create , name = "<STR_LIT>" ) <EOL> self . assertRaises ( AttributeError , bob . group_set . create , name = "<STR_LIT>" ) <EOL> UserMembership . objects . create ( user = frank , group = rock ) <EOL> UserMembership . objects . create ( user = frank , group = roll ) <EOL> UserMembership . objects . create ( user = jane , group = rock ) <EOL> self . assertQuerysetEqual ( <EOL> frank . group_set . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> roll . user_members . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> def test_serialization ( self ) : <EOL> "<STR_LIT>" <EOL> p = Person . objects . create ( name = "<STR_LIT>" ) <EOL> g = Group . objects . create ( name = "<STR_LIT>" ) <EOL> m = Membership . objects . create ( person = p , group = g ) <EOL> pks = { "<STR_LIT>" : p . pk , "<STR_LIT>" : g . pk , "<STR_LIT>" : m . pk } <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" % pks ) <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , <EOL> indent = <NUM_LIT:2> , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" . strip ( ) % pks ) <EOL> def test_join_trimming ( self ) : <EOL> "<STR_LIT>" <EOL> bob = Person . objects . create ( name = "<STR_LIT>" ) <EOL> jim = Person . objects . create ( name = "<STR_LIT>" ) <EOL> rock = Group . objects . create ( name = "<STR_LIT>" ) <EOL> roll = Group . objects . create ( name = "<STR_LIT>" ) <EOL> Membership . objects . create ( person = bob , group = rock ) <EOL> Membership . objects . create ( person = jim , group = rock , price = <NUM_LIT:50> ) <EOL> Membership . objects . create ( person = bob , group = roll , price = <NUM_LIT:50> ) <EOL> self . assertQuerysetEqual ( <EOL> rock . members . filter ( membership__price = <NUM_LIT:50> ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> bob . group_set . filter ( membership__price = <NUM_LIT:50> ) , [ <EOL> "<STR_LIT>" , <EOL> ] <EOL> ) <EOL> class ToFieldThroughTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . car = Car . objects . create ( make = "<STR_LIT>" ) <EOL> self . driver = Driver . objects . create ( name = "<STR_LIT>" ) <EOL> CarDriver . objects . create ( car = self . car , driver = self . driver ) <EOL> def test_to_field ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . car . drivers . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> def test_to_field_reverse ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . driver . car_set . all ( ) , <EOL> [ "<STR_LIT>" ] <EOL> ) <EOL> class ThroughLoadDataTestCase ( TestCase ) : <EOL> fixtures = [ "<STR_LIT>" ] <EOL> def test_sequence_creation ( self ) : <EOL> "<STR_LIT>" <EOL> out = StringIO ( ) <EOL> management . call_command ( "<STR_LIT>" , "<STR_LIT>" , format = "<STR_LIT>" , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) . strip ( ) , """<STR_LIT>""" ) </s>
