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


Python UserFactory.claim_messages方法代码示例

本文整理汇总了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)
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:13,代码来源:test_models.py

示例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())
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:53,代码来源:test_models.py


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