Commits

Gustavo Picon committed fd57de9

More test cleanup

  • Participants
  • Parent commits d367df3

Comments (0)

Files changed (1)

treebeard/tests/test_treebeard.py

 """Unit/Functional tests"""
 
 from __future__ import with_statement
+import datetime
 import os
 import sys
 
                     ('41', 2, 0)]
         expected_descs = ['1', '2', '21', '22', '23', '231', '24',
                           '3', '4', '41']
-        got_descs = [obj.desc
-                     for obj in model.objects.filter(id__in=ids)]
+        got_descs = [obj.desc for obj in model.objects.filter(id__in=ids)]
         assert sorted(got_descs) == sorted(expected_descs)
         assert self.got(model) == expected
 
 
 class TestMoveLeafRoot(TestNonEmptyTree):
     def test_move_leaf_last_sibling_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'last-sibling')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'last-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_first_sibling_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'first-sibling')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'first-sibling')
         expected = [('231', 1, 0),
                     ('1', 1, 0),
                     ('2', 1, 4),
         assert self.got(model) == expected
 
     def test_move_leaf_left_sibling_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'left')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'left')
         expected = [('1', 1, 0),
                     ('231', 1, 0),
                     ('2', 1, 4),
         assert self.got(model) == expected
 
     def test_move_leaf_right_sibling_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'right')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_last_child_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'last-child')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'last-child')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_first_child_root(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='2'), 'first-child')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='231').move(target, 'first-child')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('231', 2, 0),
 
 class TestMoveLeaf(TestNonEmptyTree):
     def test_move_leaf_last_sibling(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'last-sibling')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'last-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_first_sibling(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'first-sibling')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'first-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('231', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_left_sibling(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'left')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'left')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_right_sibling(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'right')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_left_sibling_itself(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='231'), 'left')
+        target = model.objects.get(desc='231')
+        model.objects.get(desc='231').move(target, 'left')
         assert self.got(model) == UNCHANGED
 
     def test_move_leaf_last_child(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'last-child')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'last-child')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_leaf_first_child(self, model):
-        model.objects.get(desc='231').move(
-            model.objects.get(desc='22'), 'first-child')
+        target = model.objects.get(desc='22')
+        model.objects.get(desc='231').move(target, 'first-child')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
 
 class TestMoveBranchRoot(TestNonEmptyTree):
     def test_move_branch_first_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'first-sibling')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'first-sibling')
         expected = [('4', 1, 1),
                     ('41', 2, 0),
                     ('1', 1, 0),
         assert self.got(model) == expected
 
     def test_move_branch_last_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'last-sibling')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'last-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_left_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'left')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'left')
         expected = [('1', 1, 0),
                     ('4', 1, 1),
                     ('41', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_right_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'right')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_left_noleft_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2').get_first_sibling(), 'left')
+        target = model.objects.get(desc='2').get_first_sibling()
+        model.objects.get(desc='4').move(target, 'left')
         expected = [('4', 1, 1),
                     ('41', 2, 0),
                     ('1', 1, 0),
         assert self.got(model) == expected
 
     def test_move_branch_right_noright_sibling_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2').get_last_sibling(), 'right')
+        target = model.objects.get(desc='2').get_last_sibling()
+        model.objects.get(desc='4').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_first_child_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'first-child')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'first-child')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('4', 2, 1),
         assert self.got(model) == expected
 
     def test_move_branch_last_child_root(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='2'), 'last-child')
+        target = model.objects.get(desc='2')
+        model.objects.get(desc='4').move(target, 'last-child')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
 
 class TestMoveBranch(TestNonEmptyTree):
     def test_move_branch_first_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'first-sibling')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'first-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('4', 2, 1),
         assert self.got(model) == expected
 
     def test_move_branch_last_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'last-sibling')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'last-sibling')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_left_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'left')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'left')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_right_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'right')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_left_noleft_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23').get_first_sibling(), 'left')
+        target = model.objects.get(desc='23').get_first_sibling()
+        model.objects.get(desc='4').move(target, 'left')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('4', 2, 1),
         assert self.got(model) == expected
 
     def test_move_branch_right_noright_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23').get_last_sibling(), 'right')
+        target = model.objects.get(desc='23').get_last_sibling()
+        model.objects.get(desc='4').move(target, 'right')
         expected = [('1', 1, 0),
                     ('2', 1, 5),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_left_itself_sibling(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='4'), 'left')
+        target = model.objects.get(desc='4')
+        model.objects.get(desc='4').move(target, 'left')
         assert self.got(model) == UNCHANGED
 
     def test_move_branch_first_child(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'first-child')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'first-child')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
         assert self.got(model) == expected
 
     def test_move_branch_last_child(self, model):
-        model.objects.get(desc='4').move(
-            model.objects.get(desc='23'), 'last-child')
+        target = model.objects.get(desc='23')
+        model.objects.get(desc='4').move(target, 'last-child')
         expected = [('1', 1, 0),
                     ('2', 1, 4),
                     ('21', 2, 0),
             # because raw queries don't update django objects
             node = sorted_model.objects.get(pk=node.pk)
             target = sorted_model.objects.get(pk=target.pk)
-
             node.move(target, 'sorted-child')
         expected = [(1, 4, 'bcd', 1, 7),
                     (2, 2, 'qwe', 2, 0),
             # because raw queries don't update django objects
             node = sorted_model.objects.get(pk=node.pk)
             target = sorted_model.objects.get(pk=target.pk)
-
             node.val1 -= 2
             node.save()
             node.move(target, 'sorted-sibling')
 
     def test_sorted_by_autonow_workaround(self, mpsortedautonow_model):
         # workaround
-        import datetime
-
         for i in range(1, 5):
-            mpsortedautonow_model.add_root(
-                desc='node%d' % (i, ),
-                created=datetime.datetime.now()
-            )
+            mpsortedautonow_model.add_root(desc='node%d' % (i, ),
+                                           created=datetime.datetime.now())
 
     def test_sorted_by_autonow_FAIL(self, mpsortedautonow_model):
         """