本文整理汇总了Python中mozillians.groups.tests.GroupFactory.add_member方法的典型用法代码示例。如果您正苦于以下问题:Python GroupFactory.add_member方法的具体用法?Python GroupFactory.add_member怎么用?Python GroupFactory.add_member使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozillians.groups.tests.GroupFactory
的用法示例。
在下文中一共展示了GroupFactory.add_member方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_member_counts
# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import add_member [as 别名]
def test_member_counts(self):
# The Group admin computes how many vouched members there are
# and how many overall
# IMPORTANT: This test is expected to fail on Postgres, and
# probably other databases where the Boolean type is not just
# an alias for a small integer. Mozillians is currently
# deployed on a database where this works. If we ever try
# deploying it on another database where it doesn't work, this
# test will alert us quickly that we'll need to take another
# approach to this feature.
# Create group with 1 vouched member and 1 unvouched member
group = GroupFactory()
user = UserFactory(userprofile={'is_vouched': False})
group.add_member(user.userprofile)
user2 = UserFactory(userprofile={'is_vouched': True})
group.add_member(user2.userprofile)
admin = GroupAdmin(model=Group, admin_site=site)
mock_request = Mock(spec=HttpRequest)
qset = admin.queryset(mock_request)
g = qset.get(name=group.name)
eq_(2, g.member_count)
eq_(1, g.vouched_member_count)
示例2: test_member_counts
# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import add_member [as 别名]
def test_member_counts(self):
group = GroupFactory()
user = UserFactory.create()
group.add_member(user.userprofile)
admin = GroupAdmin(model=Group, admin_site=site)
mock_request = Mock(spec=HttpRequest)
qset = admin.queryset(mock_request)
g = qset.get(name=group.name)
eq_(1, g.member_count)
示例3: test_list_groups
# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import add_member [as 别名]
def test_list_groups(self):
unvouched_user = UserFactory.create()
user = UserFactory.create(userprofile={"is_vouched": True})
group = GroupFactory()
group.add_member(unvouched_user.userprofile)
group.add_member(user.userprofile)
client = Client()
response = client.get(self.resource_url, follow=True)
data = json.loads(response.content)
eq_(data["meta"]["total_count"], 1)
eq_(data["objects"][0]["name"], group.name)
eq_(data["objects"][0]["number_of_members"], 1, "List includes unvouched users")
eq_(int(data["objects"][0]["id"]), group.id)
eq_(data["objects"][0]["url"], absolutify(reverse("groups:show_group", args=[group.url])))
示例4: TestGroupRemoveMember
# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import add_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',
#.........这里部分代码省略.........
示例5: TestGroupRemoveMember
# 需要导入模块: from mozillians.groups.tests import GroupFactory [as 别名]
# 或者: from mozillians.groups.tests.GroupFactory import add_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))
#.........这里部分代码省略.........