def test_create_post(self): label = Label() label.name = 'python' label.save() post = Post() post.title = 'Test post' post.save() post.abstract = 'Test Abstract' post.body = 'Post Body' post.slug = 'test-post' post.label = [1] post.publish = True post.created = timezone.now() post.modified = timezone.now() post.numofseen = 0 post.save() all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post, post) self.assertEquals(only_post.title, 'Test post') self.assertEquals(only_post.abstract, 'Test Abstract') self.assertEquals(only_post.body, post.body) self.assertEquals(only_post.slug, post.slug) self.assertEquals(only_post.label.get(), post.label.get()) self.assertEquals(only_post.created.day, post.created.day) self.assertEquals(only_post.created.month, post.created.month) self.assertEquals(only_post.created.year, post.created.year) self.assertEquals(only_post.created.hour, post.created.hour) self.assertEquals(only_post.created.minute, post.created.minute) self.assertEquals(only_post.created.second, post.created.second) self.assertEquals(only_post.modified, post.modified) self.assertEquals(only_post.numofseen, 0)
def test_index(self): label = Label() label.name = 'python' label.save() post = Post() post.title = 'Test post' post.save() post.abstract = 'Test Abstract' post.body = 'Post Body' post.slug = 'test-post' post.label = str(label.pk) post.publish = True post.created = timezone.now() post.modified = timezone.now() post.numofseen = 0 post.publish = True post.save() all_posts = Post.objects.all() self.assertEquals(len(all_posts),1) year = str(post.created.year) month = post.created.strftime('%b') day = str(post.created.day) response = self.client.get('/') self.assertEquals(response.status_code,200) self.assertTrue(str.encode(post.title) in response.content) self.assertTrue(str.encode(post.abstract) in response.content) self.assertTrue(str.encode(post.label.get().name) in response.content) self.assertTrue(str.encode(year) in response.content) self.assertTrue(str.encode(month) in response.content) self.assertTrue(str.encode(day) in response.content)
def test_delete_post(self): label = Label() label.name = 'python' label.save() post = Post() post.title = 'Test post' post.save() post.abstract = 'Test Abstract' post.body = 'Post Body' post.slug = 'test-post' post.label = [1] post.publish = True post.created = timezone.now() post.modified = timezone.now() post.numofseen = 0 post.save() all_posts = Post.objects.all() self.assertEquals(len(all_posts),1) self.client.login(username = '******', password = '******') response = self.client.post('/admin/blog/post/'+str(post.pk)+'/delete/',{ 'post':'yes'}, follow = True) self.assertEquals(response.status_code,200) self.assertTrue(str.encode('deleted successfully') in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts),0)
def test_detail(self): label = Label() label.name = 'python' label.save() post = Post() post.title = 'Test post' post.save() post.abstract = 'Test Abstract' post.body = 'Post Body' post.slug = 'test-post' post.label = str(label.pk) post.publish = True post.created = timezone.now() post.modified = timezone.now() post.numofseen = 0 post.publish = True post.save() all_posts = Post.objects.all() self.assertEquals(len(all_posts),1) response=self.client.get('/'+str(post.slug)) self.assertEquals(response.status_code,200) self.assertTrue(str.encode(post.body) in response.content)
def test_edit_post(self): label = Label() label.name = 'python' label.save() post = Post() post.title = 'Test post' post.save() post.abstract = 'Test Abstract' post.body = 'Post Body' post.slug = 'test-post' post.label = [1] post.publish = True post.created = timezone.now() post.modified = timezone.now() post.numofseen = 0 post.save() self.client.login(username = '******', password = '******') response = self.client.post('/admin/blog/post/'+str(post.pk)+'/', { 'title':'second test post', 'abstract':'second test abstract', 'body':'second test body', 'label':str(label.pk), 'slug':'second-test-post', 'numofseen':str(0) }, follow = True ) self.assertEquals(response.status_code,200) self.assertTrue(str.encode('changed successfully') in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post.title, 'second test post') self.assertEquals(only_post.body, 'second test body')