def _test_remembering_setter_unsaved(self, field): """A remembering setter shouldn't kick in until the doc is saved.""" old_field = 'old_' + field d = DocumentFactory.build() setattr(d, field, 'Foo') assert not hasattr( d, old_field), "Doc shouldn't have %s until it's saved." % old_field
def test_validate_category_on_save(self): """Make sure invalid categories can't be saved. Invalid categories cause errors when viewing documents. """ d = DocumentFactory.build(category=9999) self.assertRaises(ValidationError, d.save)
def test_only_localizable_allowed_children(self): """You can't have children for a non-localizable document.""" # Make English rev: en_doc = DocumentFactory(is_localizable=False) # Make Deutsch translation: de_doc = DocumentFactory.build(parent=en_doc, locale='de') self.assertRaises(ValidationError, de_doc.save)
def test_new_doc_does_not_update_categories(self): """Make sure that creating a new document doesn't change the category of all the other documents.""" d1 = DocumentFactory(category=20) assert d1.pk d2 = DocumentFactory.build(category=30) assert not d2.pk d2._clean_category() d1prime = Document.objects.get(pk=d1.pk) eq_(20, d1prime.category)
def _test_remembering_setter_unsaved(self, field): """A remembering setter shouldn't kick in until the doc is saved.""" old_field = 'old_' + field d = DocumentFactory.build() setattr(d, field, 'Foo') assert not hasattr(d, old_field), "Doc shouldn't have %s until it's saved." % old_field