本文整理汇总了Python中misago.threads.models.Thread.move方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.move方法的具体用法?Python Thread.move怎么用?Python Thread.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misago.threads.models.Thread
的用法示例。
在下文中一共展示了Thread.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import move [as 别名]
#.........这里部分代码省略.........
post = Post.objects.create(
forum=self.forum,
thread=self.thread,
poster=user,
poster_name=user.username,
poster_ip='127.0.0.1',
original="Hello! I am test message!",
parsed="<p>Hello! I am test message!</p>",
checksum="nope",
posted_on=datetime,
updated_on=datetime)
self.thread.set_first_post(post)
self.assertEqual(self.thread.first_post, post)
self.assertEqual(self.thread.started_on, post.posted_on)
self.assertEqual(self.thread.starter, user)
self.assertEqual(self.thread.starter_name, user.username)
self.assertEqual(self.thread.starter_slug, user.slug)
def test_set_last_post(self):
"""set_last_post sets first post and poster data on thread"""
User = get_user_model()
user = User.objects.create_user("Bob", "[email protected]", "Pass.123")
datetime = timezone.now() + timedelta(5)
post = Post.objects.create(
forum=self.forum,
thread=self.thread,
poster=user,
poster_name=user.username,
poster_ip='127.0.0.1',
original="Hello! I am test message!",
parsed="<p>Hello! I am test message!</p>",
checksum="nope",
posted_on=datetime,
updated_on=datetime)
self.thread.set_last_post(post)
self.assertEqual(self.thread.last_post, post)
self.assertEqual(self.thread.last_post_on, post.posted_on)
self.assertEqual(self.thread.last_poster, user)
self.assertEqual(self.thread.last_poster_name, user.username)
self.assertEqual(self.thread.last_poster_slug, user.slug)
def test_move(self):
"""move(new_forum) moves thread to other forum"""
# pick category instead of forum (so we don't have to create one)
new_forum = Forum.objects.filter(role="category")[:1][0]
self.thread.move(new_forum)
self.assertEqual(self.thread.forum, new_forum)
for post in self.thread.post_set.all():
self.assertEqual(post.forum_id, new_forum.id)
def test_merge(self):
"""merge(other_thread) moves other thread content to this thread"""
with self.assertRaises(ValueError):
self.thread.merge(self.thread)
datetime = timezone.now() + timedelta(5)
other_thread = Thread(
forum=self.forum,
weight=0,
started_on=datetime,
starter_name='Tester',
starter_slug='tester',
last_post_on=datetime,
last_poster_name='Tester',
last_poster_slug='tester')
other_thread.set_title("Other thread")
other_thread.save()
post = Post.objects.create(
forum=self.forum,
thread=other_thread,
poster_name='Admin',
poster_ip='127.0.0.1',
original="Hello! I am other message!",
parsed="<p>Hello! I am other message!</p>",
checksum="nope",
posted_on=datetime,
updated_on=datetime)
other_thread.first_post = post
other_thread.last_post = post
other_thread.save()
self.thread.merge(other_thread)
self.thread.synchronize()
self.assertEqual(self.thread.replies, 1)
self.assertEqual(self.thread.last_post, post)
self.assertEqual(self.thread.last_post_on, post.posted_on)
self.assertEqual(self.thread.last_poster_name, "Admin")
self.assertEqual(self.thread.last_poster_slug, "admin")
示例2: ThreadModelTests
# 需要导入模块: from misago.threads.models import Thread [as 别名]
# 或者: from misago.threads.models.Thread import move [as 别名]
#.........这里部分代码省略.........
self.thread.set_first_post(post)
self.assertEqual(self.thread.first_post, post)
self.assertEqual(self.thread.started_on, post.posted_on)
self.assertEqual(self.thread.starter, user)
self.assertEqual(self.thread.starter_name, user.username)
self.assertEqual(self.thread.starter_slug, user.slug)
def test_set_last_post(self):
"""set_last_post sets first post and poster data on thread"""
user = UserModel.objects.create_user("Bob", "[email protected]", "Pass.123")
datetime = timezone.now() + timedelta(5)
post = Post.objects.create(
category=self.category,
thread=self.thread,
poster=user,
poster_name=user.username,
poster_ip='127.0.0.1',
original="Hello! I am test message!",
parsed="<p>Hello! I am test message!</p>",
checksum="nope",
posted_on=datetime,
updated_on=datetime,
)
self.thread.set_last_post(post)
self.assertEqual(self.thread.last_post, post)
self.assertEqual(self.thread.last_post_on, post.posted_on)
self.assertEqual(self.thread.last_poster, user)
self.assertEqual(self.thread.last_poster_name, user.username)
self.assertEqual(self.thread.last_poster_slug, user.slug)
def test_move(self):
"""move(new_category) moves thread to other category"""
# pick category instead of category (so we don't have to create one)
root_category = Category.objects.root_category()
Category(
name='New Category',
slug='new-category',
).insert_at(
root_category,
position='last-child',
save=True,
)
new_category = Category.objects.get(slug='new-category')
self.thread.move(new_category)
self.assertEqual(self.thread.category, new_category)
for post in self.thread.post_set.all():
self.assertEqual(post.category_id, new_category.id)
def test_merge(self):
"""merge(other_thread) moves other thread content to this thread"""
with self.assertRaises(ValueError):
self.thread.merge(self.thread)
datetime = timezone.now() + timedelta(5)
other_thread = Thread(
category=self.category,
started_on=datetime,
starter_name='Tester',
starter_slug='tester',
last_post_on=datetime,