def test_create_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() self.client.login(username='******',password='******') response = self.client.get( '/admin/blogengine/post/add/') self.assertEquals(response.status_code,200) response = self.client.post('/admin/blogengine/post/add/',{ 'title':'My first Post', 'text' :'this is my first post text', 'pub_date_0':'2014-10-07', 'pub_date_1':'22:00:04', 'slug':'my-first-test', 'category': Category.objects.all()[0].id, 'tags':Tag.objects.all()[0].id, }, follow=True) self.assertEqual(response.status_code,200) self.assertTrue( 'success' in response.content ) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1)
def test_create_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() self.client.login(username='******', password='******') response = self.client.get('/admin/blogengine/post/add/') self.assertEquals(response.status_code, 200) response = self.client.post('/admin/blogengine/post/add/', { 'title': 'My first Post', 'text': 'this is my first post text', 'pub_date_0': '2014-10-07', 'pub_date_1': '22:00:04', 'slug': 'my-first-test', 'category': Category.objects.all()[0].id, 'tags': Tag.objects.all()[0].id, }, follow=True) self.assertEqual(response.status_code, 200) self.assertTrue('success' in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1)
def test_edit_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() #create tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() post = Post() post.title = 'My first Post' post.text = 'first blog post' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.client.login(username='******', password='******') url = '/admin/blogengine/post/%d/' % Post.objects.all()[0].id response = self.client.post(url, { 'title': 'my second post', 'text': 'this is my second post', 'pub_date_0': '2014-10-9', 'pub_date_1': '22:00:04', 'slug': 'my-first-test', 'category': Category.objects.all()[0].id, 'tags': Tag.objects.all()[0].id, }, follow=True) self.assertEquals(response.status_code, 200) self.assertTrue('changed successfully' in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) self.assertEquals(all_posts[0].title, 'my second post'), self.assertEquals(all_posts[0].text, 'this is my second post')
def test_edit_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create author author = User.objects.create_user('testuser','*****@*****.**','password') author.save() #create tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() post = Post() post.title = 'My first Post' post.text = 'first blog post' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.client.login(username='******',password='******') url = '/admin/blogengine/post/%d/' % Post.objects.all()[0].id response = self.client.post(url,{ 'title':'my second post', 'text':'this is my second post', 'pub_date_0':'2014-10-9', 'pub_date_1':'22:00:04', 'slug':'my-first-test', 'category': Category.objects.all()[0].id, 'tags' : Tag.objects.all()[0].id, },follow=True) self.assertEquals(response.status_code,200) self.assertTrue('changed successfully' in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts),1) self.assertEquals(all_posts[0].title,'my second post'), self.assertEquals(all_posts[0].text,'this is my second post')
def test_edit_category(self): category = Category() category.name = 'python' category.descritption = 'python' category.save() self.client.login(username='******',password='******') url = '/admin/blogengine/category/%d/' % Category.objects.all()[0].id r = self.client.post(url,{ 'name':'peee', 'description':'asdf' },follow=True) self.assertEquals(r.status_code,200) self.assertTrue( 'success' in r.content) self.assertEquals(len(Category.objects.all()),1) self.assertEquals(Category.objects.all()[0].name,'peee') self.assertEquals(Category.objects.all()[0].description,'asdf')
def test_post_page(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #tag tag = Tag() tag.name = 'python' tag.description = 'not perl' tag.save() #create author author = User.objects.create_user('adsf', '*****@*****.**', 'asdf') author.save() post = Post() post.title = 'my first page' post.text = 'This is my [first blog post](http://localhost:8000/)' post.pub_date = timezone.now() post.slug = 'my-first-post' post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEquals(len(Post.objects.all()), 1) self.assertEqual(Post.objects.all()[0], post) p = Post.objects.all()[0] p_url = p.get_absolute_url() r = self.client.get(p_url) self.assertEquals(r.status_code, 200) self.assertTrue(post.title in r.content) self.assertTrue(post.category.name in r.content) self.assertTrue(markdown.markdown(post.text) in r.content) self.assertTrue(str(post.pub_date.year) in r.content) self.assertTrue(str(post.pub_date.day) in r.content) self.assertTrue(tag.name in r.content) self.assertTrue('<a href="http://localhost:8000/">first blog post</a>' in r.content)
def test_edit_category(self): category = Category() category.name = 'python' category.descritption = 'python' category.save() self.client.login(username='******', password='******') url = '/admin/blogengine/category/%d/' % Category.objects.all()[0].id r = self.client.post(url, { 'name': 'peee', 'description': 'asdf' }, follow=True) self.assertEquals(r.status_code, 200) self.assertTrue('success' in r.content) self.assertEquals(len(Category.objects.all()), 1) self.assertEquals(Category.objects.all()[0].name, 'peee') self.assertEquals(Category.objects.all()[0].description, 'asdf')
def test_post_page(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #tag tag = Tag() tag.name = 'python' tag.description = 'not perl' tag.save() #create author author = User.objects.create_user('adsf','*****@*****.**','asdf') author.save() post = Post() post.title = 'my first page' post.text = 'This is my [first blog post](http://localhost:8000/)' post.pub_date = timezone.now() post.slug = 'my-first-post' post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEquals(len(Post.objects.all()),1) self.assertEqual(Post.objects.all()[0],post) p = Post.objects.all()[0] p_url = p.get_absolute_url() r = self.client.get(p_url) self.assertEquals(r.status_code,200) self.assertTrue(post.title in r.content) self.assertTrue(post.category.name in r.content) self.assertTrue(markdown.markdown(post.text) in r.content) self.assertTrue( str(post.pub_date.year) in r.content) self.assertTrue( str(post.pub_date.day) in r.content) self.assertTrue(tag.name in r.content) self.assertTrue( '<a href="http://localhost:8000/">first blog post</a>' in r.content)
def test_index(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create tag tag = Tag() tag.name = 'perl' tag.description = 'perl' tag.save() author = User.objects.create_user('test', '*****@*****.**', 'test') author.save() post = Post() post.title = 'first post' post.text = 'this is [my first blog post](http://localhost:8000/)' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEqual(len(Post.objects.all()), 1) r = self.client.get('/') self.assertEquals(r.status_code, 200) self.assertTrue(post.category.name in r.content) self.assertTrue(Tag.objects.all()[0].name in r.content) self.assertTrue(post.title in r.content) self.assertTrue(markdown.markdown(post.text) in r.content) self.assertTrue(str(post.pub_date.year) in r.content) self.assertTrue(str(post.pub_date.day) in r.content) #Check the link is makred down properly self.assertTrue( '<a href="http://localhost:8000/">my first blog post</a>' in r.content)
def test_index(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create tag tag = Tag() tag.name = 'perl' tag.description = 'perl' tag.save() author = User.objects.create_user('test','*****@*****.**','test') author.save() post = Post() post.title = 'first post' post.text = 'this is [my first blog post](http://localhost:8000/)' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEqual(len(Post.objects.all()),1) r = self.client.get('/') self.assertEquals(r.status_code,200) self.assertTrue( post.category.name in r.content) self.assertTrue( Tag.objects.all()[0].name in r.content) self.assertTrue( post.title in r.content) self.assertTrue( markdown.markdown(post.text) in r.content) self.assertTrue( str(post.pub_date.year) in r.content) self.assertTrue( str(post.pub_date.day) in r.content) #Check the link is makred down properly self.assertTrue('<a href="http://localhost:8000/">my first blog post</a>' in r.content)
def test_delete_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create user author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() #creat tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() post = Post() post.title = 'first' post.text = 'first text' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEquals(len(Post.objects.all()), 1) self.client.login(username='******', password='******') url = '/admin/blogengine/post/%d/delete/' % Post.objects.all()[0].id r = self.client.post(url, {'post': 'yes'}, follow=True) self.assertEquals(r.status_code, 200) self.assertEqual(len(Post.objects.all()), 0)
def test_delete_post(self): #create category category = Category() category.name = 'python' category.descritption = 'python' category.save() #create user author = User.objects.create_user('testuser','*****@*****.**','password') author.save() #creat tag tag = Tag() tag.name = 'python' tag.description = 'python' tag.save() post = Post() post.title = 'first' post.text = 'first text' post.pub_date = timezone.now() post.author = author post.category = category post.save() post.tags.add(tag) post.save() self.assertEquals( len(Post.objects.all()) ,1) self.client.login(username='******',password='******') url = '/admin/blogengine/post/%d/delete/' % Post.objects.all()[0].id r = self.client.post(url,{'post':'yes'},follow=True) self.assertEquals(r.status_code,200) self.assertEqual(len(Post.objects.all()),0)