def test_model_validation(self): self.assertRaisesRegexp( AttributeError, r"'NoneType' object has no attribute 'revisions'", # cannot set `revision` without a parent PostRevision.objects.create, *[], **{ 'text': 'blah', 'author': self.u1, 'revised_at': datetime.datetime.now() }) post_revision = PostRevision( text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=1, ) self.assertRaisesRegexp( ValidationError, r"{'__all__': \[u'Post field has to be set.'\]}", post_revision.save) question = self.post_question(user=self.u1) rev2 = PostRevision(post=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=2) rev2.save() self.assertFalse(rev2.id is None)
def test_model_validation(self): """ self.assertRaisesRegexp( AttributeError, r"'NoneType' object has no attribute 'revisions'", # cannot set `revision` without a parent PostRevision.objects.create, *[], **{ 'text': 'blah', 'author': self.u1, 'revised_at': datetime.datetime.now() } ) #this test does not work post_revision = PostRevision( text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=1, ) self.assertRaisesRegexp( ValidationError, r"{'__all__': \[u'Post field has to be set.'\]}", post_revision.save ) """ question = self.post_question(user=self.u1) rev2 = PostRevision(post=question, text="blah", author=self.u1, revised_at=datetime.datetime.now(), revision=2) rev2.save() self.assertFalse(rev2.id is None)
def import_post_revisions(self): """Imports OSQA revisions to Askbot revisions""" for osqa_revision in self.get_objects_for_model('forum.noderevision'): post = self.get_imported_object_by_old_id(Post, osqa_revision.node) if post is None: continue #deleted post user = self.get_imported_object_by_old_id(User, osqa_revision.author) revision = PostRevision(post=post, author=user, text=osqa_revision.body, title=osqa_revision.title, tagnames=osqa_revision.tagnames, revised_at=osqa_revision.revised_at, summary=osqa_revision.summary, revision=osqa_revision.revision) post.text = osqa_revision.body if osqa_revision == 1: post.added_at = osqa_revision.revised_at else: post.last_edited_at = osqa_revision.revised_at post.last_edited_by = user post.parse_and_save(author=user) revision.save()
def test_model_validation(self): with self.assertRaises(NotImplementedError): PostRevision.objects.create(text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision_type=PostRevision.QUESTION_REVISION) with self.assertRaisesRegexp(AttributeError, r"'NoneType' object has no attribute 'revisions'"): # cannot set `revision` without a parent PostRevision.objects.create_answer_revision(text='blah', author=self.u1, revised_at=datetime.datetime.now()) with self.assertRaisesRegexp(ValidationError, r"{'__all__': \[u'One \(and only one\) of question/answer fields has to be set.'\], 'revision_type': \[u'Value 4 is not a valid choice.'\]}"): # revision_type not in (1,2) PostRevision(text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=1, revision_type=4).save() question = self.post_question(user=self.u1) rev2 = PostRevision(question=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=2, revision_type=PostRevision.QUESTION_REVISION) rev2.save() self.assertIsNotNone(rev2.id) with self.assertRaisesRegexp(ValidationError, r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.', u'Post revision with this Question and Revision already exists.'\]}"): PostRevision(question=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=2, revision_type=PostRevision.ANSWER_REVISION).save() with self.assertRaisesRegexp(ValidationError, r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.'\]}"): PostRevision(question=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=3, revision_type=PostRevision.ANSWER_REVISION).save() rev3 = PostRevision.objects.create_question_revision(question=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision_type=123) # revision_type self.assertIsNotNone(rev3.id) self.assertEqual(3, rev3.revision) # By the way: let's test the auto-increase of revision number self.assertEqual(PostRevision.QUESTION_REVISION, rev3.revision_type)
def import_post_revisions(self): """Imports OSQA revisions to Askbot revisions""" for osqa_revision in self.get_objects_for_model('forum.noderevision'): post = self.get_imported_object_by_old_id(Post, osqa_revision.node) if post is None: continue #deleted post user = self.get_imported_object_by_old_id(User, osqa_revision.author) revision = PostRevision( post=post, author=user, text=osqa_revision.body, title=osqa_revision.title, tagnames=osqa_revision.tagnames, revised_at=osqa_revision.revised_at, summary=osqa_revision.summary, revision=osqa_revision.revision ) post.text = osqa_revision.body if osqa_revision == 1: post.added_at = osqa_revision.revised_at else: post.last_edited_at = osqa_revision.revised_at post.last_edited_by = user post.parse_and_save(author=user) revision.save()
def import_post_revisions(self): """Imports OSQA revisions to Askbot revisions""" for osqa_revision in self.get_objects_for_model('forum.noderevision'): post = self.get_imported_object_by_old_id(Post, osqa_revision.node) user = self.get_imported_object_by_old_id(User, osqa_revision.author) revision = PostRevision( post=post, author=user, text=osqa_revision.body, title=osqa_revision.title, tagnames=osqa_revision.tagnames, revised_at=osqa_revision.revised_at, summary=osqa_revision.summary, revision=osqa_revision.revision ) revision.save()
def test_model_validation(self): self.assertRaises( NotImplementedError, PostRevision.objects.create, [], { 'text': 'blah', 'author': self.u1, 'revised_at': datetime.datetime.now(), 'revision_type': PostRevision.QUESTION_REVISION } ) self.assertRaisesRegexp( AttributeError, r"'NoneType' object has no attribute 'revisions'", # cannot set `revision` without a parent PostRevision.objects.create_answer_revision, *[], **{ 'text': 'blah', 'author': self.u1, 'revised_at': datetime.datetime.now() } ) post_revision = PostRevision( text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=1, revision_type=4 ) self.assertRaisesRegexp( ValidationError, r"{'__all__': \[u'Post field has to be set.'\], 'revision_type': \[u'Value 4 is not a valid choice.'\]}", post_revision.save ) # revision_type not in (1,2) question = self.post_question(user=self.u1) rev2 = PostRevision(post=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=2, revision_type=PostRevision.QUESTION_REVISION) rev2.save() self.assertFalse(rev2.id is None) post_revision = PostRevision( post=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=2, revision_type=PostRevision.ANSWER_REVISION ) self.assertRaisesRegexp( ValidationError, r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.', u'Post revision with this Post and Revision already exists.'\]}", post_revision.save ) post_revision = PostRevision( post=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision=3, revision_type=PostRevision.ANSWER_REVISION ) self.assertRaisesRegexp( ValidationError, r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.'\]}", post_revision.save ) rev3 = PostRevision.objects.create_question_revision(post=question, text='blah', author=self.u1, revised_at=datetime.datetime.now(), revision_type=123) # revision_type self.assertFalse(rev3.id is None) self.assertEqual(3, rev3.revision) # By the way: let's test the auto-increase of revision number self.assertEqual(PostRevision.QUESTION_REVISION, rev3.revision_type)