Ejemplo n.º 1
0
    def test_index(self):
        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'pass')
        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.site = site
        post.author = author
        post.pub_date = timezone.now()
        post.save()

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

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

        # check the post title is in the response
        self.assertTrue(post.title in response.content)

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

        self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
Ejemplo n.º 2
0
    def test_edit_post(self):
        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'pass')
        author.save()

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

        # Create the category
        category = Category()
        category.name = 'Python'
        category.description = 'Python is a rad language'
        category.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.site = site
        post.pub_date = timezone.now()
        post.author = author
        post.category = category
        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': '2014-05-06',
            'pub_date_1': '22:00:04',
            'slug': 'my-second-post',
            'site': 1,
            'author': 1,
            'category': 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')
Ejemplo n.º 3
0
    def test_category_page(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.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.category = category
        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 category URL
        category_url = post.category.get_absolute_url()

        # Fetch the category
        response = self.client.get(category_url)
        self.assertEquals(response.status_code, 200)

        # Check the category name is in the response
        self.assertTrue(post.category.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)
Ejemplo n.º 4
0
    def test_delete_post(self):
        #create author
        author = User.objects.create_user('testuser', '*****@*****.**', 'pass')
        author.save()

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

        # Create the category
        category = Category()
        category.name = 'Python'
        category.description = 'Python is a rad language'
        category.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.site = site
        post.pub_date = timezone.now()
        post.author = author
        post.category = category
        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 amended
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 0)
Ejemplo n.º 5
0
    def test_create_post(self):
        # Create the author
        author = User.objects.create_user('testuser', '*****@*****.**', 'pass')
        author.save()

        # Create the category
        category = Category()
        category.name = 'Python'
        category.description = 'Python is a rad dynamic programming language'
        category.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. Hope you like this thing'
        post.slug = 'my-first-post'
        post.site = site
        post.pub_date = timezone.now()
        post.author = author
        post.category = category
        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. Hope you like this thing')
        self.assertEquals(only_post.pub_date.day, post.pub_date.day)
        # Skip month year, hour and 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, 'Python is a rad dynamic programming language')