<s> from django . core . exceptions import FieldError <EOL> from django . test import TestCase <EOL> from models import ( SelfRefer , Tag , TagCollection , Entry , SelfReferChild , <EOL> SelfReferChildSibling , Worksheet ) <EOL> class M2MRegressionTests ( TestCase ) : <EOL> def assertRaisesErrorWithMessage ( self , error , message , callable , * args , ** kwargs ) : <EOL> self . assertRaises ( error , callable , * args , ** kwargs ) <EOL> try : <EOL> callable ( * args , ** kwargs ) <EOL> except error , e : <EOL> self . assertEqual ( message , str ( e ) ) <EOL> def test_multiple_m2m ( self ) : <EOL> s1 = SelfRefer . objects . create ( name = '<STR_LIT>' ) <EOL> s2 = SelfRefer . objects . create ( name = '<STR_LIT>' ) <EOL> s3 = SelfRefer . objects . create ( name = '<STR_LIT>' ) <EOL> s1 . references . add ( s2 ) <EOL> s1 . related . add ( s3 ) <EOL> e1 = Entry . objects . create ( name = '<STR_LIT>' ) <EOL> t1 = Tag . objects . create ( name = '<STR_LIT>' ) <EOL> t2 = Tag . objects . create ( name = '<STR_LIT>' ) <EOL> e1 . topics . add ( t1 ) <EOL> e1 . related . add ( t2 ) <EOL> self . assertQuerysetEqual ( s1 . references . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( s1 . related . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( e1 . topics . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( e1 . related . all ( ) , [ "<STR_LIT>" ] ) <EOL> def test_internal_related_name_not_in_error_msg ( self ) : <EOL> self . assertRaisesErrorWithMessage ( FieldError , <EOL> "<STR_LIT>" , <EOL> lambda : SelfRefer . objects . filter ( porcupine = '<STR_LIT>' ) <EOL> ) <EOL> def test_m2m_inheritance_symmetry ( self ) : <EOL> sr_child = SelfReferChild ( name = "<STR_LIT>" ) <EOL> sr_child . save ( ) <EOL> sr_sibling = SelfReferChildSibling ( name = "<STR_LIT>" ) <EOL> sr_sibling . save ( ) <EOL> sr_child . related . add ( sr_sibling ) <EOL> self . assertQuerysetEqual ( sr_child . related . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( sr_sibling . related . all ( ) , [ "<STR_LIT>" ] ) <EOL> def test_m2m_pk_field_type ( self ) : <EOL> w = Worksheet ( id = '<STR_LIT:abc>' ) <EOL> w . save ( ) <EOL> w . delete ( ) <EOL> def test_add_m2m_with_base_class ( self ) : <EOL> t1 = Tag . objects . create ( name = '<STR_LIT>' ) <EOL> t2 = Tag . objects . create ( name = '<STR_LIT>' ) <EOL> c1 = TagCollection . objects . create ( name = '<STR_LIT>' ) <EOL> c1 . tags = [ t1 , t2 ] <EOL> c1 = TagCollection . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( c1 . tags . all ( ) , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( t1 . tag_collections . all ( ) , [ "<STR_LIT>" ] ) </s>
