def test_creating_a_new_comment_and_saving_it_to_the_database(self): # start by create one Category and one post category = Category() category.name = "First" category.slug = "first" category.save() # create new post post = Post() post.category = category post.title = "First post" post.content = "Content" post.visable = True post.save() # create one comment comment = Comment() comment.name = "John" comment.content = "This is cool" comment.post = post # check save comment.save() # now check we can find it in the database all_comment_in_database = Comment.objects.all() self.assertEquals(len(all_comment_in_database), 1) only_comment_in_database = all_comment_in_database[0] self.assertEquals(only_comment_in_database, comment) # and check that it's saved its two attributes: name and content self.assertEquals(only_comment_in_database.name, comment.name) self.assertEquals(only_comment_in_database.content, comment.content)
def test_creating_a_new_post_and_saving_it_to_the_database(self): # start by create one Category category = Category() category.name = "First" category.slug = "first" category.save() # create new post post = Post() post.category = category post.title = "First post" post.content = "Content" post.visable = True # check we can save it post.save() # check slug self.assertEquals(post.slug, "first-post") # now check we can find it in the database all_post_in_database = Post.objects.all() self.assertEquals(len(all_post_in_database), 1) only_post_in_database = all_post_in_database[0] self.assertEquals(only_post_in_database, post) # check that it's saved all attributes: category, title, content, visable and generate slug self.assertEquals(only_post_in_database.category, category) self.assertEquals(only_post_in_database.title, post.title) self.assertEquals(only_post_in_database.content, post.content) self.assertEquals(only_post_in_database.visable, post.visable) self.assertEquals(only_post_in_database.slug, post.slug)