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


Python UserFactory.__str__方法代码示例

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


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

示例1: UserModelTest

# 需要导入模块: from accounts.factories import UserFactory [as 别名]
# 或者: from accounts.factories.UserFactory import __str__ [as 别名]
class UserModelTest(TestCase):
    fixtures = ['group_perms']

    def setUp(self):
        self.moderator = ModeratorFactory()
        self.standard_user = UserFactory(
            first_name='Firsto',
            last_name='Namo',
        )
        self.invited_pending = InvitedPendingFactory()
        self.requested_pending = RequestedPendingFactory()

    def test_string_method(self):
        self.assertEqual(self.standard_user.__str__(), 'Firsto Namo')

    def test_get_full_name(self):
        full_name = self.standard_user.get_full_name()

        self.assertEqual(full_name, 'Firsto Namo')

    def test_get_short_name(self):
        short_name = self.standard_user.get_short_name()

        self.assertEqual(short_name, 'Firsto')

    def test_is_pending_activation(self):
        self.assertFalse(self.standard_user.is_pending_activation())
        self.assertTrue(self.invited_pending.is_pending_activation())

    def test_is_invited_pending_activation(self):
        self.assertFalse(self.standard_user.is_invited_pending_activation())
        self.assertTrue(self.invited_pending.is_invited_pending_activation())

    def test_is_pending_approval(self):
        self.assertFalse(self.standard_user.is_pending_approval())
        self.assertTrue(self.requested_pending.is_pending_approval())

    def test_moderator_can_invite_new_user(self):
        user = self.moderator.invite_new_user(email='[email protected]',
                                              first_name='standard_user',
                                              last_name='user')

        self.assertEqual(user.email,'[email protected]')
        self.assertEqual(user.first_name, 'standard_user')
        self.assertEqual(user.last_name, 'user')
        self.assertEqual(user.registration_method, CustomUser.INVITED)
        self.assertEqual(user.moderator, self.moderator)
        self.assertEqual(user.moderator_decision, CustomUser.PRE_APPROVED)
        self.assertIsNotNone(user.decision_datetime)
        self.assertIsNotNone(user.auth_token)

    def test_standard_user_user_cannot_invite_new_user(self):
        with self.assertRaises(PermissionDenied):
            user = self.standard_user.invite_new_user(
                email='[email protected]',
                first_name='standard_user',
                last_name='user'
            )

    def test_moderator_can_reinvite_user(self):
        decision_datetime = self.invited_pending.decision_datetime
        auth_token = self.invited_pending.auth_token

        self.moderator.reinvite_user(user=self.invited_pending,
                                     email='[email protected]')

        self.assertEqual(self.invited_pending.email, '[email protected]')
        self.assertNotEqual(self.invited_pending.decision_datetime, decision_datetime)
        self.assertNotEqual(self.invited_pending.auth_token, auth_token)

    def test_standard_user_user_cannot_reinvite_user(self):
        decision_datetime = self.invited_pending.decision_datetime
        auth_token = self.invited_pending.auth_token

        with self.assertRaises(PermissionDenied):
            self.standard_user.reinvite_user(user=self.invited_pending,
                                        email='[email protected]')

    def test_moderator_can_approve_user_application(self):
        self.moderator.approve_user_application(self.requested_pending)

        self.assertEqual(self.requested_pending.moderator, self.moderator)
        self.assertEqual(self.requested_pending.moderator_decision, CustomUser.APPROVED)
        self.assertIsNotNone(self.requested_pending.decision_datetime)
        self.assertIsNotNone(self.requested_pending.auth_token)

    def test_standard_user_user_cannot_approve_user_application(self):
        with self.assertRaises(PermissionDenied):
            self.standard_user.approve_user_application(self.requested_pending)

    def test_moderator_can_reject_user_application(self):
        self.moderator.reject_user_application(self.requested_pending)

        self.assertEqual(self.requested_pending.moderator, self.moderator)
        self.assertEqual(self.requested_pending.moderator_decision, CustomUser.REJECTED)
        self.assertIsNotNone(self.requested_pending.decision_datetime)
        self.assertIsNotNone(self.requested_pending.auth_token)

    def test_standard_user_user_cannot_reject_user_application(self):
        with self.assertRaises(PermissionDenied):
#.........这里部分代码省略.........
开发者ID:Natim,项目名称:connect,代码行数:103,代码来源:test_models.py


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