def search(): form = SearchForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_num=form.search_id.data) data = user.search() return render_template('profile.html', data=data) else: return render_template('search.html', form=form)
def test_add_rating(self): db.session.add(models.Levels(difficulty=self.DIFFICULTY)) db.session.add(models.Users(**self.TEST_ADD_USER)) db.session.add(models.Recipe(**self.TEST_ADD_RECIPE)) db_queries.add_rating(self.TEST_ID, self.TEST_RECIPE_ID, 3.5) db_queries.add_rating(self.TEST_ID, self.TEST_RECIPE_ID, 5) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.ratings[0].rate, 5)
def delete(): form = DeleteForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_num=form.del_id.data) user.delete() return redirect('/') else: return render_template('delete.html', form=form)
def testUserFriends(): c = Cassandra() g = Goodreads(new=False) user = models.Users(id=uuid4(), gid='3371638', name='Katie') friends, friendRelation, total = g.getFriends(user) if (friends is None): print "Private" else: print len(friends), len(friendRelation), total
def register(): programs = db.session.query(models.Program).all() programChoices = sorted([(p.program_name, p.program_name) for p in programs]) programChoices.insert(0, ("--", "--")) majorCodes = db.session.query(models.MajorCodes).distinct().all() majorCodeChoices = sorted([(m.duke_major_code, m.duke_major_code) for m in majorCodes]) majorCodeChoices.insert(0, ("--", "--")) if request.method == 'POST': email = request.form['email'] name = request.form['name'] major = request.form['major'] term = request.form['term'] program_name = request.form['program_name'] uname = request.form['username'] pwd = request.form['password'] confpwd = request.form['confirmpassword'] error = None if email[-9:] != "@duke.edu": error = 'You must enter a valid Duke email' elif major == "--": error = 'You must choose a major.' elif program_name == "--": error = 'You must choose a program.' elif not uname: error = 'Username is required.' elif not pwd: error = 'Password is required.' elif not confpwd: error = 'Confirm your password' elif db.session.query(models.Users).filter(models.Users.username.contains(uname, autoescape=True)).first() \ is not None: error = 'User {} is already registered.'.format(uname) elif pwd != confpwd: error = 'Passwords do not match' if error is None: hashed_pwd = generate_password_hash(pwd) new_account = models.Users(email=email, name=name, major=major, term=term, program_name=program_name, username=uname, password=hashed_pwd) db.session.add(new_account) db.session.flush() db.session.commit() return redirect(url_for('auth.login')) else: flash(error) return render_template('auth/register.html', majors=majorCodeChoices, programs=programChoices)
def test_search_by_tag(self): recipe = models.Recipe(**self.TEST_ADD_RECIPE) tag = models.Tag(**self.TEST_ADD_TAG) recipe.tags.append(tag) db.session.add(models.Levels(difficulty=self.DIFFICULTY)) db.session.add(models.Users(**self.TEST_ADD_USER)) db.session.add(recipe) searched_recipes = db_queries.search_by_tag(self.TEST_ADD_TAG["name"]) self.assertEqual(searched_recipes[0]["title"], self.TEST_ADD_RECIPE["title"])
def _createUserSmall(obj): u = models.Users() u.id = uuid.uuid4() u.gid = int(obj.id) u.name = ascii(obj.name) u.friends_count = int(obj.friends_count) u.reviews_count = int(obj.reviews_count) u.small_user = True return u
def test_add_recipe(self): with mock.patch( "db_queries.generate_random_user_id", mocked_generate_recipe_id ): db.session.add(models.Levels(difficulty=self.DIFFICULTY)) db.session.add(models.Users(**self.TEST_ADD_USER)) db.session.add(models.Recipe(**self.TEST_ADD_RECIPE_2)) recipe_id = db_queries.add_recipe(self.TEST_RECIPE) self.assertEqual( self.TEST_RECIPE["user"], db.session.query(models.Recipe).get(recipe_id).user_id, ) self.assertEqual( self.TEST_RECIPE["title"], db.session.query(models.Recipe).get(recipe_id).title, ) self.assertEqual( self.TEST_RECIPE["description"], db.session.query(models.Recipe).get(recipe_id).description, ) self.assertEqual( self.TEST_RECIPE["images"], db.session.query(models.Recipe).get(recipe_id).images, ) self.assertEqual( self.TEST_RECIPE["videos"], db.session.query(models.Recipe).get(recipe_id).videos, ) self.assertEqual( self.TEST_RECIPE["difficulty"], db.session.query(models.Recipe).get(recipe_id).difficulty, ) self.assertEqual( self.TEST_RECIPE["ingredients"], db.session.query(models.Recipe).get(recipe_id).ingredients, ) self.assertEqual( self.TEST_RECIPE["instructions"], db.session.query(models.Recipe).get(recipe_id).instructions, ) self.assertEqual( self.TEST_RECIPE["readyInMinutes"], db.session.query(models.Recipe).get(recipe_id).ready_in_minutes, ) self.assertEqual( self.TEST_RECIPE["servings"], db.session.query(models.Recipe).get(recipe_id).servings, ) forked_recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID_2) self.assertEqual(forked_recipe.number_of_forks, 1) self.assertEqual( db.session.query(models.Recipe).get(recipe_id).forked_from_recipe, self.TEST_RECIPE_ID_2, )
def register(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_no=form.id_no.data, name=form.name.data, course=form.course.data) user.add() return redirect('/') else: return render_template('signup.html', form=form)
def update(): form = UpdateForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_no=form.new_id.data, name=form.new_name.data, course=form.new_course.data) user.update() return redirect('/') else: return render_template('update.html', form=form)
def put(self): session = models.Session() if self.userID in models.query(models.Users.id): query = session.query(models.Users).filter(models.Users.id == str(self.userID)).first() query.forms = str(self.forms) else: session.add(models.Users(id=self.userID, forms=str(self.forms))) session.commit() session.close() return True
def update_user(data): user = get_user(data["email"]) if not user: db.session.add( models.Users(data["email"], data["name"], data["imageURL"])) db.session.commit() else: user.name = data["name"] user.profile_pic = data["imageURL"] db.session.commit()
def test_add_recipe(self): with mock.patch( "db_queries.generate_random_user_id", mocked_generate_recipe_id ): db.session.add(models.Levels(difficulty=self.DIFFICULTY)) db.session.add( models.Users( id=self.TEST_ID, email=self.TEST_USER["email"], name=self.TEST_USER["name"], shopping_list=[], shared_recipes=[], saved_recipes=[], profile_pic=self.TEST_USER["imageURL"], ) ) recipe_id = db_queries.add_recipe(self.TEST_RECIPE) self.assertEqual( self.TEST_RECIPE["user"], db.session.query(models.Recipe).get(recipe_id).user_id, ) self.assertEqual( self.TEST_RECIPE["title"], db.session.query(models.Recipe).get(recipe_id).title, ) self.assertEqual( self.TEST_RECIPE["description"], db.session.query(models.Recipe).get(recipe_id).description, ) self.assertEqual( self.TEST_RECIPE["images"], db.session.query(models.Recipe).get(recipe_id).images, ) self.assertEqual( self.TEST_RECIPE["difficulty"], db.session.query(models.Recipe).get(recipe_id).difficulty, ) self.assertEqual( self.TEST_RECIPE["ingredients"], db.session.query(models.Recipe).get(recipe_id).ingredients, ) self.assertEqual( self.TEST_RECIPE["instructions"], db.session.query(models.Recipe).get(recipe_id).instructions, ) self.assertEqual( self.TEST_RECIPE["readyInMinutes"], db.session.query(models.Recipe).get(recipe_id).ready_in_minutes, ) self.assertEqual( self.TEST_RECIPE["servings"], db.session.query(models.Recipe).get(recipe_id).servings, )
def register(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(username=form.username.data, email=form.email.data, password=form.password.data) user.add() # return str(user) return redirect('/') else: return render_template('signup.html', form=form)
def test_on_data(self): session = UnifiedAlchemyMagicMock() session.add(models.Users("Jake", "email@email", "password", "role", "img")) session.add(models.Participants("email@email", "gc")) session.add(models.Projects("gc", "testName", "testDescription")) session.add( models.Tasks("testTitle", "testDescription", "date", "gc", "owner", "done") ) with mock.patch("app.db.session", session): with mock.patch("app.request", RequestObj()): app.on_data({"email": "email@email"})
def log_user_info(user_access_token): headers = {'Authorization': 'token ' + user_access_token} user = requests.get('https://api.github.com/user', headers=headers).json() login = user['login'] name = user['name'] email = user['email'] profile_image = user['avatar_url'] model = models.Users(login, name, email, profile_image, request.sid, user_access_token) db.session.add(model) db.session.commit()
def test_edit_recipe(self): db.session.add(models.Levels(difficulty=self.DIFFICULTY)) db.session.add(models.Users(**self.TEST_ADD_USER)) db.session.add(models.Recipe(**self.TEST_ADD_RECIPE)) db_queries.edit_recipe(self.TEST_RECIPE_ID, {"title": "Edited Title"}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.title, "Edited Title") db_queries.edit_recipe(self.TEST_RECIPE_ID, {"videos": ["new test video"]}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.videos, ["new test video"]) db_queries.edit_recipe( self.TEST_RECIPE_ID, {"ingredients": {"name": "Edited Ingredients"}} ) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertDictEqual(recipe.ingredients, {"name": "Edited Ingredients"}) db_queries.edit_recipe(self.TEST_RECIPE_ID, {"images": ["new test image"]}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.images, ["new test image"]) db_queries.edit_recipe(self.TEST_RECIPE_ID, {"servings": 1}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.servings, 1) db_queries.edit_recipe(self.TEST_RECIPE_ID, {"readyInMinutes": 10}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.ready_in_minutes, 10) db_queries.edit_recipe( self.TEST_RECIPE_ID, {"instructions": {"step": "Edited Instructions"}} ) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertDictEqual(recipe.instructions, {"step": "Edited Instructions"}) db_queries.edit_recipe(self.TEST_RECIPE_ID, {"difficulty": "advanced"}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.difficulty, "advanced") db_queries.edit_recipe(self.TEST_RECIPE_ID, {"description": "New Description"}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) self.assertEqual(recipe.description, "New Description") db_queries.edit_recipe(self.TEST_RECIPE_ID, {"tags": ["new tag", "dinner"]}) recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID) assert ( db.session.query(models.Tag).filter_by(name="new tag").first() in recipe.tags ) assert ( db.session.query(models.Tag).filter_by(name="dinner").first() in recipe.tags )
def UserRegister(): form = forms.UserRegisterForm() if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data u = models.Users(username=username, email=email, password=password) u.save() flash('Confirm Your Access') login_user(u) return redirect(url_for('confirmed', username=u.username)) return render_template('user_register.html', form=form)
def create_user(db: Session, user: schemas.NewUser): print(user.__dict__) secret_password = user.password db_user = models.Users(name=user.name, email=user.email, password=secret_password, mobile_no=user.mobile_no, position=user.ownership) db.add(db_user) db.commit() db.refresh(db_user) return db_user
def register(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_num=form.id_num.data, f_name=form.f_name.data, l_name=form.l_name.data, course=form.course.data, year=form.year.data, gender=form.gender.data) user.add() return redirect('/') else: return render_template('add.html', form=form)
def add_user(self, username, password): user = self.dbs.query(models.Users).get(self.user_id) if user.is_administrator: add_user = self.dbs.query( models.Users).filter_by(username=username).first() if not add_user: add_user = models.Users(username=username, password=password) self.dbs.add(add_user) self.dbs.commit() else: print('用户名已存在') else: print(Fore.RED + '无权限' + Fore.RESET)
def confirm(): if request.json: mydata = request.json # will be userExist = models.Users.query.filter_by(email=mydata["email"]).all() if (len(userExist) == 0): user = models.Users(mydata["email"], mydata["password"], mydata["phoneNumber"], mydata["closetName"]) models.db.session.add(user) models.db.session.commit() return jsonify({"message": 'Success'}) else: return jsonify({"message": 'user already exist'})
def testUserReviews(c): #user=Users(id=uuid4(), gid='902976', name='Katie') #902976 katie, 1085121 Stephanie, 47225465 mio user = models.Users(id=uuid.uuid4(), gid=1085121, name='Simone', friends_count=1, small_user=True) u = c.get_user_if_exsists_or_save(user) reviewsDict, altready_retrieved = Goodreads().getUserReviews(u) if (altready_retrieved is False): c.saveUserReviews(u, reviewsDict) else: print "already retrieved"
def register_user(): username = request.form['username'] password = request.form['password'] fname = request.form['fname'] lname = request.form['lname'] if username is None or password is None: return jsonify({'success':False}) if models.Users.query.filter_by(username = username).first() is not None: return jsonify({'success':False}) new_user = models.Users(username = username, fname = fname, lname = lname) new_user.hash_password(password) db.session.add(new_user) db.session.commit() return jsonify({'username': new_user.username, 'success':True})
def check_user(self): admin = self.dbs.query(models.Users).filter_by(id=1).first() if not admin: admin = models.Users(username='******', password='******', is_administrator=True) self.dbs.add(admin) self.dbs.commit() user = self.dbs.query(models.Users).filter_by( username=self.username, is_deleted=False).first() if user and user.verify_password(self.password): self.user_id = user.id return True return False
def test_get_user_id(self): db.session.add( models.Users( id=self.TEST_ID, email=self.TEST_USER["email"], name=self.TEST_USER["name"], shopping_list=[], shared_recipes=[], saved_recipes=[], profile_pic=self.TEST_USER["imageURL"], ) ) user_id = db_queries.get_user_id("*****@*****.**") self.assertEqual(user_id, self.TEST_ID)
async def create_new_user(Create_user: CreateUser, db: Session = Depends(get_db)): create_user_model = models.Users() create_user_model.email = Create_user.email create_user_model.username = Create_user.username create_user_model.first_name = Create_user.first_name create_user_model.last_name = Create_user.last_name hash_password = get_password_hash(Create_user.password) create_user_model.hashed_password = hash_password create_user_model.is_active = True db.add(create_user_model) db.commit() return create_user_model
def test_on_create_project_success(self): session = UnifiedAlchemyMagicMock() session.add(models.Users("Jake", "*****@*****.**", "password", "img", "xyzabc")) with mock.patch("app.db.session", SessionObject()): with mock.patch("app.ssl", sslObj()): with mock.patch("app.smtplib", smtplibObj()): app.on_create_project( { "projectName": "testproject", "projectDescription": "test", "code": "xyzabc", "selectedUsers": ["mike", "aarati", "jake", "devin"], "email": "*****@*****.**", } )
def init_db(): import models Base.metadata.create_all(bind=engine) admin = models.Roles(name='Admin') operator = models.Roles(name='Operator') user = models.Roles(name='User') print(str(db_session.query(models.Roles).all()), file=sys.stderr) if not db_session.query(models.Roles).all(): db_session.add(admin) db_session.add(operator) db_session.add(user) db_session.commit() print("roles added", file=sys.stderr) ivan = models.Users(name='Ivan') maria = models.Users(name='Maria') kate = models.Users(name='Kate') gleb = models.Users(name='Gleb') print(str(db_session.query(models.Users).all()), file=sys.stderr) if not db_session.query(models.Users).all(): db_session.add(ivan) db_session.add(maria) db_session.add(kate) db_session.add(gleb) db_session.commit() if not db_session.query(models.users_to_roles).all(): ivan.role.append(user) maria.role.append(operator) kate.role.append(admin) gleb.role.append(operator) gleb.role.append(admin) db_session.commit()
def create_users(): word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain" log.info("Getting words for random names...") words = requests.get(word_url).text.splitlines() upper_words = [word for word in words if word[0].isupper()] name_words = [ word.lower() for word in upper_words if not word.isupper() ] li = LoremIpsum() for name in name_words: u = models.Users(name=name, comments=[li.get_sentences(5) for i in range(10)]) db_session.add(u) db_session.commit() del upper_words del name_words