Exemplo n.º 1
0
    def test_template_title_and_category_localized(self):
        # Because localized articles are required to match templates with their
        # parents, this deserves extra testing.

        d_en = DocumentFactory()
        d_fr = DocumentFactory(parent=d_en, locale='fr')

        # Just changing the title isn't enough
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        self.assertRaises(ValidationError, d_fr.save)

        # Trying to change the category won't work, since `d_en` will force the
        # old category.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d_fr.save)

        # Change the parent
        d_en.title = TEMPLATE_TITLE_PREFIX + d_en.title
        d_en.category = TEMPLATES_CATEGORY
        d_en.save()

        # Now the French article can be changed too.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        d_fr.save()
Exemplo n.º 2
0
    def test_template_title_and_category_localized(self):
        # Because localized articles are required to match templates with their
        # parents, this deserves extra testing.

        d_en = DocumentFactory()
        d_fr = DocumentFactory(parent=d_en, locale='fr')

        # Just changing the title isn't enough
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        self.assertRaises(ValidationError, d_fr.save)

        # Trying to change the category won't work, since `d_en` will force the
        # old category.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d_fr.save)

        # Change the parent
        d_en.title = TEMPLATE_TITLE_PREFIX + d_en.title
        d_en.category = TEMPLATES_CATEGORY
        d_en.save()

        # Now the French article can be changed too.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        d_fr.save()
Exemplo n.º 3
0
 def test_no_redirect_on_unsaved_change(self):
     """No redirect should be made when an unsaved doc's title or slug is
     changed."""
     d = DocumentFactory(title='Gerbil')
     d.title = 'Weasel'
     d.save()
     # There should be no redirect from Gerbil -> Weasel:
     assert not Document.objects.filter(title='Gerbil').exists()
Exemplo n.º 4
0
    def test_document_is_template(self):
        """is_template stays in sync with the title"""
        d = DocumentFactory(title='test')

        assert not d.is_template

        d.title = TEMPLATE_TITLE_PREFIX + 'test'
        d.category = TEMPLATES_CATEGORY
        d.save()

        assert d.is_template

        d.title = 'Back to document'
        d.category = CATEGORIES[0][0]
        d.save()

        assert not d.is_template
Exemplo n.º 5
0
    def test_template_title_and_category_to_template(self):
        d = DocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        self.assertRaises(ValidationError, d.save)

        # Next, try and change just the category. It should also fail.
        d = Document.objects.get(id=d.id)  # reset
        d.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d.save)

        # Finally, try and change both title and category. It should work.
        d = Document.objects.get(id=d.id)  # reset
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        d.category = TEMPLATES_CATEGORY
        d.save()
Exemplo n.º 6
0
 def test_no_redirect_on_unsaved_change(self):
     """No redirect should be made when an unsaved doc's title or slug is
     changed."""
     d = DocumentFactory(title='Gerbil')
     d.title = 'Weasel'
     d.save()
     # There should be no redirect from Gerbil -> Weasel:
     assert not Document.objects.filter(title='Gerbil').exists()
Exemplo n.º 7
0
    def test_document_is_template(self):
        """is_template stays in sync with the title"""
        d = DocumentFactory(title='test')

        assert not d.is_template

        d.title = TEMPLATE_TITLE_PREFIX + 'test'
        d.category = TEMPLATES_CATEGORY
        d.save()

        assert d.is_template

        d.title = 'Back to document'
        d.category = CATEGORIES[0][0]
        d.save()

        assert not d.is_template
Exemplo n.º 8
0
    def test_template_title_and_category_to_template(self):
        d = DocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        self.assertRaises(ValidationError, d.save)

        # Next, try and change just the category. It should also fail.
        d = Document.objects.get(id=d.id)  # reset
        d.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d.save)

        # Finally, try and change both title and category. It should work.
        d = Document.objects.get(id=d.id)  # reset
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        d.category = TEMPLATES_CATEGORY
        d.save()