def test_delete_user(c): user = User.query.filter(User.id != 1).first() response = c.get(f'/user_d/{user.id}', follow_redirects=True) assert response.status == '200 OK' assert User.get(user.id) is None
def test_update_operator(c): office = choice(Office.query.all()) new_office = choice(Office.query.all()) while new_office == office: new_office = choice(Office.query.all()) name = f'{uuid4()}'.replace('-', '') password = '******' role = 3 new_name = f'{uuid4()}'.replace('-', '') c.post('/user_a', data={ 'name': name, 'password': password, 'role': role, 'offices': office.id }) user = User.query.filter_by(name=name).first() response = c.post(f'/user_u/{user.id}', data={ 'name': new_name, 'password': password, 'role': role, 'offices': new_office.id }, follow_redirects=True) assert response.status == '200 OK' assert User.get(user.id).name == new_name assert Operators.get(user.id).office_id == new_office.id
def test_update_admin_password(c): new_password = '******' response = c.post('/admin_u', data=dict(password=new_password), follow_redirects=True) assert response.status == '200 OK' assert User.get(1).verify_password(new_password)
def test_delete_user(client): with client.application.app_context(): user = User.query.filter(User.id != 1).first() response = client.get(f'/user_d/{user.id}', follow_redirects=True) assert response.status == '200 OK' assert User.get(user.id) is None
def test_delete_user(client): with client.application.app_context(): user = User.query.filter(User.id != 1).first() response = client.get(f'/user_d/{user.id}') assert response.status == '302 FOUND' assert User.get(user.id) is None
def test_list_operators(c): bundles = [] with c.application.app_context(): bundles += [(User.get(o.id), Office.get(o.office_id)) for o in Operators.query.all()] for user, office in bundles: response = c.get(f'/operators/{office.id}') page_content = response.data.decode('utf-8') assert f'<strong>{user.id}. {user.name}</strong>' in page_content
def login(): if request.method == 'POST' and request.form['username']: try: pw_hash = md5(request.form['password'].encode('utf-8')).hexdigest() user = User.get((User.username == request.form['username']) & (User.password == pw_hash)) except User.DoesNotExist: web.logger.error('[DEBUG] pass: %s, hash: %s', request.form['password'], pw_hash) flash('The password entered is incorrect') else: auth_user(user) return redirect(url_for('task_list')) return render_template('login.html')
def test_update_user(client): name = f'{uuid4()}'.replace('-', '') password = '******' new_name = f'{uuid4()}'.replace('-', '') role = 1 client.post('/user_a', data={ 'name': name, 'password': password, 'role': role }) user = User.query.filter_by(name=name).first() response = client.post(f'/user_u/{user.id}', data={ 'name': new_name, 'password': password, 'role': role }) assert response.status == '302 FOUND' assert User.get(user.id).name == new_name
def test_update_user(c): name = f'{uuid4()}'.replace('-', '') password = '******' new_name = f'{uuid4()}'.replace('-', '') role = 1 c.post('/user_a', data={'name': name, 'password': password, 'role': role}) user = User.query.filter_by(name=name).first() response = c.post(f'/user_u/{user.id}', data={ 'name': new_name, 'password': password, 'role': role }, follow_redirects=True) assert response.status == '200 OK' assert User.get(user.id).name == new_name
def picking(): if request.method == 'GET': username = request.args.get('username') explorer = request.args.get('explorer') return render_template("homepage.html", username=username, explorer=explorer) else: data = json.loads(request.get_data()) dtype = data['type'] username = data['username'] # 输入 if dtype == "information": signature = data['newSign'] nickname = data['newNick'] User.update(username, 'signature', signature) User.update(username, 'nickname', nickname) return jsonify({"code": 1111, "msg": "succeed!"}) if dtype == "photo": user = User.get(username) album_list = Album.get_mine(user.uid) count = Album.get_my_count(username) result = {"album": album_list, "count": count} result_json = json.dumps(result) return result_json if dtype == "homepage": user = User.get(username) if user.birth is None: age = 0 else: now_time = time.time() year = now_time - user.birth age = time.localtime(year) year = age.tm_year - 1970 age = int(year) result = { "nickname": user.nickname, "realname": user.real_name, "age": age, "gender": user.gender, "signature": user.signature, "portrait": user.portrait, } result_json = json.dumps(result) return result_json if dtype == "picking": re = [] picked_id = Relation.get_picked(username) for id_i in picked_id: picked_info = User.get(id_i[0]) result = { "portrait": picked_info.portrait, "realname": picked_info.real_name, "nickname": picked_info.nickname, "follow": 1 } result_json = json.dumps(result) re.append(result_json) return re elif dtype == "followers": re = [] picked_id = Relation.get_follower(username) for id_i in picked_id: picked_info = User.get(id_i[0]) relation = Relation.get_level(username, picked_info.uid) if relation != 0: relation = 1 result = { "portrait": picked_info.portrait, "realname": picked_info.real_name, "nickname": picked_info.nickname, "follow": relation } result_json = json.dumps(result) re.append(result_json) return re
def get_current_user(): if session.get('logged_in'): return User.get(User.id == session['user_id'])