def test_get_user_returns_400_if_username_isnt_provided(): """ When get_user is called with a username that doesn't exist, a 400 error code should be returned. """ request = Mock(json={'asd': 'sdf'}) with pytest.raises(BadRequest): main.get_user(request)
def tools(tid=None): if tid: tool = get_tool_info(get_user(session["user"])["database"],tid) avl = [[i,j] for i,j in zip(*tool["avl"].values())] return render_template("tool.html",tool_id=tid,tool_name=tool['tool'],tool_sr=tool['sr_num'],total_quant=tool['total_quant'],avl=avl) else: tool = get_tools(get_user(session["user"])["database"]) tool = [[i['_id'],i['tool'],i['sr_num']] for i in tool] return render_template("tool.html",tool=tool)
def test_get_user_returns_400_if_username_doesnt_exist(): """ When get_user is called with a username that doesn't exist, a 400 error code should be returned. """ (main.db.collection.return_value.where.return_value.stream.return_value ) = [] request = Mock(json={'username': '******'}) with pytest.raises(BadRequest): main.get_user(request)
def projects(pid): project = get_project_info(get_user(session.get("user"))["database"],pid) name = project["proj_name"] city = project["city"] status = project["status"] tools = list() if project.get("avl"): for i in project.get("avl").keys(): t_name = get_tool_info(get_user(session.get("user"))["database"],int(i))["tool"] for quant,sr,date,sender in zip(*project["avl"][i].values()): tools.append([int(i),t_name,quant,sr,date,sender]) else: tools=None return render_template("project.html",name=name,pid=pid,city=city,status=status,tools=tools)
def deluser(): name=request.args.get('name') if name in get_user(): del_user(name) return redirect("/") else: print "用户不存在"
def deluser(): name=request.args.get('name') if name in get_user(): del_user(name) return redirect("/") else: print "用户不存在"
def search(self): user = self.cleaned_data['user'] client_id = self.cleaned_data['client_id'] client_secret = self.cleaned_data['client_secret'] token = get_token(client_id=client_id, client_secret=client_secret) url = get_user(token, client_id, user) return url
def new_tool(): if request.method == "POST": tool_name=request.form["tool_name"] tool_quant=request.form["tool_quant"] tool_sr = request.form["tool_sr"] db_name = get_user(session.get("user",None))["database"] add_new_tool(db_name,tool_name,tool_quant,tool_sr) return redirect(url_for('user',username=session["user"]))
def user(username): user=get_user(username) if session.get("user",None) == username: project=list() if user["database"]: for i in get_projects(user["database"]): project.append([i["_id"],i["proj_name"]]) return render_template("user.html",name=user["name"],username=user["username"],database=user["database"],admin=user["admin"],project=project) else: return redirect(url_for("login"))
def test_get_user_returns_info(): """ When get_user is called with no errors, it should return the player's information. """ (main.db.collection.return_value.where.return_value.stream.return_value ) = [ Mock(id='asd', to_dict=Mock(return_value={ 'elo': 1234, 'credits': 2345, 'modules': ['asd', 'sdf'] })) ] request = Mock(json={'username': '******'}) result = json.loads(main.get_user(request)) assert result == {'elo': 1234, 'credits': 2345, 'modules': ['asd', 'sdf']}
def adduser(): name = request.args.get('name') pwd = request.args.get('password') if name not in get_user(): add_user(name,pwd) else: return redirect("/") @app.route('/deluser') def deluser(): name=request.args.get('name') if name in get_user(): del_user(name) return redirect("/") else: print "用户不存在" if __name__ == '__main__': app.run(host='0.0.0.0',port=9092,debug=True)
def adduser(): name = request.args.get('name') pwd = request.args.get('password') if name not in get_user(): add_user(name,pwd) else: return redirect("/") @app.route('/deluser') def deluser(): name=request.args.get('name') if name in get_user(): del_user(name) return redirect("/") else: print "用户不存在" if __name__ == '__main__': app.run(host='0.0.0.0',port=9092,debug=True)
def index(): names=get_user() return render_template('index.html',names=names)
def new_project(): if request.method=="POST": project_name = request.form["p_name"] project_city = request.form["p_city"] create_new_project(get_user(session.get("user"))["database"],project_name,project_city) return redirect(url_for('user',username=session.get("user")))
def retrive_user_route(): if request.method == 'POST': user_to_get = request.json user = get_user(user_to_get) return jsonify(user)
def index(): names=get_user() return render_template('index.html',names=names)
def delete(pid): complete_project(get_user(session["user"])["database"],pid) return redirect(url_for('user',username=session['user']))