Added test for move_pages command

This commit is contained in:
Karl Hobley 2014-05-30 15:43:54 +01:00
parent 9b0e56dc90
commit e9ce499d5a
2 changed files with 22 additions and 2 deletions

View file

@ -15,8 +15,8 @@ class Command(BaseCommand):
pages = from_page.get_children()
# Move the pages
print 'Moving ' + str(len(pages)) + ' pages from "' + from_page.title + '" to "' + to_page.title + '"'
self.stdout.write('Moving ' + str(len(pages)) + ' pages from "' + from_page.title + '" to "' + to_page.title + '"')
for page in pages:
page.move(to_page, pos='last-child')
print 'Done'
self.stdout.write('Done')

View file

@ -821,3 +821,23 @@ class TestFixTreeCommand(TestCase):
# Check if its fixed
self.assertEqual(Page.objects.get(url_path='/home/').depth, old_depth)
class TestMovePagesCommand(TestCase):
fixtures = ['test.json']
def run_command(self, from_, to):
management.call_command('move_pages', str(from_), str(to), interactive=False, stdout=StringIO())
def test_move_pages(self):
# Get pages
events_index = Page.objects.get(url_path='/home/events/')
about_us = Page.objects.get(url_path='/home/about-us/')
page_ids = events_index.get_children().values_list('id', flat=True)
# Move all events into "about us"
self.run_command(events_index.id, about_us.id)
# Check that all pages moved
for page_id in page_ids:
self.assertEqual(Page.objects.get(id=page_id).get_parent(), about_us)