def test_modify_user_role_id(self, client): """ With this code is tested the services to perform the user modification with service and have the result on db Test flow - Create user - Modify user - check user - delete user to clean the database """ form = UserForm() form.firstname.data = "Vincenzo" form.lastname.data = "Palazzo" form.password = "******" form.phone.data = "12345" form.dateofbirth = "12/12/2020" form.email.data = "*****@*****.**" user = User() form.populate_obj(user) user = UserService.create_user(user, form.password, 2) assert user is not None assert user.role_id is 2 response = login(client, form.email.data, form.password) assert response.status_code == 200 assert "logged_test" in response.data.decode("utf-8") formTest = UserForm(obj=user) user_modified = UserService.modify_user(formTest, 3) assert user is not None assert user.role_id is not 2 UserService.delete_user(user_modified.id) user_modified = get_user_with_email(user_modified.email) assert user_modified is None
def test_delete_user_with_email(self): """ This test cases test if the user service are able to remove correctly the user inside the DB Test flow - Create a new user with the service - delete a new user with service with user pass - check on db if this user is gone """ form = UserForm() form.firstname.data = "Vincenzo" form.lastname.data = "Palazzo" form.password = "******" form.phone.data = "12345" form.dateofbirth = "12/12/2020" form.email.data = "*****@*****.**" user = User() form.populate_obj(user) user = UserService.create_user(user, form.password, 2) assert user is not None assert user.role_id is 2 UserService.delete_user(email=user.email) user = db.session.query(User).filter_by(email=user.email).first() assert user is None
def create_user_on_db(ran: int = randrange(100000)): form = UserForm() # form.data["email"] = "alibaba" + str(ran) + "@alibaba.com" # form.data["password"] = "******" form.firstname.data = "User_{}".format(ran) form.lastname.data = "user_{}".format(ran) form.password = "******".format(ran) form.phone.data = "1234562344{}".format(ran) form.dateofbirth = "12/12/2000" form.email.data = "alibaba" + str(ran) + "@alibaba.com" user = User() form.populate_obj(user) return UserService.create_user(user, form.password)
def test_create_user(self): """ test create user :return: """ form = UserForm() form.firstname.data = "Vincenzo" form.lastname.data = "Palazzo" form.password = "******" form.phone.data = "12345" form.dateofbirth = "12/12/2020" form.email.data = "*****@*****.**" user = User() form.populate_obj(user) user = UserService.create_user(user, form.password) assert user is not None assert user.role_id is 3 db.session.query(User).filter_by(id=user.id).delete() db.session.commit()