Example #1
0
    def test_edit_category(self):
        # Create the category

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

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

        # Edit the category
        response = self.client.post('/admin/blogengine/category/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 category amended
        all_categories = Category.objects.all()
        self.assertEquals(len(all_categories), 1)
        only_category = all_categories[0]
        self.assertEquals(only_category.name, 'perl')
        self.assertEquals(only_category.description, 'The Perl programming language')
Example #2
0
    def test_create_post(self):
        #log in
        self.client.login(username='******', password="******")

        # Create the category
        category = Category()
        category.name = 'Python'
        category.description = 'Python is a rad language'
        category.save()

        #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': '2014-04-06',
            'pub_date_1': '22:00:04',
            'slug': 'my-first-post',
            'site': 1,
            'author': 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)
Example #3
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')
Example #4
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)
Example #5
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)
Example #6
0
    def test_create_category(self):
        # Create Post Category
        category = Category()

        # fill the category attributes
        category.name = 'Python'
        category.description = 'Python is a rad dynamic programming language'
        category.save()

        # Now test category creation
        all_categories = Category.objects.all()
        self.assertEquals(len(all_categories), 1)
        only_category = all_categories[0]
        self.assertEquals(only_category, category)

        #check Attributes 
        self.assertEquals(only_category.name, 'Python')
        self.assertEquals(only_category.description, 'Python is a rad dynamic programming language')
Example #7
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')
Example #8
0
    def test_delete_category(self):
        # Create the category
        category = Category()
        category.name = 'python'
        category.description = 'The Python programming language'
        category.save()

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

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

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

        # Check category deleted
        all_categories = Category.objects.all()
        self.assertEquals(len(all_categories), 0)