本文整理汇总了Python中streetsign_server.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streetsign_server.models.User
的用法示例。
在下文中一共展示了User.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one_user_group_write_and_publish
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
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_one_user_group_read_only
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
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))
示例3: test_user_with_no_perms
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
def test_user_with_no_perms(self):
u = User(passwordhash='123')
f = Feed()
u.save()
f.save()
self.assertEqual(u.writeable_feeds(), [])
示例4: test_user_with_one_feed
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
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])
示例5: test_normal_user_cannot_set_other_to_admin
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
def test_normal_user_cannot_set_other_to_admin(self):
user2 = User(loginname="user2",
emailaddress='[email protected]',
is_admin=False)
user2.set_password("userpass2")
user2.save()
self.login(USERNAME, USERPASS)
resp = self.post_update_request(userid=user2.id, is_admin=True)
self.assertEqual(resp.status_code, 403)
usernow = User.get(id=user2.id)
self.assertEqual(usernow.is_admin, False)
示例6: test_user_with_one_feed_via_group
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
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])
示例7: BasicUsersTestCase
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
class BasicUsersTestCase(StreetSignTestCase):
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()
示例8: test_one_user_publish
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
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))
示例9: test_cannot_have_matching_usernames
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
def test_cannot_have_matching_usernames(self):
user2 = User(loginname='user2',
emailaddress='[email protected]',
is_admin=False)
user2.set_password(USERPASS)
user2.save()
# if this get works, then the user exists:
usernow = User.get(loginname="user2")
self.assertEqual(user2.id, usernow.id)
self.login(ADMINNAME, ADMINPASS)
resp = self.post_create_request(currpass=ADMINPASS,
newpass='not42', conf_newpass='not42')
self.assertIn("Username already exists", resp.data)
# and just make sure we didn't delete them, or set their password...
usernew = User.get(loginname="user2")
self.assertEqual(usernow.passwordhash, usernew.passwordhash)
示例10: test_cannot_change_other_users_password_even_with_their_currpass
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
def test_cannot_change_other_users_password_even_with_their_currpass(self):
user2 = User(loginname="user2",
emailaddress='[email protected]',
is_admin=False)
user2.set_password("userpass2")
user2.save()
self.login(USERNAME, USERPASS)
with self.ctx():
resp = self.client.post(url_for('user_edit', userid=user2.id),
data={"action":"update",
"newpass": "200",
"conf_newpass": "200",
"currpass": "userpass2"},
follow_redirects=True)
self.assertIn("Permission Denied", resp.data)
self.assertEquals(resp.status_code, 403)
usernow = User.get(id=user2.id)
self.assertEqual(usernow.passwordhash, user2.passwordhash)
示例11: user_edit
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
def user_edit(userid=-1):
''' edit one user. Admins can edit any user, but other users
can only edit themselves. if userid is -1, create a new user. '''
try:
current_user = user_session.get_user()
except user_session.NotLoggedIn as e:
flash("Sorry, you're not logged in!")
return permission_denied("You're not logged in!")
userid = int(userid)
if userid != -1:
try:
user = User.get(id=userid)
except User.DoesNotExist:
return not_found(title="User doesn't exist",
message="Sorry, that user does not exist!")
else:
if not current_user.is_admin:
flash('Sorry! Only admins can create new users!')
return permission_denied("Admins only!")
try:
user = User.get(loginname=request.form['loginname'])
return permission_denied("Username already exists!")
except peewee.DoesNotExist:
pass
user = User() #pylint: disable=no-value-for-parameter
if request.method == 'POST':
if current_user != user and not current_user.is_admin:
return permission_denied("Sorry, you may not edit this user.")
update_user(user, request.form, current_user)
# save:
try:
user.save()
if userid == -1:
flash('New user created.')
return redirect(url_for('user_edit', userid=user.id))
else:
flash('Saved')
except peewee.IntegrityError as err:
flash('Cannot Save:' + str(err))
elif request.method == 'DELETE':
if not current_user.is_admin:
return 'Sorry, only admins can delete users', 403
if user.id == current_user.id:
return 'Sorry! You cannot delete yourself!', 403
user.delete_instance(recursive=True)
return 'User: %s deleted. (And all their posts)' % user.displayname
users_posts = Post.select().where(Post.author == user) \
.order_by(Post.write_date.desc()) \
.limit(10)
return render_template('user.html',
allgroups=Group.select(),
posts=users_posts, user=user)
示例12: DeletingUsers
# 需要导入模块: from streetsign_server.models import User [as 别名]
# 或者: from streetsign_server.models.User import save [as 别名]
class DeletingUsers(BasicUsersTestCase):
''' Only admin can delete users, and not themselves. '''
def setUp(self):
super(DeletingUsers, self).setUp()
self.user2 = User(loginname='user2',
emailaddress='[email protected]',
is_admin=False)
self.user2.set_password(USERPASS)
self.user2.save()
def post_delete_request(self, userid=False, **kwargs):
data = {}
data.update(kwargs)
if userid == False:
userid = self.user2.id
with self.ctx():
return self.client.delete(url_for('user_edit', userid=userid),
data=data,
follow_redirects=True)
def test_logged_out_cannot_delete_user(self):
resp = self.post_delete_request()
self.assertEqual(resp.status_code, 403)
User.get(id=self.user2.id)
def test_normal_user_cannot_delete_user(self):
self.login(USERNAME, USERPASS)
resp = self.post_delete_request()
self.assertEqual(resp.status_code, 403)
User.get(id=self.user2.id)
def test_normal_user_cannot_delete_self(self):
self.login(USERNAME, USERPASS)
resp = self.post_delete_request(userid=self.user.id)
self.assertEqual(resp.status_code, 403)
User.get(id=self.user.id)
def test_normal_user_cannot_delete_admin(self):
self.login(USERNAME, USERPASS)
resp = self.post_delete_request(userid=self.admin.id)
self.assertEqual(resp.status_code, 403)
User.get(id=self.admin.id)
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)
def test_admin_cannot_delete_self(self):
self.login(ADMINNAME, ADMINPASS)
resp = self.post_delete_request(userid=self.admin.id)
self.assertIn("You cannot delete yourself", resp.data)
User.get(id=self.admin.id)
def test_admin_cannot_delete_nonexistant_user(self):
self.login(ADMINNAME, ADMINPASS)
resp = self.post_delete_request(userid=200)
self.assertEqual(resp.status_code, 404)
def test_normal_user_cannot_delete_nonexistant_user(self):
self.login(USERNAME, USERPASS)
resp = self.post_delete_request(userid=200)
self.assertEqual(resp.status_code, 404)
def when_user_deleted_posts_also_deleted(self):
self.login(ADMINNAME, ADMINPASS)
# TODO
pass