def post(self): args = UserLoginArgs().args user = get_user(name=args['name'])[0] if check_user_password(user, args['password']) and check_user_enable(user): session['user'] = user.key return marshal(user, user_fields) return None
def test_patch(self): self.login_as_admin() # this will add a user name admin! user = add_user('name1', 'pw1', 'normal') user_key = user.key rv = self.app.patch('/api/user/%s/' % (user_key), data={'password': '******', 'level': 'admin'}) rv = json.loads(rv.data) assert rv['level'] == 'admin' user = get_user(key=user_key)[0] assert check_user_password(user, 'new_password')
def test_add_user(self): name = 'user_name' password = '******' level = 'normal' user = add_user(name, password, level) assert add_user(name, password, level) is None assert len(get_user(key=user.key)) == 1 user = get_user()[0] assert user.name == 'user_name' assert user.password == _encrypt('user_name', 'user_password') assert check_user_password(user, 'user_password') assert user.level == 'normal'
def test_update_user(self): name = 'user_name' password = '******' level = 'normal' add_user(name, password, level) user = get_user()[0] update_user(user, password='******', level='disable') user = get_user()[0] assert user.name == 'user_name' assert user.password == _encrypt(user.name, 'new_password') assert check_user_password(user, 'new_password') assert user.level == 'disable' try: update_user(user, name='some_name') except AttributeError: pass try: update_user(user, level='some_level') except AssertionError: pass