def test_create_user(self): with app.app_context(): user = User() user.email = "*****@*****.**" user.password = "******" db.session.add(user) db.session.commit() # this works assert user in db.session response = self.app.get("/api/user") # this raises an AssertionError assert user in db.session
def test_register(self): """ This test will create a dummy user in the database we will use him for later test of booking/cancel booking functions Function: create a user with dummny details, check if the user exists (for second run or later). If not, create a new user Assertion: the user with dummy details exists, check by the calling userExists() """ username = "******" password = "******" email = "*****@*****.**" fname = "testfirstname" lname = "testlastname" role = "engineer" registered = db.session.query(User).filter( or_(User.username == username, User.email == email)).first() if registered is not None: self.assertTrue(self.userExists(username)) else: hashed_password = sha256_crypt.hash(str(password)) newUser = User(username=username, password=hashed_password, email=email, fname=fname, lname=lname, role=role) db.session.add(newUser) db.session.commit() self.assertTrue(self.userExists(username))
def register(): form = RegistrationForm() if form.validate_on_submit()==True: flash('Account created!', 'success') user = User(form.username.data, form.email.data, form.password.data) db.session.add(user) db.session.commit() return redirect(url_for('home')) return render_template('register.html', title='Register', form=form)
def register(): form = RegistrationForm() if form.validate_on_submit() == True: flash('Account created!', 'success') hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') if (form.dp.data): client = storage.Client() bucket = client.get_bucket('a2iot-carshare.appspot.com') blob = bucket.blob('dp_' + form.username.data + '.jpg') with open('/home/pi/Desktop/' + form.dp.data, "rb") as my_file: blob.upload_from_file(my_file) dp = "https://storage.cloud.google.com/a2iot-carshare.appspot.com/dp_" + form.username.data + ".jpg" else: dp = None user = User(username=form.username.data, email=form.email.data, password=hashed_password, dp=dp) db.session.add(user) db.session.commit() return redirect(url_for('home')) return render_template('register.html', title='Register', form=form)
def populate_users_data(self): with app.app_context(): user1 = User() user1.email = "*****@*****.**" user1.password = "******" user1.fname = "harry" user1.lname = "porter" user2 = User() user2.email = "*****@*****.**" user2.password = "******" user2.fname = "don" user2.lname = "john" db.session.add(user1) db.session.add(user2) db.session.commit()