<s> from __future__ import unicode_literals <EOL> from datetime import datetime <EOL> from django . test import TestCase <EOL> from django . utils import six <EOL> from . models import Article , Reporter , Writer <EOL> class M2MIntermediaryTests ( TestCase ) : <EOL> def test_intermeiary ( self ) : <EOL> r1 = Reporter . objects . create ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) <EOL> r2 = Reporter . objects . create ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) <EOL> a = Article . objects . create ( <EOL> headline = "<STR_LIT>" , pub_date = datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) <EOL> ) <EOL> w1 = Writer . objects . create ( reporter = r1 , article = a , position = "<STR_LIT>" ) <EOL> w2 = Writer . objects . create ( reporter = r2 , article = a , position = "<STR_LIT>" ) <EOL> self . assertQuerysetEqual ( <EOL> a . writer_set . select_related ( ) . order_by ( "<STR_LIT>" ) , [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] , <EOL> lambda w : ( six . text_type ( w . reporter ) , w . position ) <EOL> ) <EOL> self . assertEqual ( w1 . reporter , r1 ) <EOL> self . assertEqual ( w2 . reporter , r2 ) <EOL> self . assertEqual ( w1 . article , a ) <EOL> self . assertEqual ( w2 . article , a ) <EOL> self . assertQuerysetEqual ( <EOL> r1 . writer_set . all ( ) , [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] , <EOL> lambda w : ( six . text_type ( w . reporter ) , w . position ) <EOL> ) </s>
