Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango-mptt: .move_to is not working in test runner
    primarykey
    data
    text
    <p>the .move_to() method is not working for me. I've looked at other posts an people recommend saving the instance, as well as re-loading the node instances. But none of these solutions work in this test case. I also tried to do ._tree_manager.rebuild(), which doesn't work either. My test code below:</p> <pre><code>def test_reorder_pages(self): p = Page.objects.get(slug='page-1') p2 = Page.objects.get(slug='page-2') self.assertEqual(1, p.lft) self.assertEqual(3, p2.lft) p2.move_to(p, 'left') p = Page.objects.get(slug='page-1') p2 = Page.objects.get(slug='page-2') ## Values should now be reversed self.assertEqual(3, p.lft) self.assertEqual(1, p2.lft) </code></pre> <p>Basically what I'm expecting to happen is that page-2 is placed 'before' ( to the left of...) page-1. But the last two asserts fail. Also I checked all the other values (lft, rght, level, tree_id), and <em>none</em> of them changed.</p> <p>Does anyone know what I'm doing wrong?</p> <p><strong>EDIT:</strong> After suggestion by mossplix, I tried Page.tree.rebuild() again. This still doesn't work, but I did notice a strange behaviour. Before the move_to() these tests would pass:</p> <pre><code> self.assertEqual(0, p.level) self.assertEqual(1, p.lft) self.assertEqual(2, p.rght) self.assertEqual(1, p.tree_id) self.assertEqual(0, p2.level) self.assertEqual(3, p2.lft) self.assertEqual(4, p2.rght) self.assertEqual(1, p.tree_id) </code></pre> <p>After the <strong>move_to()</strong> and <strong>rebuild()</strong> what I'm expecting is this:</p> <pre><code> self.assertEqual(0, np.level) self.assertEqual(3, np.lft) self.assertEqual(4, np.rght) self.assertEqual(1, p.tree_id) self.assertEqual(0, np2.level) self.assertEqual(1, np2.lft) self.assertEqual(2, np2.rght) self.assertEqual(1, p.tree_id) </code></pre> <p>The tests above fail however, and on closer inspection, both pages now have identical values for all those attributes (lft, rght, level, tree_id). Surely this is wrong since that would imply that they occupy the exact same position in the tree?</p> <p><strong>Latest Update:</strong> Seems like using runserver, the moves works perfectly. The issues I'm having seems to be related to the testing framework. I've tried to use TransactionTestCase but this didn't solve the issue either. Updated title to reflect that it's related to tests.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload