当前位置: 首页>>代码示例>>Python>>正文


Python models.Category类代码示例

本文整理汇总了Python中blogengine.models.Category的典型用法代码示例。如果您正苦于以下问题:Python Category类的具体用法?Python Category怎么用?Python Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_index

    def test_index(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', '[email protected]', '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.assertEqual(len(all_posts), 1)

        # Fetch the index
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)
开发者ID:n2o,项目名称:DjangoBlog,代码行数:35,代码来源:tests.py

示例2: test_category_page

	def test_category_page(self):
		category = Category()
		category.name = 'python'
		category.description = 'The Python programming language'
		category.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()

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

		category_url = post.category.get_absolute_url()

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

		self.assertTrue(post.category.name in response.content)
		self.assertTrue(post.title in response.content)
开发者ID:shaffer-wv,项目名称:django_blog,代码行数:33,代码来源:tests.py

示例3: test_create_post

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

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

        # Check response code
        response = self.client.get('/admin/blogengine/post/add/')
        self.assertEqual(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',
                'category': '1',
            },
            follow=True
        )
        self.assertEqual(response.status_code, 200)
开发者ID:n2o,项目名称:DjangoBlog,代码行数:26,代码来源:tests.py

示例4: test_all_post_feed

    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', '[email protected]', '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)
开发者ID:bhamhawker,项目名称:DjangoTutorialBlog,代码行数:60,代码来源:tests.py

示例5: test_create_post

    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='bobsmith',password='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)
开发者ID:paulw54jrn,项目名称:blog_tutorial,代码行数:35,代码来源:tests.py

示例6: test_edit_category

    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="bobsmith", password="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")
开发者ID:Zna12,项目名称:blog-project,代码行数:27,代码来源:tests.py

示例7: test_creat_post_without_tag

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

        # Log in
        self.client.login(username='bobsmith', password="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
        },
        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)
开发者ID:jwillet1,项目名称:djangoblog,代码行数:34,代码来源:tests.py

示例8: test_category_page

    def test_category_page(self):
        #create category
        cat = Category()
        cat.name = 'python'
        cat.description = 'python'
        cat.save()

        author = User.objects.create_user('testuser','[email protected]','password')
        author.save()

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

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

        cat_url = post.category.get_absolute_url()

        r = self.client.get(cat_url)
        self.assertEquals(r.status_code,200)

        self.assertTrue( post.category.name in r.content )
        self.assertTrue( markdown.markdown(post.text) in r.content)
开发者ID:paulw54jrn,项目名称:blog_tutorial,代码行数:29,代码来源:tests.py

示例9: test_edit_category

    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='bobsmith', password="password")

        # Edit the category
        response = self.client.post('/admin/blogengine/category/%s/' % category.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 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')
开发者ID:jwillet1,项目名称:djangoblog,代码行数:26,代码来源:tests.py

示例10: test_create_post

	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')
开发者ID:shaffer-wv,项目名称:django_blog,代码行数:59,代码来源:tests.py

示例11: test_post_page

    def test_post_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", "[email protected]", "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 post URL
        post_url = only_post.get_absolute_url()

        # Fetch the post
        response = self.client.get(post_url)
        self.assertEquals(response.status_code, 200)

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

        # Check the post category 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)
开发者ID:Zna12,项目名称:blog-project,代码行数:57,代码来源:tests.py

示例12: test_delete_post

    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', '[email protected]', '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='admintest', password="admintest")

        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)
开发者ID:4everer,项目名称:django_test,代码行数:56,代码来源:tests.py

示例13: test_edit_post

    def test_edit_post(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", "[email protected]", "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()

        # Log in
        self.client.login(username="bobsmith", password="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",
            },
            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")
开发者ID:Zna12,项目名称:blog-project,代码行数:55,代码来源:tests.py

示例14: test_create_post

    def test_create_post(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", "[email protected]", "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()

        # 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, "[email protected]")
        self.assertEquals(only_post.category.name, "python")
        self.assertEquals(only_post.category.description, "The Python programming language")
开发者ID:Zna12,项目名称:blog-project,代码行数:54,代码来源:tests.py

示例15: test_create_category

    def test_create_category(self):
        category = Category()

        category.name = 'python'
        category.description = 'the python programming language'
        category.save()

        self.assertEquals(len(Category.objects.all()),1)
        self.assertEquals(Category.objects.all()[0],category)
        c = Category.objects.all()[0]
        self.assertEquals(c.name,category.name)
        self.assertEqual(c.description,category.description)
开发者ID:paulw54jrn,项目名称:blog_tutorial,代码行数:12,代码来源:tests.py


注:本文中的blogengine.models.Category类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。