From 86969e9df3a4e5416e14c8a0a67a1d047d9ba782 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 30 May 2014 15:49:21 +0100 Subject: [PATCH] Added test for replace_text command --- .../management/commands/replace_text.py | 2 +- wagtail/wagtailcore/tests.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailcore/management/commands/replace_text.py b/wagtail/wagtailcore/management/commands/replace_text.py index 23788d370..d654a61d6 100644 --- a/wagtail/wagtailcore/management/commands/replace_text.py +++ b/wagtail/wagtailcore/management/commands/replace_text.py @@ -24,7 +24,7 @@ class Command(BaseCommand): revision.save(update_fields=['content_json']) for content_type in get_page_types(): - print "scanning %s" % content_type.name + self.stdout.write("scanning %s" % content_type.name) page_class = content_type.model_class() try: diff --git a/wagtail/wagtailcore/tests.py b/wagtail/wagtailcore/tests.py index 8cbd7be9a..df66c6b93 100644 --- a/wagtail/wagtailcore/tests.py +++ b/wagtail/wagtailcore/tests.py @@ -841,3 +841,20 @@ class TestMovePagesCommand(TestCase): # Check that all pages moved for page_id in page_ids: self.assertEqual(Page.objects.get(id=page_id).get_parent(), about_us) + + +class TestReplaceTextCommand(TestCase): + fixtures = ['test.json'] + + def run_command(self, from_text, to_text): + management.call_command('replace_text', from_text, to_text, interactive=False, stdout=StringIO()) + + def test_replace_text(self): + # Check that the christmas page is definitely about christmas + self.assertEqual(Page.objects.get(url_path='/home/events/christmas/').title, "Christmas") + + # Make it about easter + self.run_command("Christmas", "Easter") + + # Check that its now about easter + self.assertEqual(Page.objects.get(url_path='/home/events/christmas/').title, "Easter")