def test_delete_user(self, testdir_class, test_utils): testdir_class.activate() username = test_utils.random_string(5) Users.create_user(username, '123456') errors = Users.delete_user(username) assert errors == [] assert not Users.user_exists(username)
def login(): if current_user is not None and current_user.is_authenticated: return redirect(url_for('webapp.index')) if request.method == 'POST': errors = [] username = request.form['username'] password = request.form['password'] next_url = request.form['next'] if not username: errors.append('Username is required') elif not password: errors.append('Password is required') elif not Users.user_exists(username): errors.append('Username does not exists') elif not Users.verify_password(username, password): errors.append('Username and password do not match') if errors: return render_template('login.html', next_url=next_url, errors=errors) else: login_user(Users.get_user_by_username(username)) if not next_url or not is_safe_url(next_url): next_url = '/' return redirect(next_url) else: next_url = request.args.get('next') if not next_url or not is_safe_url(next_url): next_url = '/' return render_template('login.html', next_url=next_url, errors=[])
def test_create_user_file_not_exist(self, testdir_function, test_utils): """Users file is created if it does not exist""" testdir_function.activate() username = test_utils.random_string(5) os.remove(Users.file_path()) Users.create_user(username, '123', None) assert os.path.isfile(Users.file_path()) assert Users.user_exists(username)
def test_users(self, testdir_function, test_utils): testdir_function.activate() users = Users.users() assert len(users) == 1 username = test_utils.random_string(10) Users.create_user(username, '123') users = Users.users() assert len(users) == 2 assert Users.user_exists(username)
def test_create_superuser_command(self, testdir_class, test_utils, capsys): testdir_class.activate() username = test_utils.random_string(5) email = test_utils.random_email() password = test_utils.random_string(5) commands.createsuperuser_command(username, email, password, no_input=True) out, err = capsys.readouterr() assert f'Superuser {username} was created successfully.' in out assert Users.user_exists(username) user = Users.get_user_by_username(username) assert user.email == email
def test_user_exists(self, testdir_function): testdir_function.activate() assert Users.user_exists('admin') assert not Users.user_exists('not-exist')