示例#1
0
    def test_tag_page(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        author = User.objects.create_user('testuser', '*****@*****.**',
                                          'password')
        author.save()

        post = Post()
        post.title = 'first post'
        post.text = 'fir post'
        post.slug = 'first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.save()
        post.tags.add(tag)
        post.save()

        self.assertEquals(len(Post.objects.all()), 1)
        self.assertEquals(Post.objects.all()[0], post)

        r = self.client.get(post.tags.all()[0].get_absolute_url(), follow=True)
        self.assertEquals(r.status_code, 200)
        self.assertTrue(tag.name in r.content)
        self.assertTrue(markdown.markdown(post.text) in r.content)
示例#2
0
    def test_edit_tag(self):
        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Edit the tag
        response = self.client.post('/admin/blogengine/tag/1/', {
            'name': 'perl',
            'description': 'The Perl programming language'
            }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check changed successfully
        self.assertTrue('changed successfully' in response.content)

        # Check tag amended
        all_tags = Tag.objects.all()
        self.assertEquals(len(all_tags), 1)
        only_tag = all_tags[0]
        self.assertEquals(only_tag.name, 'perl')
        self.assertEquals(only_tag.description, 'The Perl programming language')
示例#3
0
    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)
示例#4
0
    def test_tag_page(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        author = User.objects.create_user('testuser','*****@*****.**','password')
        author.save()

        post = Post()
        post.title = 'first post'
        post.text = 'fir post'
        post.slug = 'first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.save()
        post.tags.add(tag)
        post.save()

        self.assertEquals(len(Post.objects.all()),1)
        self.assertEquals(Post.objects.all()[0],post)

        r = self.client.get(post.tags.all()[0].get_absolute_url(),follow=True)
        self.assertEquals(r.status_code,200)
        self.assertTrue(tag.name in r.content)
        self.assertTrue(markdown.markdown(post.text) in  r.content)
示例#5
0
    def test_all_post_feed(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
 
        # Create a post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.category = category

        # Save it
        post.save()

        # Add the tag
        post.tags.add(tag)
        post.save()

        # Check we can find it
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Fetch the feed
        response = self.client.get('/feeds/posts/')
        self.assertEquals(response.status_code, 200)

        # Parse the feed
        feed = feedparser.parse(response.content)

        # Check length
        self.assertEquals(len(feed.entries), 1)

        # Check post retrieved is the correct one
        feed_post = feed.entries[0]
        self.assertEquals(feed_post.title, post.title)
        self.assertEquals(feed_post.description, post.text)
示例#6
0
    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)
示例#7
0
文件: tests.py 项目: daniel924/MyBlog
def CreateTag():
  # Create the tag
  tag = Tag()
  tag.name = 'python'
  tag.description = 'The Python programming language'
  tag.save()
  return tag
示例#8
0
    def test_edit_tag(self):
        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Edit the tag
        response = self.client.post('/admin/blogengine/tag/%s/' % tag.id, {
            'name': 'perl',
            'description': 'The Perl programming language'
        }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check changed successfully
        self.assertTrue('changed successfully' in response.content)

        # Check tag amended
        all_tags = Tag.objects.all()
        self.assertEquals(len(all_tags), 1)
        only_tag = all_tags[0]
        self.assertEquals(only_tag.name, 'perl')
        self.assertEquals(only_tag.description, 'The Perl programming language')
示例#9
0
	def test_create_post(self):
		category = Category()
		category.name = 'python'
		category.description = 'The Python programming language'
		category.save()

		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		site = Site()
		site.name = 'example.com'
		site.domain = 'example.com'
		site.save()

		post = Post()

		post.title = 'My first post'
		post.text = 'This is my first blog post'
		post.pub_date = timezone.now()
		post.slug = 'my-first-post'
		post.site = site
		post.category = category

		post.save()

		# Add tags
		post.tags.add(tag)
		post.save()

		# Retrieve new post
		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 1)
		only_post = all_posts[0]
		self.assertEquals(only_post, post)

		# Check attributes
		self.assertEquals(only_post.title, 'My first post')
		self.assertEquals(only_post.text, 'This is my first blog post')
		self.assertEquals(only_post.slug, 'my-first-post')
		self.assertEquals(only_post.site.name, 'example.com')
		self.assertEquals(only_post.site.domain, 'example.com')
		self.assertEquals(only_post.pub_date.day, post.pub_date.day)
		self.assertEquals(only_post.pub_date.month, post.pub_date.month)
		self.assertEquals(only_post.pub_date.year, post.pub_date.year)
		self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)
		self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)
		self.assertEquals(only_post.pub_date.second, post.pub_date.second)
		self.assertEquals(only_post.category.name, 'python')
		self.assertEquals(only_post.category.description, 'The Python programming language')

		# Check tags
		post_tags = only_post.tags.all()
		self.assertEquals(len(post_tags), 1)
		only_post_tag = post_tags[0]
		self.assertEquals(only_post_tag, tag)
		self.assertEquals(only_post_tag.name, 'python')
		self.assertEquals(only_post_tag.description, 'The Python programming language')
示例#10
0
    def test_delete_post(self):

        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the author
        author = User.objects.create_user(
            'testuser', '*****@*****.**', 'password')
        author.save()
        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.category = category
        post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        # Log in
        self.client.login(username='******', password="******")

        id_ = Post.objects.all()[0].id
        # Delete the post
        response = self.client.post(
            '/admin/blogengine/post/{0}/delete/'.format(id_),
            {
                'post': 'yes'
            }, follow=True)
        self.assertEquals(response.status_code, 200)
        # Check deleted successfully
        self.assertTrue('deleted successfully' in response.content)
        # Check post amended
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 0)
示例#11
0
    def test_delete_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
        
        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.site = site
        post.author = author
        post.category = category
        post.save()
        post.tags.add(tag)
        post.save()

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)

        # Log in
        self.client.login(username='******', password="******")

        # Delete the post
        response = self.client.post('/admin/blogengine/post/1/delete/', {
            'post': 'yes'
        }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check deleted successfully
        self.assertTrue('deleted successfully' in response.content)

        # Check post deleted
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 0)
示例#12
0
    def test_create_post(self):
        #create author
        author = User.objects.create_user('testuser', '*****@*****.**',
                                          'password')
        author.save()

        #create Category
        cat = Category()
        cat.name = 'python'
        cat.description = 'python'
        cat.save()

        #create tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        post = Post()

        title = "first blog"
        pub_date = timezone.now()
        text = "first blog text"

        post.text = text
        post.pub_date = pub_date
        post.title = title
        post.slug = 'first-post'
        post.author = author
        post.category = cat
        post.save()

        post.tags.add(tag)
        post.save()

        posts = Post.objects.all()
        self.assertEquals(len(posts), 1)

        p = posts[0]
        self.assertEquals(p, post)
        self.assertEqual(p.title, title)
        self.assertEqual(p.text, text)
        self.assertEqual(p.pub_date, pub_date)
        self.assertEquals(p.author.username, author.username)
        self.assertEquals(p.author.email, author.email)
        self.assertEquals(p.category.name, cat.name)
        self.assertEquals(p.category.description, cat.description)

        #check tags
        post_tags = p.tags.all()
        self.assertEqual(len(post_tags), 1)
        t = post_tags[0]
        self.assertEqual(t, tag)
        self.assertEqual(t.name, tag.name)
        self.assertEqual(t.description, tag.description)
示例#13
0
    def test_tag_page(self):
        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is [my first blog post](http://127.0.0.1:8000/)'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Get the tag
        tag_url = post.tags.all()[0].get_absolute_url()

        # Fetch the tag
        response = self.client.get(tag_url)
        self.assertEquals(response.status_code, 200)

        # Check the tag name is in the response
        self.assertTrue(post.tags.all()[0].name in response.content)

        # Check the post text is in the response
        self.assertTrue(markdown.markdown(post.text) in response.content)

        # Check the post date is in the response
        self.assertTrue(str(post.pub_date.year) in response.content)
        self.assertTrue(post.pub_date.strftime('%b') in response.content)
        self.assertTrue(str(post.pub_date.day) in response.content)

        # Check the link is marked up properly
        self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
示例#14
0
    def test_tag_page(self):
        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is [my first blog post](http://127.0.0.1:8000/)'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.save()
        post.tags.add(tag)

        # Check new post saved
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Get the tag URL
        tag_url = post.tags.all()[0].get_absolute_url()

        # Fetch the tag
        response = self.client.get(tag_url)
        self.assertEquals(response.status_code, 200)

        # Check the tag name is in the response
        self.assertTrue(post.tags.all()[0].name in response.content)

        # Check the post text is in the response
        self.assertTrue(markdown.markdown(post.text) in response.content)

        # Check the post date is in the response
        self.assertTrue(str(post.pub_date.year) in response.content)
        self.assertTrue(post.pub_date.strftime('%b') in response.content)
        self.assertTrue(str(post.pub_date.day) in response.content)

        # Check the link is marked up properly
        self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
示例#15
0
    def test_create_post(self):
        #create author
        author = User.objects.create_user('testuser','*****@*****.**','password')
        author.save()

        #create Category
        cat = Category()
        cat.name = 'python'
        cat.description = 'python'
        cat.save()

        #create tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        post = Post()

        title = "first blog"
        pub_date = timezone.now()
        text = "first blog text"

        post.text = text
        post.pub_date = pub_date
        post.title = title
        post.slug = 'first-post'
        post.author = author
        post.category = cat
        post.save()

        post.tags.add(tag)
        post.save()

        posts = Post.objects.all()
        self.assertEquals(len(posts),1)

        p = posts[0]
        self.assertEquals(p,post)
        self.assertEqual(p.title,title)
        self.assertEqual(p.text,text)
        self.assertEqual(p.pub_date,pub_date)
        self.assertEquals(p.author.username,author.username)
        self.assertEquals(p.author.email,author.email)
        self.assertEquals(p.category.name,cat.name)
        self.assertEquals(p.category.description,cat.description)

        #check tags
        post_tags = p.tags.all()
        self.assertEqual(len(post_tags),1)
        t = post_tags[0]
        self.assertEqual(t,tag)
        self.assertEqual(t.name,tag.name)
        self.assertEqual(t.description,tag.description)
示例#16
0
    def test_create_tag(self):
        tag = Tag()

        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.assertEqual(len(Tag.objects.all()), 1)
        t = Tag.objects.all()[0]
        self.assertEquals(t, tag)
        self.assertEquals(t.name, tag.name)
        self.assertEqual(t.description, tag.description)
示例#17
0
    def test_create_tag(self):
        tag = Tag()

        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.assertEqual(len(Tag.objects.all()),1)
        t = Tag.objects.all()[0]
        self.assertEquals(t,tag)
        self.assertEquals(t.name,tag.name)
        self.assertEqual(t.description,tag.description)
示例#18
0
	def test_create_tag(self):
		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		all_tags = Tag.objects.all()
		self.assertEquals(len(all_tags), 1)
		only_tag = all_tags[0]
		self.assertEquals(only_tag, tag)

		self.assertEquals(only_tag.name, 'python')
		self.assertEquals(only_tag.description, 'The Python programming language')
示例#19
0
    def test_delete_tag(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.client.login(username='******', password='******')
        url = '/admin/blogengine/tag/%d/delete/' % Tag.objects.all()[0].id

        r = self.client.post(url, {'post': 'yes'}, follow=True)

        self.assertEquals(r.status_code, 200)
        self.assertTrue('success' in r.content)
        self.assertEquals(len(Tag.objects.all()), 0)
示例#20
0
	def test_edit_post(self):
		category = Category()
		category.name = 'python'
		category.description = 'The Python programming language'
		category.save()

		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		site = Site()
		site.name = 'example.com'
		site.domain = 'example.com'
		site.save()

		post = Post()
		post.title = 'My first post'
		post.text = 'This is my first blog post'
		post.pub_date = timezone.now()
		post.slug = 'my-first-post'
		post.site = site
		post.save()
		post.tags.add(tag)
		post.save()

		self.client.login(username='******', password="******")

		# Edit post
		response = self.client.post('/admin/blogengine/post/1/', {
			'title': 'My second post',
			'text': 'This is my second blog post',
			'pub_date_0': '2013-12-28',
			'pub_date_1': '22:00:04',
			'slug': 'my-second-post',
			'site': '1',
			'category': '1',
			'tags': '1',
			},
			follow=True
			)
		self.assertEquals(response.status_code, 200)
		self.assertTrue('changed successfully' in response.content)

		# Check post amended
		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 1)
		only_post = all_posts[0]
		self.assertEquals(only_post.title, 'My second post')
		self.assertEquals(only_post.text, 'This is my second blog post')
示例#21
0
    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')
示例#22
0
	def test_individual_post(self):
		category = Category()
		category.name = 'python'
		category.description = 'The Python programming language'
		category.save()

		tag = Tag()
		tag.name = 'java'
		tag.description = 'The Java programming language'
		tag.save()

		site = Site()
		site.name = 'example.com'
		site.domain = 'example.com'
		site.save()

		post = Post()
		post.title = 'My first post'
		post.text = 'This is [my first blog post](http://127.0.0.1:8000/)'
		post.pub_date = timezone.now()
		post.slug = 'my-first-post'
		post.site = site
		post.category = category
		post.save()
		post.tags.add(tag)
		post.save()

		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 1)
		only_post = all_posts[0]
		self.assertEquals(only_post, post)

		post_url = only_post.get_absolute_url()

		response = self.client.get(post_url)
		self.assertEquals(response.status_code, 200)

		self.assertTrue(post.title in response.content)
		self.assertTrue(markdown.markdown(post.text) in response.content)
		self.assertTrue(post.category.name in response.content)

		post_tag = all_posts[0].tags.all()[0]
		self.assertTrue(post_tag.name in response.content)

		self.assertTrue(str(post.pub_date.year) in response.content)
		self.assertTrue(post.pub_date.strftime('%b') in response.content)
		self.assertTrue(str(post.pub_date.day) in response.content)

		self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
示例#23
0
    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')
示例#24
0
    def test_delete_tag(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.client.login(username='******', password='******')
        url = '/admin/blogengine/tag/%d/delete/' % Tag.objects.all()[0].id

        r = self.client.post(url, {
            'post': 'yes'
        }, follow=True)

        self.assertEquals(r.status_code, 200)
        self.assertTrue('success' in r.content)
        self.assertEquals(len(Tag.objects.all()), 0)
示例#25
0
文件: tests.py 项目: daniel924/MyBlog
 def test_create_tag(self):
   # Create the tag
   tag = Tag()
   # Add attributes
   tag.name = 'python'
   tag.description = 'The Python programming language'
   # Save it
   tag.save()
   # Check we can find it
   all_tags = Tag.objects.all()
   self.assertEquals(len(all_tags), 1)
   only_tag = all_tags[0]
   self.assertEquals(only_tag, tag)
   # Check attributes
   self.assertEquals(only_tag.name, 'python')
   self.assertEquals(only_tag.description, 'The Python programming language')
示例#26
0
    def test_create_post(self):

        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Check response code
        response = self.client.get('/admin/blogengine/post/add/')
        self.assertEquals(response.status_code, 200)

        # Create the new post
        cate_id = Category.objects.all()[0].id
        tags_id = Tag.objects.all()[0].id
        site_id = Site.objects.all()[0].id
        response = self.client.post('/admin/blogengine/post/add/', {
            'title': 'My first post',
            'text': 'This is my first post',
            'pub_date_0': '2013-12-28',
            'pub_date_1': '22:00:04',
            'slug': 'my-first-post',
            'category': str(cate_id),
            'site': str(site_id),
            'tags': str(tags_id),
        },
            follow=True
        )
        self.assertEquals(response.status_code, 200)
        # Check added successfullys
        # with open("../testResult.html", "w") as f:
        #     f.write(response.content)
        self.assertTrue('added successfully' in response.content)
        # Check new post now in database
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
示例#27
0
    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)
示例#28
0
    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)
示例#29
0
	def test_delete_tag(self):
		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		self.client.login(username='******', password="******")

		response = self.client.post('/admin/blogengine/tag/1/')
		self.assertEquals(response.status_code, 200)

		response = self.client.post('/admin/blogengine/tag/1/delete/', {
			'post': 'yes'
			}, follow=True)
		self.assertEquals(response.status_code, 200)
		self.assertTrue('deleted successfully' in response.content)

		all_tags = Tag.objects.all()
		self.assertEquals(len(all_tags), 0)
示例#30
0
    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)
示例#31
0
	def test_edit_tag(self):
		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		self.client.login(username='******', password="******")

		response = self.client.post('/admin/blogengine/tag/1/', {
			'name': 'java',
			'description': 'The Java programming language'
			}, follow=True)
		self.assertEquals(response.status_code, 200)
		self.assertTrue('changed successfully' in response.content)

		all_tags = Tag.objects.all()
		self.assertEquals(len(all_tags), 1)
		only_tag = all_tags[0]
		self.assertEquals(only_tag.name, 'java')
		self.assertEquals(only_tag.description, 'The Java programming language')
示例#32
0
文件: tests.py 项目: daniel924/MyBlog
  def test_delete_tag(self):
    # Create the tag
    tag = Tag()
    tag.name = 'python'
    tag.description = 'The Python programming language'
    tag.save()
    # Log in
    self.Login()
    # Delete the tag
    response = self.client.post('/admin/blogengine/tag/1/delete/', {
        'post': 'yes'
        }, follow=True)
    self.assertEquals(response.status_code, 200)

    # Check deleted successfully
    self.assertTrue('deleted successfully' in response.content)

    # Check tag deleted
    all_tags = Tag.objects.all()
    self.assertEquals(len(all_tags), 0)
示例#33
0
    def test_edit_tag(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.assertEquals(Tag.objects.all()[0], tag)
        self.assertEquals(len(Tag.objects.all()), 1)

        self.client.login(username='******', password='******')

        url = '/admin/blogengine/tag/%d/' % Tag.objects.all()[0].id
        r = self.client.post(url, {
            'name': 'perl',
            'description': 'perl'
        }, follow=True)
        self.assertEquals(len(Tag.objects.all()), 1)
        t = Tag.objects.all()[0]
        self.assertEquals(t.name, 'perl')
        self.assertEquals(t.description, 'perl')
示例#34
0
    def test_create_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Check response code
        response = self.client.get('/admin/blogengine/post/add/')
        self.assertEquals(response.status_code, 200)

        # Create the new post
        response = self.client.post('/admin/blogengine/post/add/', {
            'title': 'My first post',
            'text': 'This is my first post',
            'pub_date_0': '2013-12-28',
            'pub_date_1': '22:00:04',
            'slug': 'my-first-post',
            'site': '1',
            'category': '%s' % category.id ,
            'tags': '%s' % tag.id
        },
        follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check added successfully
        self.assertTrue('added successfully' in response.content)

        # Check new post now in database
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
示例#35
0
	def test_delete_post(self):
		category = Category()
		category.name = 'python'
		category.description = 'The Python programming language'
		category.save()

		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		site = Site()
		site.name = 'example.com'
		site.domain = 'example.com'
		site.save()

		post = Post()
		post.title = 'My first post'
		post.text = 'This is my first blog post'
		post.pub_date = timezone.now()
		post.slug = 'my-first-post'
		post.site = site
		post.category = category
		post.save()
		post.tags.add(tag)
		post.save()

		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 1)

		self.client.login(username='******', password="******")

		# Delete the post
		response = self.client.post('/admin/blogengine/post/1/delete/', {
			'post': 'yes'
			}, follow=True)
		self.assertEquals(response.status_code, 200)
		self.assertTrue('deleted successfully' in response.content)

		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 0)
示例#36
0
    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)
示例#37
0
    def test_create_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Check response code
        response = self.client.get('/admin/blogengine/post/add/')
        self.assertEquals(response.status_code, 200)

        # Create the new post
        response = self.client.post('/admin/blogengine/post/add/', {
            'title': 'My first post',
            'text': 'This is my first post',
            'pub_date_0': '2013-12-28',
            'pub_date_1': '22:00:04',
            'slug': 'my-first-post',
            'site': '1',
            'category': '1',
            'tags': '1'
        },
        follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check added successfully
        self.assertTrue('added successfully' in response.content)

        # Check new post now in database
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
示例#38
0
    def test_edit_tag(self):
        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        self.assertEquals(Tag.objects.all()[0], tag)
        self.assertEquals(len(Tag.objects.all()), 1)

        self.client.login(username='******', password='******')

        url = '/admin/blogengine/tag/%d/' % Tag.objects.all()[0].id
        r = self.client.post(url, {
            'name': 'perl',
            'description': 'perl'
        },
                             follow=True)
        self.assertEquals(len(Tag.objects.all()), 1)
        t = Tag.objects.all()[0]
        self.assertEquals(t.name, 'perl')
        self.assertEquals(t.description, 'perl')
示例#39
0
    def test_create_tag(self):
        # Create the tag
        tag = Tag()

        # Add attributes
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.slug = 'python'

        # Save it
        tag.save()

        # Check we can find it
        all_tags = Tag.objects.all()
        self.assertEquals(len(all_tags), 1)
        only_tag = all_tags[0]
        self.assertEquals(only_tag, tag)

        # Check attributes
        self.assertEquals(only_tag.name, 'python')
        self.assertEquals(only_tag.description, 'The Python programming language')
        self.assertEquals(only_tag.slug, 'python')
示例#40
0
    def test_delete_tag(self):
        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Log in
        self.client.login(username='******', password="******")

        # Delete the tag
        response = self.client.post('/admin/blogengine/tag/1/delete/', {
            'post': 'yes'
        }, follow=True)
        self.assertEquals(response.status_code, 200)

        # Check deleted successfully
        self.assertTrue('deleted successfully' in response.content)

        # Check tag deleted
        all_tags = Tag.objects.all()
        self.assertEquals(len(all_tags), 0)
示例#41
0
    def test_all_post_feed(self):
        cat = Category()
        cat.name = 'python'
        cat.description = 'python'
        cat.save()

        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        author = User.objects.create_user('example', '*****@*****.**',
                                          'password')
        author.save()

        post = Post()
        post.title = 'first post'
        post.text = 'first post text'
        post.slug = 'first-text'
        post.pub_date = timezone.now()
        post.author = author
        post.category = cat
        post.save()

        post.tags.add(tag)
        post.save()

        self.assertEquals(len(Post.objects.all()), 1)
        self.assertEquals(Post.objects.all()[0], post)

        r = self.client.get('/feeds/posts/')
        self.assertEqual(r.status_code, 200)

        feed = feedparser.parse(r.content)
        self.assertEqual(len(feed.entries), 1)

        self.assertEquals(feed.entries[0].title, post.title)
        self.assertEquals(feed.entries[0].description, post.text)
示例#42
0
	def test_tag_page(self):
		tag = Tag()
		tag.name = 'python'
		tag.description = 'The Python programming language'
		tag.save()

		site = Site()
		site.name = 'example.com'
		site.domain = 'example.com'
		site.save()

		post = Post()
		post.title = 'My first post'
		post.text = 'This is my first blog post'
		post.pub_date = timezone.now()
		post.slug = 'my-first-post'
		post.site = site
		post.save()
		post.tags.add(tag)
		post.save()

		all_posts = Post.objects.all()
		self.assertEquals(len(all_posts), 1)
		only_post = all_posts[0]
		self.assertEquals(only_post, post)

		tag_url = post.tags.all()[0].get_absolute_url()

		response = self.client.get(tag_url)
		self.assertEquals(response.status_code, 200)

		self.assertTrue(post.tags.all()[0].name in response.content)

		self.assertTrue(post.text in response.content)

		self.assertTrue(str(post.pub_date.year) in response.content)
		self.assertTrue(post.pub_date.strftime('%b') in response.content)
		self.assertTrue(str(post.pub_date.day) in response.content)
示例#43
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)
示例#44
0
    def test_all_post_feed(self):
        cat = Category()
        cat.name = 'python'
        cat.description = 'python'
        cat.save()

        tag = Tag()
        tag.name = 'python'
        tag.description = 'python'
        tag.save()

        author = User.objects.create_user('example','*****@*****.**','password')
        author.save()

        post = Post()
        post.title = 'first post'
        post.text = 'first post text'
        post.slug = 'first-text'
        post.pub_date = timezone.now()
        post.author = author
        post.category = cat
        post.save()

        post.tags.add(tag)
        post.save()

        self.assertEquals(len(Post.objects.all()),1)
        self.assertEquals(Post.objects.all()[0],post)

        r = self.client.get('/feeds/posts/')
        self.assertEqual(r.status_code,200)

        feed = feedparser.parse(r.content)
        self.assertEqual(len(feed.entries),1)

        self.assertEquals(feed.entries[0].title,post.title)
        self.assertEquals(feed.entries[0].description,post.text)
示例#45
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)
示例#46
0
    def test_create_post(self):
        # create category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # crate the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the post
        post = Post()

        # Set the attributes
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.category = category

        # Save it
        post.save()

        # add the tag
        post.tags.add(tag)
        post.save()

        # Check we can find it
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Check attributes
        self.assertEquals(only_post.title, 'My first post')
        self.assertEquals(only_post.text, 'This is my first blog post')
        self.assertEquals(only_post.slug, 'my-first-post')
        self.assertEquals(only_post.site.name, 'example.com')
        self.assertEquals(only_post.site.domain, 'example.com')
        self.assertEquals(only_post.pub_date.day, post.pub_date.day)
        self.assertEquals(only_post.pub_date.month, post.pub_date.month)
        self.assertEquals(only_post.pub_date.year, post.pub_date.year)
        self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)
        self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)
        self.assertEquals(only_post.pub_date.second, post.pub_date.second)
        self.assertEquals(only_post.author.username, 'testuser')
        self.assertEquals(only_post.author.email, '*****@*****.**')
        self.assertEquals(only_post.category.name, 'python')
        self.assertEquals(only_post.category.description, 'The Python programming language')

        # check tags
        post_tags = only_post.tags.all()
        self.assertEquals(len(post_tags), 1)
        only_post_tag = post_tags[0]
        self.assertEquals(only_post_tag, tag)
        self.assertEquals(only_post_tag.name, 'python')
        self.assertEquals(only_post_tag.description, 'The Python programming language')
示例#47
0
    def test_edit_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
        
        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

        # Log in
        self.client.login(username='******', password="******")

        # Edit the post
        response = self.client.post('/admin/blogengine/post/1/', {
            'title': 'My second post',
            'text': 'This is my second blog post',
            'pub_date_0': '2013-12-28',
            'pub_date_1': '22:00:04',
            'slug': 'my-second-post',
            'site': '1',
            'category': '1',
            'tags': '1'
        },
        follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check changed successfully
        self.assertTrue('changed successfully' in response.content)

        # Check post amended
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post.title, 'My second post')
        self.assertEquals(only_post.text, 'This is my second blog post')
示例#48
0
    def test_create_post(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'password')
        author.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()
        
        # Create the post
        post = Post()

        # Set the attributes
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.site = site
        post.category = category

        # Save it
        post.save()

        # Add the tag
        post.tags.add(tag)
        post.save()

        # Check we can find it
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Check attributes
        self.assertEquals(only_post.title, 'My first post')
        self.assertEquals(only_post.text, 'This is my first blog post')
        self.assertEquals(only_post.slug, 'my-first-post')
        self.assertEquals(only_post.site.name, 'example.com')
        self.assertEquals(only_post.site.domain, 'example.com')
        self.assertEquals(only_post.pub_date.day, post.pub_date.day)
        self.assertEquals(only_post.pub_date.month, post.pub_date.month)
        self.assertEquals(only_post.pub_date.year, post.pub_date.year)
        self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)
        self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)
        self.assertEquals(only_post.pub_date.second, post.pub_date.second)
        self.assertEquals(only_post.author.username, 'testuser')
        self.assertEquals(only_post.author.email, '*****@*****.**')
        self.assertEquals(only_post.category.name, 'python')
        self.assertEquals(only_post.category.description, 'The Python programming language')

        # Check tags
        post_tags = only_post.tags.all()
        self.assertEquals(len(post_tags), 1)
        only_post_tag = post_tags[0]
        self.assertEquals(only_post_tag, tag)
        self.assertEquals(only_post_tag.name, 'python')
        self.assertEquals(only_post_tag.description, 'The Python programming language')
示例#49
0
    def test_edit_post(self):

        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

        # Create the tag
        tag = Tag()
        tag.name = 'python'
        tag.description = 'The Python programming language'
        tag.save()

        # Create the site
        site = Site()
        site.name = 'example.com'
        site.domain = 'example.com'
        site.save()

        # Create the author
        author = User.objects.create_user(
            'testuser', '*****@*****.**', 'password')
        author.save()
        # Create the post
        post = Post()
        post.title = 'My first post'
        post.text = 'This is my first blog post'
        post.slug = 'my-first-post'
        post.pub_date = timezone.now()
        post.author = author
        post.category = category
        post.site = site
        post.save()
        post.tags.add(tag)
        post.save()

        # Log in
        self.client.login(username='******', password="******")

        id_ = Post.objects.all()[0].id
        cate_id = Category.objects.all()[0].id
        tags_id = Tag.objects.all()[0].id
        site_id = Site.objects.all()[0].id
        # Edit the post
        response = self.client.post(
            '/admin/blogengine/post/{0}/'.format(id_),
            {
                'title': 'My second post',
                'text': 'This is my second blog post',
                'pub_date_0': '2013-12-28',
                'pub_date_1': '22:00:04',
                'slug': 'my-second-post',
                'category': str(cate_id),
                'site': str(site_id),
                'tags': str(tags_id),
            },
            follow=True
        )
        self.assertEquals(response.status_code, 200)

        # Check changed successfully
        self.assertTrue('changed successfully' in response.content)
        # Check post amended
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post.title, 'My second post')
        self.assertEquals(only_post.text, 'This is my second blog post')