本文整理汇总了Python中myjobs.tests.factories.UserFactory.claim_messages方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.claim_messages方法的具体用法?Python UserFactory.claim_messages怎么用?Python UserFactory.claim_messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myjobs.tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.claim_messages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_message_made_sent_to_multiple
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import claim_messages [as 别名]
def test_message_made_sent_to_multiple(self):
"""
Test that one message can be received by multiple users.
"""
user = UserFactory(email="[email protected]")
user.groups.add(Group.objects.get(id=1))
user.claim_messages()
self.assertEqual(Message.objects.count(), 1)
self.assertEqual(MessageInfo.objects.count(), 2)
self.assertEqual(self.message,
self.user.messageinfo_set.get().message)
示例2: MessageManagerTests
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import claim_messages [as 别名]
class MessageManagerTests(MyJobsBase):
def setUp(self):
super(MessageManagerTests, self).setUp()
self.user = UserFactory()
self.user.groups.add(Group.objects.get(pk=1))
def test_create_message_by_group(self):
message = Message.objects.create_message(
subject='subject', body='message body',
groups=Group.objects.all())
self.user.claim_messages()
infos = self.user.messageinfo_set.all()
self.assertEqual(len(infos), 1)
self.assertEqual(infos[0].message, message)
def test_create_message_creates_messageinfo(self):
message = Message.objects.create_message(
users=self.user, subject='subject', body='message body')
infos = MessageInfo.objects.all()
self.assertEqual(infos.count(), 1)
self.assertEqual(infos[0].user, self.user)
self.assertEqual(infos[0].message, message)
def test_create_message_with_users_and_groups(self):
new_user = UserFactory(email='[email protected]')
message = Message.objects.create_message(
users=new_user, subject='subject', body='message body',
groups=Group.objects.get(pk=1))
[user.claim_messages() for user in [new_user, self.user]]
get_messages = lambda u: list(u.message_set.all())
group_user_messages = get_messages(self.user)
new_user_messages = get_messages(new_user)
self.assertEqual(group_user_messages, new_user_messages)
self.assertEqual(len(group_user_messages), 1)
self.assertEqual(group_user_messages[0], message)
def test_create_message_sets_expiration(self):
message = Message.objects.create_message(
subject='subject', body='message body',
groups=Group.objects.get(pk=1), expires=False)
self.assertTrue(message.expire_at is None)
self.user.claim_messages()
info = self.user.messageinfo_set.first()
self.assertFalse(info.expired_time())