本文整理汇总了Python中access.models.Group类的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_edit_buttons
def test_edit_buttons(self):
"""Ensure admin/user edit buttons are shown."""
def get_links(id):
"""Grab profile, return edit links."""
url = reverse("users.profile", args=[id])
r = self.client.get(url)
return pq(r.content)("#profile-actions a")
# Anonymous user.
links = get_links(self.user.id)
eq_(links.length, 1)
eq_(links.eq(0).attr("href"), reverse("users.abuse", args=[self.user.id]))
# Non-admin, someone else's profile.
self.client.login(username="[email protected]", password="password")
links = get_links(9945)
eq_(links.length, 1)
eq_(links.eq(0).attr("href"), reverse("users.abuse", args=[9945]))
# Non-admin, own profile.
links = get_links(self.user.id)
eq_(links.length, 1)
eq_(links.eq(0).attr("href"), reverse("users.edit"))
# Admin, someone else's profile.
admingroup = Group(rules="Users:Edit")
admingroup.save()
GroupUser.objects.create(group=admingroup, user=self.user)
cache.clear()
# Admin, own profile.
links = get_links(self.user.id)
eq_(links.length, 2)
eq_(links.eq(0).attr("href"), reverse("users.edit"))
示例2: test_password_empty
def test_password_empty(self):
admingroup = Group(rules="Users:Edit")
admingroup.save()
GroupUser.objects.create(group=admingroup, user=self.user)
homepage = {"username": "jbalogh", "email": "[email protected]", "homepage": "http://cbc.ca", "lang": "en-US"}
res = self.client.post(self.url, homepage)
eq_(res.status_code, 302)
示例3: test_edit_buttons
def test_edit_buttons(self):
"""Ensure admin/user edit buttons are shown."""
def get_links(id):
"""Grab profile, return edit links."""
url = reverse('users.profile', args=[id])
r = self.client.get(url)
return PyQuery(r.content)('p.editprofile a')
# Anonymous user.
links = get_links(self.user.id)
eq_(links.length, 0)
# Non-admin, someone else's profile.
self.client.login(username='[email protected]', password='foo')
links = get_links(9945)
eq_(links.length, 0)
# Non-admin, own profile.
links = get_links(self.user.id)
eq_(links.length, 1)
eq_(links.eq(0).attr('href'), reverse('users.edit'))
# Admin, someone else's profile.
admingroup = Group(rules='Admin:EditAnyUser')
admingroup.save()
GroupUser.objects.create(group=admingroup, user=self.user_profile)
cache.clear()
示例4: test_my_account_menu
def test_my_account_menu(self):
def get_homepage():
response = self.client.get('/', follow=True)
return PyQuery(response.content)
# Logged out
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 0)
eq_(doc('#aux-nav .tools').length, 0)
# Logged in, regular user = one tools link
self.client.login(username='[email protected]', password='password')
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 1)
eq_(doc('#aux-nav ul.tools').length, 0)
eq_(doc('#aux-nav p.tools').length, 1)
# Logged in, admin = multiple links
admingroup = Group(rules='Admin:*')
admingroup.save()
GroupUser.objects.create(group=admingroup, user_id=4043307)
cache.clear()
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 1)
eq_(doc('#aux-nav ul.tools').length, 1)
eq_(doc('#aux-nav p.tools').length, 0)
示例5: test_password_empty
def test_password_empty(self):
admingroup = Group(rules='Users:Edit')
admingroup.save()
GroupUser.objects.create(group=admingroup, user=self.user)
homepage = {'username': 'jbalogh', 'email': '[email protected]',
'homepage': 'http://cbc.ca'}
res = self.client.post(self.url, homepage)
eq_(res.status_code, 302)