本文整理汇总了Python中machina.test.factories.GroupFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python GroupFactory.create方法的具体用法?Python GroupFactory.create怎么用?Python GroupFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machina.test.factories.GroupFactory
的用法示例。
在下文中一共展示了GroupFactory.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def setup(self):
self.loadstatement = '{% load forum_permission_tags %}'
self.request_factory = RequestFactory()
self.g1 = GroupFactory.create()
self.u1 = UserFactory.create()
self.u2 = UserFactory.create()
self.u1.groups.add(self.g1)
self.u2.groups.add(self.g1)
self.moderators = GroupFactory.create()
self.moderator = UserFactory.create()
self.moderator.groups.add(self.moderators)
self.superuser = UserFactory.create(is_superuser=True)
# Permission handler
self.perm_handler = PermissionHandler()
# Set up a top-level category
self.top_level_cat = create_category_forum()
# Set up some forums
self.forum_1 = create_forum(parent=self.top_level_cat)
self.forum_2 = create_forum(parent=self.top_level_cat)
# Set up some topics and posts
self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
示例2: test_knows_that_granted_permissions_should_take_precedence_over_the_same_non_granted_permissions
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def test_knows_that_granted_permissions_should_take_precedence_over_the_same_non_granted_permissions(self): # noqa: E501
# Setup
user = UserFactory.create()
group_all_users = GroupFactory.create()
group_specific_access = GroupFactory.create()
user.groups.add(group_all_users)
user.groups.add(group_specific_access)
assign_perm('can_read_forum', group_all_users, None) # global permission
assign_perm('can_read_forum', group_all_users, self.forum, has_perm=False)
assign_perm('can_read_forum', group_specific_access, self.forum, has_perm=True)
checker = ForumPermissionChecker(user)
# Run & check
assert checker.has_perm('can_read_forum', self.forum)
示例3: setup
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def setup(self):
# Add some users
self.u1 = UserFactory.create()
self.g1 = GroupFactory.create()
self.u1.groups.add(self.g1)
self.user.groups.add(self.g1)
# Permission handler
self.perm_handler = PermissionHandler()
self.top_level_cat_1 = create_category_forum()
self.forum_1 = create_forum(parent=self.top_level_cat_1)
self.forum_2 = create_forum(parent=self.top_level_cat_1)
self.forum_3 = create_forum(parent=self.top_level_cat_1)
self.topic_1 = create_topic(forum=self.forum_2, poster=self.u1)
PostFactory.create(topic=self.topic_1, poster=self.u1)
PostFactory.create(topic=self.topic_1, poster=self.user)
self.topic_2 = create_topic(forum=self.forum_1, poster=self.user)
PostFactory.create(topic=self.topic_2, poster=self.user)
PostFactory.create(topic=self.topic_2, poster=self.u1)
self.topic_3 = create_topic(forum=self.forum_2, poster=self.u1)
PostFactory.create(topic=self.topic_3, poster=self.u1)
self.topic_4 = create_topic(forum=self.forum_2, poster=self.user)
PostFactory.create(topic=self.topic_4, poster=self.user)
# Assign some permissions
assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
assign_perm('can_read_forum', self.g1, self.forum_1)
assign_perm('can_read_forum', self.g1, self.forum_2)
示例4: setUp
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def setUp(self):
self.loadstatement = '{% load forum_tracking_tags %}'
self.request_factory = RequestFactory()
# Tracking handler
self.tracks_handler = TrackingHandler()
self.g1 = GroupFactory.create()
self.u1 = UserFactory.create()
self.u2 = UserFactory.create()
self.u1.groups.add(self.g1)
self.u2.groups.add(self.g1)
# Set up a top-level category
self.top_level_cat = create_category_forum()
# Set up some forums
self.forum_1 = create_forum(parent=self.top_level_cat)
self.forum_2 = create_forum(parent=self.top_level_cat)
# Set up some topics and posts
self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u1)
self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u1)
# Assign some permissions
assign_perm('can_see_forum', self.g1, self.top_level_cat)
assign_perm('can_read_forum', self.g1, self.top_level_cat)
assign_perm('can_see_forum', self.g1, self.forum_1)
assign_perm('can_read_forum', self.g1, self.forum_1)
assign_perm('can_see_forum', self.g1, self.forum_2)
assign_perm('can_read_forum', self.g1, self.forum_2)
示例5: setup
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def setup(self):
self.u1 = UserFactory.create()
self.g1 = GroupFactory.create()
self.u1.groups.add(self.g1)
# Permission handler
self.perm_handler = PermissionHandler()
# Set up a top-level category
self.top_level_cat = create_category_forum()
# Set up some forums
self.forum_1 = create_forum(parent=self.top_level_cat)
self.forum_2 = create_forum(parent=self.top_level_cat)
self.forum_3 = create_link_forum(parent=self.top_level_cat)
# Set up a top-level forum link
self.top_level_link = create_link_forum()
# Set up some topics
self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
self.forum_3_topic = create_topic(forum=self.forum_3, poster=self.u1)
self.forum_3_topic_2 = create_topic(
forum=self.forum_3, poster=self.u1, status=Topic.TOPIC_LOCKED)
# Set up some posts
self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
self.post_2 = PostFactory.create(topic=self.forum_3_topic, poster=self.u1)
# Assign some permissions
assign_perm('can_see_forum', self.u1, self.top_level_cat)
assign_perm('can_see_forum', self.u1, self.forum_1)
assign_perm('can_read_forum', self.g1, self.forum_3)
示例6: setup
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def setup(self):
self.loadstatement = '{% load forum_polls_tags %}'
self.request_factory = RequestFactory()
self.g1 = GroupFactory.create()
self.u1 = UserFactory.create()
self.u2 = UserFactory.create()
self.u1.groups.add(self.g1)
self.u2.groups.add(self.g1)
self.moderators = GroupFactory.create()
self.moderator = UserFactory.create()
self.moderator.groups.add(self.moderators)
self.superuser = UserFactory.create(is_superuser=True)
# Permission handler
self.perm_handler = PermissionHandler()
# Set up a top-level category
self.top_level_cat = create_category_forum()
# Set up some forums
self.forum_1 = create_forum(parent=self.top_level_cat)
self.forum_2 = create_forum(parent=self.top_level_cat)
# Set up some topics and posts
self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
self.poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
self.poll_2 = TopicPollFactory.create(topic=self.forum_2_topic)
# Assign some permissions
assign_perm('can_see_forum', self.g1, self.forum_1)
assign_perm('can_read_forum', self.g1, self.forum_1)
assign_perm('can_edit_own_posts', self.g1, self.forum_1)
assign_perm('can_delete_own_posts', self.g1, self.forum_1)
assign_perm('can_reply_to_topics', self.g1, self.forum_1)
assign_perm('can_see_forum', self.moderators, self.forum_1)
assign_perm('can_read_forum', self.moderators, self.forum_1)
assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
assign_perm('can_edit_posts', self.moderators, self.forum_1)
assign_perm('can_delete_posts', self.moderators, self.forum_1)
assign_perm('can_vote_in_polls', self.g1, self.forum_1)
示例7: test_knows_that_user_permissions_take_precedence_over_group_permissions
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def test_knows_that_user_permissions_take_precedence_over_group_permissions(self):
# Setup
user = UserFactory.create()
group = GroupFactory.create()
user.groups.add(group)
assign_perm('can_read_forum', user, self.forum, has_perm=False)
assign_perm('can_read_forum', group, self.forum, has_perm=True)
checker = ForumPermissionChecker(user)
# Run & check
assert not checker.has_perm('can_read_forum', self.forum)
示例8: test_editpermission_index_view_can_redirect_to_group_permissions_form
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def test_editpermission_index_view_can_redirect_to_group_permissions_form(self):
# Setup
group = GroupFactory.create()
model = self.model
raw_url = 'admin:{}_{}_editpermission_index'.format(model._meta.app_label, self._get_module_name(model._meta))
# Run
url = reverse(raw_url, kwargs={'forum_id': self.top_level_cat.id})
response = self.client.post(url, {'group': group.id}, follow=True)
# Check
editpermissions_group_raw_url = 'admin:{}_{}_editpermission_group'.format(
model._meta.app_label, self._get_module_name(model._meta))
editpermissions_group_url = reverse(editpermissions_group_raw_url, kwargs={
'forum_id': self.top_level_cat.id, 'group_id': self.user.id})
assert len(response.redirect_chain)
last_url, status_code = response.redirect_chain[-1]
assert editpermissions_group_url in last_url
示例9: test_editpermission_index_view_can_copy_permissions_from_another_forum
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def test_editpermission_index_view_can_copy_permissions_from_another_forum(self):
# Setup
group = GroupFactory.create()
model = self.model
UserForumPermissionFactory.create(
permission=ForumPermission.objects.get(codename='can_see_forum'),
forum=self.sub_forum_1,
user=self.user, has_perm=False)
UserForumPermissionFactory.create(
permission=ForumPermission.objects.get(codename='can_read_forum'),
forum=self.sub_forum_1,
user=self.user, has_perm=True)
UserForumPermissionFactory.create(
permission=ForumPermission.objects.get(codename='can_start_new_topics'),
forum=self.sub_forum_1,
user=self.user, has_perm=False)
GroupForumPermissionFactory.create(
permission=ForumPermission.objects.get(codename='can_start_new_topics'),
forum=self.sub_forum_1,
group=group, has_perm=False)
raw_url = 'admin:{}_{}_editpermission_index'.format(
model._meta.app_label, self._get_module_name(model._meta))
# Run
url = reverse(raw_url, kwargs={'forum_id': self.top_level_cat.id})
response = self.client.post(url, {'forum': self.sub_forum_1.id})
# Check
assert response.status_code == 200
assert UserForumPermission.objects.filter(
permission__codename='can_see_forum', forum=self.top_level_cat,
user=self.user, has_perm=False).exists()
assert UserForumPermission.objects.filter(
permission__codename='can_read_forum', forum=self.top_level_cat,
user=self.user, has_perm=True).exists()
assert UserForumPermission.objects.filter(
permission__codename='can_start_new_topics', forum=self.top_level_cat,
user=self.user, has_perm=False).exists()
assert GroupForumPermission.objects.filter(
permission__codename='can_start_new_topics', forum=self.top_level_cat,
group=group, has_perm=False).exists()
示例10: test_editpermission_form_can_update_group_permissions
# 需要导入模块: from machina.test.factories import GroupFactory [as 别名]
# 或者: from machina.test.factories.GroupFactory import create [as 别名]
def test_editpermission_form_can_update_group_permissions(self):
# Setup
group = GroupFactory.create()
model = self.model
raw_url = 'admin:{}_{}_editpermission_group'.format(model._meta.app_label, self._get_module_name(model._meta))
post_data = {
'can_see_forum': 'granted',
'can_read_forum': 'not-granted',
'can_start_new_topics': 'not-set',
'can_reply_to_topics': 'not-set',
'can_post_announcements': 'not-set',
'can_post_stickies': 'not-set',
'can_delete_own_posts': 'not-set',
'can_edit_own_posts': 'not-set',
'can_post_without_approval': 'not-set',
'can_create_polls': 'not-set',
'can_vote_in_polls': 'not-set',
'can_attach_file': 'not-set',
'can_download_file': 'not-set',
'can_lock_topics': 'not-set',
'can_edit_posts': 'not-set',
'can_delete_posts': 'not-set',
'can_move_posts': 'not-set',
'can_approve_posts': 'not-set',
}
# Run
url = reverse(raw_url, kwargs={
'forum_id': self.top_level_cat.id, 'group_id': group.id})
response = self.client.post(url, post_data)
# Check
assert response.status_code == 200
granted_perm = GroupForumPermission.objects.filter(
permission__codename='can_see_forum', has_perm=True,
group=group, forum=self.top_level_cat)
assert granted_perm.exists()
not_granted_perm = GroupForumPermission.objects.filter(
permission__codename='can_read_forum', has_perm=False,
group=group, forum=self.top_level_cat)
assert not_granted_perm.exists()