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


Python GroupFactory.has_member方法代码示例

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


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

示例1: TestGroupRemoveMember

# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import has_member [as 别名]
class TestGroupRemoveMember(TestCase):
    def setUp(self):
        self.group = GroupFactory()
        self.member = UserFactory()
        self.group.add_member(self.member.userprofile)
        with override_script_prefix('/en-US/'):
            self.url = reverse('groups:remove_member',
                               kwargs={'url': self.group.url,
                                       'user_pk': self.member.userprofile.pk})

    def test_as_manager(self):
        # manager can remove another from a group they're not curator of
        user = UserFactory(manager=True)
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member.userprofile))

    def test_as_manager_from_unleavable_group(self):
        # manager can remove people even from unleavable groups
        user = UserFactory(manager=True)
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member.userprofile))

    def test_as_manager_removing_curator(self):
        # but even manager cannot remove a curator
        user = UserFactory(manager=True)
        self.group.curators.add(self.member.userprofile)
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(self.group.has_member(self.member.userprofile))

    def test_as_simple_user_removing_self(self):
        # user can remove themselves
        with self.login(self.member) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member.userprofile))

    def test_as_simple_user_removing_self_from_unleavable_group(self):
        # user cannot leave an unleavable group
        self.group.members_can_leave = False
        self.group.save()
        with self.login(self.member) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(self.group.has_member(self.member.userprofile))

    def test_as_simple_user_removing_another(self):
        # user cannot remove anyone else
        user = UserFactory()
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(404, response.status_code)

    def test_as_curator(self):
        # curator can remove another
        curator = UserFactory()
        self.group.curators.add(curator.userprofile)
        with self.login(curator) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member.userprofile))

    def test_as_curator_twice(self):
        # removing a second time doesn't blow up
        curator = UserFactory()
        self.group.curator = curator.userprofile
        self.group.save()
        with self.login(curator) as client:
            client.post(self.url, follow=False)
            client.post(self.url, follow=False)

    def test_as_curator_from_unleavable(self):
        # curator can remove another even from an unleavable group
        self.group.members_can_leave = False
        self.group.save()
        curator = UserFactory()
        self.group.curators.add(curator.userprofile)
        with self.login(curator) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member.userprofile))

    def test_accepting_sends_email(self):
        # when curator accepts someone, they are sent an email
        curator = UserFactory()
        self.group.curators.add(curator.userprofile)
        user = UserFactory()
        self.group.add_member(user.userprofile, GroupMembership.PENDING)
        # no email when someone makes membership request
        eq_(0, len(mail.outbox))
        # Using French for curator page to make sure that doesn't affect the language
        # that is used to email the member.
        with override_script_prefix('/fr/'):
            url = reverse('groups:confirm_member', args=[self.group.url, user.userprofile.pk])
        with patch('mozillians.groups.models.email_membership_change',
#.........这里部分代码省略.........
开发者ID:akatsoulas,项目名称:mozillians,代码行数:103,代码来源:test_membership.py

示例2: TestGroupRemoveMember

# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import has_member [as 别名]
class TestGroupRemoveMember(TestCase):
    def setUp(self):
        self.group = GroupFactory()
        self.member = UserFactory(userprofile={"is_vouched": True})
        self.group.add_member(self.member.userprofile)
        self.url = reverse(
            "groups:remove_member",
            prefix="/en-US/",
            kwargs={"group_pk": self.group.pk, "user_pk": self.member.userprofile.pk},
        )

    def test_as_superuser(self):
        # superuser can remove another from a group they're not curator of
        user = UserFactory(is_superuser=True, userprofile={"is_vouched": True})
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member))

    def test_as_superuser_from_unleavable_group(self):
        # superuser can remove people even from unleavable groups
        user = UserFactory(is_superuser=True, userprofile={"is_vouched": True})
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member))

    def test_as_superuser_removing_curator(self):
        # but even superuser cannot remove a curator
        user = UserFactory(is_superuser=True, userprofile={"is_vouched": True})
        self.group.curator = self.member.userprofile
        self.group.save()
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(self.group.has_member(self.member))

    def test_as_simple_user_removing_self(self):
        # user can remove themselves
        with self.login(self.member) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member))

    def test_as_simple_user_removing_self_from_unleavable_group(self):
        # user cannot leave an unleavable group
        self.group.members_can_leave = False
        self.group.save()
        with self.login(self.member) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(self.group.has_member(self.member))

    def test_as_simple_user_removing_another(self):
        # user cannot remove anyone else
        user = UserFactory(userprofile={"is_vouched": True})
        with self.login(user) as client:
            response = client.post(self.url, follow=False)
        eq_(404, response.status_code)

    def test_as_curator(self):
        # curator can remove another
        curator = UserFactory(userprofile={"is_vouched": True})
        self.group.curator = curator.userprofile
        self.group.save()
        with self.login(curator) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member))

    def test_as_curator_twice(self):
        # removing a second time doesn't blow up
        curator = UserFactory(userprofile={"is_vouched": True})
        self.group.curator = curator.userprofile
        self.group.save()
        with self.login(curator) as client:
            client.post(self.url, follow=False)
            client.post(self.url, follow=False)

    def test_as_curator_from_unleavable(self):
        # curator can remove another even from an unleavable group
        self.group.members_can_leave = False
        self.group.save()
        curator = UserFactory(userprofile={"is_vouched": True})
        self.group.curator = curator.userprofile
        self.group.save()
        with self.login(curator) as client:
            response = client.post(self.url, follow=False)
        eq_(302, response.status_code)
        ok_(not self.group.has_member(self.member))

    def test_accepting_sends_email(self):
        # when curator accepts someone, they are sent an email
        curator = UserFactory(userprofile={"is_vouched": True})
        self.group.curator = curator.userprofile
        self.group.save()
        user = UserFactory(userprofile={"is_vouched": True})
        self.group.add_member(user.userprofile, GroupMembership.PENDING)
        # no email when someone makes membership request
        eq_(0, len(mail.outbox))
#.........这里部分代码省略.........
开发者ID:venksv,项目名称:mozillians,代码行数:103,代码来源:test_membership.py


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