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


Python Blog.delete方法代码示例

本文整理汇总了Python中models.Blog.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.delete方法的具体用法?Python Blog.delete怎么用?Python Blog.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Blog的用法示例。


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

示例1: BlogTestCase

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import delete [as 别名]
class BlogTestCase(TestCase):

    def setUp(self):
        self.c = Client()

    def test_bloginstall_redirect(self):
        #check that the blog redirects to install page when there is no blog installed    
        response = self.c.get(reverse("blogango_index"))
        self.assertEqual(response.status_code,302)
        #self.assertRedirects(response,reverse('blogango_install'))



    def test_single_existence(self):
        """Test that the blog is created only once """
        self.blog = Blog(title = "test",tag_line = "new blog",entries_per_page=10,recents = 5, recent_comments = 5)
        self.blog.save()
        blog = Blog(title = "test",tag_line = "new blog",entries_per_page=10,recents = 5, recent_comments = 5)
        #should raise Exception when another blog is created
        self.assertRaises(Exception,blog.save())
        self.blog.delete()
开发者ID:Anoopsmohan,项目名称:django-blogango,代码行数:23,代码来源:tests.py

示例2: TestViews

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import delete [as 别名]

#.........这里部分代码省略.........
        num_entries = 15
        for each in range(num_entries):
            BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        self.assertEqual(BlogEntry.objects.count(), 15)
        response = self.c.get(reverse('blogango_page', args=[1]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_page', args=[2]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_page', args=[3]))
        self.assertEqual(response.status_code, 302)

    def test_entries_slug(self):
        e1 = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        e2 = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        self.assertEqual(e1.slug, "test")
        self.assertEqual(e2.slug, "test-2")
        e1 = BlogEntry.objects.get(pk=e1.pk)
        e2 = BlogEntry.objects.get(pk=e2.pk)
        e1.save()
        self.assertEqual(e1.slug, "test")
        self.assertEqual(e2.slug, "test-2")
        e3 = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        self.assertEqual(e3.slug, "test-3")

    def test_tags_url(self):
        e1 = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        e2 = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        e1.tags.add("test1", "test2")
        e2.tags.add("test1")
        response = self.c.get(reverse('blogango_tag_details', args=['test1']))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['entries']), 2)
        response = self.c.get(reverse('blogango_tag_details', args=['test2']))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['entries']), 1)

    def test_entry_existence(self):
        """Test for the existence of entry"""
        BlogEntry.objects.create(**{'title': 'test post',
            'text': 'this is the test post',
            'publish_date': datetime.strptime("2011-09-22", "%Y-%m-%d"),
            'text_markup_type': "html",
            'created_by': self.user})
        response = self.c.get(reverse('blogango_details', args=['2011', '09', 'test-post']))
        self.assertEqual(response.status_code, 200)

    def test_add_comment(self):
        #test if a comment can be added to entry
        create_test_blog_entry(self.user)
        entry = BlogEntry.default.all()[0]
        reponse = self.c.post(entry.get_absolute_url(), {'name': 'gonecrazy', 'email': '[email protected]',
                                                          'text': 'this is a comment', 'button': 'Comment'})
        comment = Comment.objects.get(comment_for=entry)
        comments = Comment.objects.filter(comment_for=entry)
        self.assertEqual(comments.count(), 1)
        self.assertEqual(comment.text, 'this is a comment')

    def test_author_details(self):
        create_test_blog_entry(self.user)
        response = self.c.get("/blog/author/%s/" % self.user.username)
        entries = response.context['entries']
        self.assertEqual(1, entries.count())

    def test_author_entries_pagination(self):
        num_entries = 15
        for each in range(num_entries):
            BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                    publish_date=datetime.today(), text_markup_type='plain')
        self.assertEqual(BlogEntry.objects.count(), 15)
        response = self.c.get(reverse('blogango_author_page', args=[self.user.username, 1]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_author_page', args=[self.user.username, 2]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_author_page', args=[self.user.username, 3]))
        self.assertEqual(response.status_code, 302)

    def test_tagged_entries_pagination(self):
        num_entries = 15
        for each in range(num_entries):
            entry = BlogEntry.objects.create(title="test", text='foo', created_by=self.user,
                        publish_date=datetime.today(), text_markup_type='plain')
            entry.tags.add("taggit")
        tag = Tag.objects.get(name='taggit')
        self.assertEqual(BlogEntry.objects.count(), 15)
        response = self.c.get(reverse('blogango_tag_details_page', args=[tag.slug, 1]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_tag_details_page', args=[tag.slug, 2]))
        self.assertEqual(response.status_code, 200)
        response = self.c.get(reverse('blogango_tag_details_page', args=[tag.slug, 3]))
        self.assertEqual(response.status_code, 302)

    def tearDown(self):
        self.blog.delete()
        self.user.delete()
开发者ID:huan80s,项目名称:django-blogango,代码行数:104,代码来源:tests.py

示例3: User

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import delete [as 别名]
__author__ = 'fang'

from models import User, Blog, Comment

from transwarp import db

db.create_engine(user='root', password='password',database='awesome')

u = User(name='Administrato', email='[email protected]', password='1234567890', image='about:blank')

u.insert()
print 'new user:', u
u.delete()

b1 = Blog(user_id='0014347129972910bbdee0a188f412394d92e5e5a299939000', user_name='Administrator',
	name = 'FirstBlog', summary='Test', content = 'Test.')

b1.insert()
print 'new blog:', b1
b1.delete()



'''
u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name

u2 = User.find_first('where email=?', '[email protected]')
print 'find user:', u2
'''
开发者ID:cnu4,项目名称:awesome-blog,代码行数:32,代码来源:test_db.py


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