def test_category_inheritance(self): """A document's categories must always be those of its parent.""" some_category = CATEGORIES[1][0] other_category = CATEGORIES[2][0] # Notice if somebody ever changes the default on the category field, # which would invalidate our test: assert some_category != DocumentFactory().category parent = DocumentFactory(category=some_category) child = DocumentFactory(parent=parent, locale='de') # Make sure child sees stuff set on parent: eq_(some_category, child.category) # Child'd category should revert to parent's on save: child.category = other_category child.save() eq_(some_category, child.category) # Changing the parent category should change the child's: parent.category = other_category parent.save() eq_(other_category, parent.translations.get(locale=child.locale).category)
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()
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
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()