<s> from __future__ import unicode_literals <EOL> from django . core . exceptions import FieldError <EOL> from django . test import TestCase <EOL> from django . utils import six <EOL> from . models import ( <EOL> Entry , Line , Post , RegressionModelSplit , SelfRefer , SelfReferChild , <EOL> SelfReferChildSibling , Tag , TagCollection , Worksheet , <EOL> ) <EOL> class M2MRegressionTests ( TestCase ) : <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> six . assertRaisesRegex ( <EOL> self , 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 . set ( [ t1 , t2 ] ) <EOL> c1 = TagCollection . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( c1 . tags . all ( ) , [ "<STR_LIT>" , "<STR_LIT>" ] , ordered = False ) <EOL> self . assertQuerysetEqual ( t1 . tag_collections . all ( ) , [ "<STR_LIT>" ] ) <EOL> def test_manager_class_caching ( self ) : <EOL> e1 = Entry . objects . create ( ) <EOL> e2 = Entry . objects . create ( ) <EOL> t1 = Tag . objects . create ( ) <EOL> t2 = Tag . objects . create ( ) <EOL> self . assertIs ( t1 . entry_set . __class__ , t1 . entry_set . __class__ ) <EOL> self . assertIs ( e1 . topics . __class__ , e1 . topics . __class__ ) <EOL> self . assertIs ( e1 . topics . __class__ , e2 . topics . __class__ ) <EOL> self . assertIs ( t1 . entry_set . __class__ , t2 . entry_set . __class__ ) <EOL> def test_m2m_abstract_split ( self ) : <EOL> m1 = RegressionModelSplit ( name = '<STR_LIT:1>' ) <EOL> m1 . save ( ) <EOL> def test_assigning_invalid_data_to_m2m_doesnt_clear_existing_relations ( 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 . set ( [ t1 , t2 ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> c1 . tags . set ( <NUM_LIT:7> ) <EOL> c1 . refresh_from_db ( ) <EOL> self . assertQuerysetEqual ( c1 . tags . order_by ( '<STR_LIT:name>' ) , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_multiple_forwards_only_m2m ( self ) : <EOL> foo = Line . objects . create ( name = '<STR_LIT:foo>' ) <EOL> bar = Line . objects . create ( name = '<STR_LIT:bar>' ) <EOL> post = Post . objects . create ( ) <EOL> post . primary_lines . add ( foo ) <EOL> post . secondary_lines . add ( bar ) <EOL> self . assertQuerysetEqual ( post . primary_lines . all ( ) , [ '<STR_LIT>' ] ) <EOL> self . assertQuerysetEqual ( post . secondary_lines . all ( ) , [ '<STR_LIT>' ] ) </s>
