本文整理汇总了Python中streetsign_server.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one_user_group_write_and_publish
def test_one_user_group_write_and_publish(self):
f = Feed(name='123')
f.save()
u = User(passwordhash='123')
u.save()
g = Group(name='usergroup')
g.save()
g.set_users([u.id])
self.assertEqual(f.authors(), [])
self.assertEqual(f.publishers(), [])
self.assertEqual(f.author_groups(), [])
self.assertEqual(f.publisher_groups(), [])
self.assertFalse(f.user_can_write(u))
self.assertFalse(f.user_can_publish(u))
f.grant('Write', group=g)
f.grant('Publish', group=g)
f = Feed.get(id=f.id)
self.assertEqual(f.authors(), [])
self.assertEqual(f.publishers(), [])
self.assertEqual(f.author_groups(), [g])
self.assertEqual(f.publisher_groups(), [g])
self.assertTrue(f.user_can_write(u))
self.assertTrue(f.user_can_publish(u))
示例2: test_admin_can_delete_user
def test_admin_can_delete_user(self):
self.login(ADMINNAME, ADMINPASS)
resp = self.post_delete_request()
self.assertEqual(resp.status_code, 200)
with self.assertRaises(User.DoesNotExist):
User.get(id=self.user2.id)
示例3: test_one_user_group_read_only
def test_one_user_group_read_only(self):
f = Feed(name='123')
f.save()
u = User(passwordhash='123')
u.save()
g = Group(name='usergroup')
g.set_users([u.id])
g.save()
self.assertEqual(f.authors(), [])
self.assertEqual(f.publishers(), [])
self.assertEqual(f.author_groups(), [])
self.assertEqual(f.publisher_groups(), [])
self.assertFalse(f.user_can_write(u))
self.assertFalse(f.user_can_publish(u))
f.grant('Read', group=g)
self.assertEqual(f.authors(), [])
self.assertEqual(f.publishers(), [])
self.assertEqual(f.author_groups(), [])
self.assertEqual(f.publisher_groups(), [])
self.assertFalse(f.user_can_write(u))
self.assertFalse(f.user_can_publish(u))
示例4: test_user_with_no_perms
def test_user_with_no_perms(self):
u = User(passwordhash='123')
f = Feed()
u.save()
f.save()
self.assertEqual(u.writeable_feeds(), [])
示例5: test_admin_needs_password_to_create_user
def test_admin_needs_password_to_create_user(self):
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
self.login(ADMINNAME, ADMINPASS)
resp = self.post_create_request()
self.assertIn("You need to enter your current password", resp.data)
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
示例6: test_admin_can_create_user
def test_admin_can_create_user(self):
# should not yet exist:
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
self.login(ADMINNAME, ADMINPASS)
resp = self.post_create_request(currpass=ADMINPASS)
self.assertEqual(resp.status_code, 200)
User.get(loginname="user2")
示例7: test_user_with_one_feed
def test_user_with_one_feed(self):
u = User(passwordhash='123')
f = Feed()
u.save()
f.save()
f.grant('Write', user=u)
self.assertEqual(u.writeable_feeds(), [f])
示例8: test_new_user_passwords_must_match
def test_new_user_passwords_must_match(self):
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
self.login(ADMINNAME, ADMINPASS)
resp = self.post_create_request(currpass=ADMINPASS,
newpass='stuff',
conf_newpass='42')
self.assertIn("Passwords don't match", resp.data)
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
示例9: test_cannot_have_empty_password
def test_cannot_have_empty_password(self):
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
self.login(ADMINNAME, ADMINPASS)
resp = self.post_create_request(currpass=ADMINPASS,
newpass='',
conf_newpass='')
self.assertIn("Cannot Save", resp.data)
self.assertIn("passwordhash", resp.data)
with self.assertRaises(User.DoesNotExist):
User.get(loginname="user2")
示例10: test_admin_can_unset_admin
def test_admin_can_unset_admin(self):
self.assertFalse(self.user.is_admin)
self.user.is_admin = True
self.user.save()
usernow = User.get(id=self.user.id)
self.assertTrue(usernow.is_admin)
self.login(ADMINNAME, ADMINPASS)
resp = self.post_update_request(userid=self.user.id, is_admin=False)
usernow = User.get(id=self.user.id)
self.assertFalse(usernow.is_admin)
示例11: setUp
def setUp(self):
super(BasicUsersTestCase, self).setUp()
self.user = User(loginname=USERNAME,
emailaddress='[email protected]',
is_admin=False)
self.user.set_password(USERPASS)
self.user.save()
self.admin = User(loginname=ADMINNAME,
emailaddress='[email protected]',
is_admin=True)
self.admin.set_password(ADMINPASS)
self.admin.save()
示例12: test_user_with_one_feed_via_group
def test_user_with_one_feed_via_group(self):
u = User(passwordhash='123')
g = Group(name='group_with_a_name')
f = Feed()
u.save()
f.save()
g.save()
g.set_users([u.id])
f.grant('Write', group=g)
self.assertEqual(u.writeable_feeds(), [f])
示例13: test_admin_can_make_admin_with_on
def test_admin_can_make_admin_with_on(self):
self.assertFalse(self.user.is_admin)
self.login(ADMINNAME, ADMINPASS)
resp = self.post_update_request(userid=self.user.id, is_admin="on")
usernow = User.get(id=self.user.id)
self.assertTrue(usernow.is_admin)
示例14: group
def group(groupid):
''' edit one user group. '''
try:
thisgroup = Group.get(id=groupid)
except:
flash('Invalid group ID')
return redirect(request.referrer if request.referrer else '/')
if request.method == 'POST':
if request.form.get('action', 'none') == 'delete':
UserGroup.delete().where(UserGroup.group == thisgroup).execute()
thisgroup.delete_instance()
flash('group:'+ thisgroup.name +' deleted.')
return redirect(url_for('users_and_groups'))
if request.form.get('action', 'none') == 'update':
thisgroup.name = request.form.get('groupname', thisgroup.name)
thisgroup.save()
groupusers = request.form.getlist('groupusers')
thisgroup.set_users(groupusers)
flash('saved')
return render_template('group.html', group=thisgroup, allusers=User.select())
示例15: test_one_user_publish
def test_one_user_publish(self):
f = Feed(name='123')
f.save()
u = User(passwordhash='123')
u.save()
f.grant('Publish', user=u)
self.assertEqual(f.authors(), [])
self.assertEqual(f.publishers(), [u])
self.assertEqual(f.author_groups(), [])
self.assertEqual(f.publisher_groups(), [])
self.assertFalse(f.user_can_write(u))
self.assertTrue(f.user_can_publish(u))