<s> from __future__ import absolute_import <EOL> from operator import attrgetter <EOL> from django . test import TestCase <EOL> from . models import Post , Question , Answer <EOL> class OrderWithRespectToTests ( TestCase ) : <EOL> def test_basic ( self ) : <EOL> q1 = Question . objects . create ( text = "<STR_LIT>" ) <EOL> q2 = Question . objects . create ( text = "<STR_LIT>" ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q1 ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q2 ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q1 ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q2 ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q1 ) <EOL> Answer . objects . create ( text = "<STR_LIT>" , question = q1 ) <EOL> self . assertQuerysetEqual ( <EOL> q1 . answer_set . all ( ) , [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ] , <EOL> attrgetter ( "<STR_LIT:text>" ) , <EOL> ) <EOL> a1 = Answer . objects . filter ( question = q1 ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( a1 . text , "<STR_LIT>" ) <EOL> a2 = a1 . get_next_in_order ( ) <EOL> self . assertEqual ( a2 . text , "<STR_LIT>" ) <EOL> a4 = list ( Answer . objects . filter ( question = q1 ) ) [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( a4 . text , "<STR_LIT>" ) <EOL> self . assertEqual ( a4 . get_previous_in_order ( ) . text , "<STR_LIT>" ) <EOL> id_list = [ o . pk for o in q1 . answer_set . all ( ) ] <EOL> self . assertEqual ( a2 . question . get_answer_order ( ) , id_list ) <EOL> a5 = Answer . objects . create ( text = "<STR_LIT>" , question = q1 ) <EOL> self . assertEqual ( <EOL> a2 . question . get_answer_order ( ) , a5 . question . get_answer_order ( ) <EOL> ) <EOL> id_list = [ o . pk for o in q1 . answer_set . all ( ) ] <EOL> x = id_list . pop ( ) <EOL> id_list . insert ( - <NUM_LIT:1> , x ) <EOL> self . assertNotEqual ( a5 . question . get_answer_order ( ) , id_list ) <EOL> a5 . question . set_answer_order ( id_list ) <EOL> self . assertQuerysetEqual ( <EOL> q1 . answer_set . all ( ) , [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> ] , <EOL> attrgetter ( "<STR_LIT:text>" ) <EOL> ) <EOL> def test_recursive_ordering ( self ) : <EOL> p1 = Post . objects . create ( title = '<STR_LIT:1>' ) <EOL> p2 = Post . objects . create ( title = '<STR_LIT:2>' ) <EOL> p1_1 = Post . objects . create ( title = "<STR_LIT>" , parent = p1 ) <EOL> p1_2 = Post . objects . create ( title = "<STR_LIT>" , parent = p1 ) <EOL> p2_1 = Post . objects . create ( title = "<STR_LIT>" , parent = p2 ) <EOL> p1_3 = Post . objects . create ( title = "<STR_LIT>" , parent = p1 ) <EOL> self . assertEqual ( p1 . get_post_order ( ) , [ p1_1 . pk , p1_2 . pk , p1_3 . pk ] ) </s>
