<s> from django . test import TestCase <EOL> from positions . examples . nodes . models import Node <EOL> import doctest <EOL> import os <EOL> import unittest <EOL> class NodesTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . parent1 = Node . objects . create ( name = '<STR_LIT>' ) <EOL> self . parent2 = Node . objects . create ( name = '<STR_LIT>' ) <EOL> self . child1 = self . parent1 . children . create ( name = '<STR_LIT>' ) <EOL> self . child2 = self . parent1 . children . create ( name = '<STR_LIT>' ) <EOL> self . child3 = self . parent1 . children . create ( name = '<STR_LIT>' ) <EOL> self . child2 . position = <NUM_LIT:0> <EOL> self . child2 . save ( ) <EOL> self . child1 = Node . objects . get ( pk = self . child1 . pk ) <EOL> self . child2 = Node . objects . get ( pk = self . child2 . pk ) <EOL> self . child3 = Node . objects . get ( pk = self . child3 . pk ) <EOL> self . child4 = self . parent2 . children . create ( name = '<STR_LIT>' ) <EOL> self . child5 = self . parent2 . children . create ( name = '<STR_LIT>' ) <EOL> self . child6 = self . parent2 . children . create ( name = '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> Node . objects . all ( ) . delete ( ) <EOL> def test_structure ( self ) : <EOL> """<STR_LIT>""" <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_sibling_position ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child6 . position = <NUM_LIT:0> <EOL> self . child6 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_first_child ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . position = <NUM_LIT:0> <EOL> self . child2 . parent = Node . objects . get ( pk = self . parent2 . pk ) <EOL> self . child2 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_last_child ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . position = - <NUM_LIT:1> <EOL> self . child2 . parent = Node . objects . get ( pk = self . parent2 . pk ) <EOL> self . child2 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_sibling_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . position = <NUM_LIT:1> <EOL> self . child2 . parent = Node . objects . get ( pk = self . parent2 . pk ) <EOL> self . child2 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_sibling_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . position = <NUM_LIT:2> <EOL> self . child2 . parent = Node . objects . get ( pk = self . parent2 . pk ) <EOL> self . child2 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_collection_field_change_sibling_3 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . position = <NUM_LIT:3> <EOL> self . child2 . parent = Node . objects . get ( pk = self . parent2 . pk ) <EOL> self . child2 . save ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) , ( u'<STR_LIT>' , <NUM_LIT:3> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_deletion_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child2 . delete ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_deletion_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child3 . delete ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_deletion_3 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . child1 . delete ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> def test_deletion_4 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . parent1 . delete ( ) <EOL> result = list ( Node . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> expected_result = [ ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:0> ) , ( u'<STR_LIT>' , <NUM_LIT:1> ) , ( u'<STR_LIT>' , <NUM_LIT:2> ) ] <EOL> self . assertEqual ( sorted ( result ) , sorted ( expected_result ) ) <EOL> class ReorderTestCase ( TestCase ) : <EOL> def tearDown ( self ) : <EOL> Node . objects . all ( ) . delete ( ) <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> def test_assigning_parent ( self ) : <EOL> a = Node . objects . create ( name = u"<STR_LIT:A>" ) <EOL> b = Node . objects . create ( name = u"<STR_LIT:B>" ) <EOL> c = Node . objects . create ( name = u"<STR_LIT:C>" ) <EOL> self . assertEqual ( a . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( b . position , <NUM_LIT:1> ) <EOL> self . assertEqual ( c . position , <NUM_LIT:2> ) <EOL> b . parent = a <EOL> b . save ( ) <EOL> self . assertEqual ( a . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( b . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( c . position , <NUM_LIT:1> ) <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> def test_changing_parent ( self ) : <EOL> a = Node . objects . create ( name = u"<STR_LIT:A>" ) <EOL> b = Node . objects . create ( name = u"<STR_LIT:B>" ) <EOL> c = Node . objects . create ( name = u"<STR_LIT:C>" , parent = a ) <EOL> d = Node . objects . create ( name = u"<STR_LIT:D>" , parent = a ) <EOL> self . assertEqual ( a . parent , None ) <EOL> self . assertEqual ( a . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( b . parent , None ) <EOL> self . assertEqual ( b . position , <NUM_LIT:1> ) <EOL> self . assertEqual ( c . parent , a ) <EOL> self . assertEqual ( c . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( d . parent , a ) <EOL> self . assertEqual ( d . position , <NUM_LIT:1> ) <EOL> c . parent = b <EOL> c . save ( ) <EOL> self . assertEqual ( a . parent , None ) <EOL> self . assertEqual ( a . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( b . parent , None ) <EOL> self . assertEqual ( b . position , <NUM_LIT:1> ) <EOL> self . assertEqual ( c . parent , b ) <EOL> self . assertEqual ( c . position , <NUM_LIT:0> ) <EOL> self . assertEqual ( d . parent , a ) <EOL> self . assertEqual ( d . position , <NUM_LIT:0> ) <EOL> def suite ( ) : <EOL> s = unittest . TestSuite ( ) <EOL> s . addTest ( unittest . TestLoader ( ) . loadTestsFromTestCase ( NodesTestCase ) ) <EOL> s . addTest ( doctest . DocFileSuite ( os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , optionflags = doctest . REPORT_ONLY_FIRST_FAILURE ) ) <EOL> return s </s>
