def test_get_by_id(self): """Get user by ID.""" user = User('foo', '*****@*****.**') user.save() retrieved = User.get_by_id(user.id) assert retrieved == user
def create_user(): form = UserForm(request.form) if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, password=form.password.data) user.save() return redirect(url_for('user.list_user')) else: flash_errors(form) return render_template('users/create_user.html', form=form)
def register(): """Register new user.""" form = UserForm(request.form) if form.validate_on_submit(): User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True) flash('Thank you for registering. You can now log in.', 'success') return redirect(url_for('public.home')) else: flash_errors(form) return render_template('public/register.html', form=form)
def initdb(): """ init system data :return: """ from goldeneye.user.models import User, Role, Permission perms = [ Permission(name='系统测试1', slug='public.about', type='N'), Permission(name='系统测试2', slug='public.about1', type='N'), Permission(name='系统测试3', slug='public.about2', type='N') ] role = Role.create(name='系统管理员', permissions=perms) user = User(username='******', email='*****@*****.**', password='******') user.roles.append(role) user.save()
def load_user(user_id): """Load user by ID.""" return User.get_by_id(int(user_id))
def test_check_password(self): """Check password.""" user = User.create(username='******', email='*****@*****.**', password='******') assert user.check_password('example') is True assert user.check_password('example123') is False
def test_password_is_nullable(self): """Test null password.""" user = User(username='******', email='*****@*****.**') user.save() assert user.password is None
def test_created_at_defaults_to_datetime(self): """Test creation date.""" user = User(username='******', email='*****@*****.**') user.save() assert bool(user.created_at) assert isinstance(user.created_at, dt.datetime)