本文整理匯總了Python中app.models.User方法的典型用法代碼示例。如果您正苦於以下問題:Python models.User方法的具體用法?Python models.User怎麽用?Python models.User使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app.models
的用法示例。
在下文中一共展示了models.User方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_users
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_users(self):
# add two users
r = Role.query.filter_by(name='User').first()
self.assertIsNotNone(r)
u1 = User(email='john@example.com', username='john',
password='cat', confirmed=True, role=r)
u2 = User(email='susan@example.com', username='susan',
password='dog', confirmed=True, role=r)
db.session.add_all([u1, u2])
db.session.commit()
# get users
response = self.client.get(
url_for('api.get_user', id=u1.id),
headers=self.get_api_headers('susan@example.com', 'dog'))
self.assertTrue(response.status_code == 200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['username'] == 'john')
response = self.client.get(
url_for('api.get_user', id=u2.id),
headers=self.get_api_headers('susan@example.com', 'dog'))
self.assertTrue(response.status_code == 200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertTrue(json_response['username'] == 'susan')
示例2: get_or_make_user
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def get_or_make_user(self, aga_id):
"""Gets or creates a fake User object for an AGA ID,
along with an AGA player
If the AGA ID has had one or more PIN changes, the most recent ID will
be used.
"""
while aga_id in self._pin_changes:
aga_id = self._pin_changes[aga_id]
if aga_id in self._users:
return self._users[aga_id]
else:
user = User(aga_id=aga_id, email=uuid4(), fake=True)
db.session.add(user)
db.session.commit()
player = Player(id=aga_id, name='', user_id=user.id, server_id=self.server_id, token=uuid4())
db.session.add(player)
self._users[aga_id] = user
return user
示例3: test_create_user
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_create_user(notify_db_session, phone_number):
email = 'notify@digital.cabinet-office.gov.uk'
data = {
'name': 'Test User',
'email_address': email,
'password': 'password',
'mobile_number': phone_number
}
user = User(**data)
save_model_user(user, password='password', validated_email_access=True)
assert User.query.count() == 1
user_query = User.query.first()
assert user_query.email_address == email
assert user_query.id == user.id
assert user_query.mobile_number == phone_number
assert user_query.email_access_validated_at == datetime.utcnow()
assert not user_query.platform_admin
示例4: login
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def login():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user is None or not user.check_password(form.password.data):
error = 'Invalid username or password'
return render_template('login.html', form=form, error=error)
login_user(user, remember=form.remember_me.data)
next_page = request.args.get('next')
if not next_page or url_parse(next_page).netloc != '':
next_page = url_for('main.index')
return redirect(next_page)
return render_template('login.html', title='Sign In', form=form)
示例5: test_gravatar
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_gravatar(self):
u = User(email='john@example.com', password='cat')
with self.app.test_request_context('/'):
gravatar = u.gravatar()
gravatar_256 = u.gravatar(size=256)
gravatar_pg = u.gravatar(rating='pg')
gravatar_retro = u.gravatar(default='retro')
with self.app.test_request_context('/',
base_url='https://example.com'):
gravatar_ssl = u.gravatar()
self.assertTrue('http://www.gravatar.com/avatar/' +
'd4c74594d841139328695756648b6bd6'in gravatar)
self.assertTrue('s=256' in gravatar_256)
self.assertTrue('r=pg' in gravatar_pg)
self.assertTrue('d=retro' in gravatar_retro)
self.assertTrue('https://secure.gravatar.com/avatar/' +
'd4c74594d841139328695756648b6bd6' in gravatar_ssl)
示例6: test_moderation
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_moderation(self):
db.create_all()
u1 = User(email='john@example.com', username='john', password='cat')
u2 = User(email='susan@example.com', username='susan', password='cat',
is_admin=True)
t = Talk(title='t', description='d', author=u1)
c1 = Comment(talk=t, body='c1', author_name='n',
author_email='e@e.com', approved=True)
c2 = Comment(talk=t, body='c2', author_name='n',
author_email='e@e.com', approved=False)
db.session.add_all([u1, u2, t, c1, c2])
db.session.commit()
for_mod1 = u1.for_moderation().all()
for_mod1_admin = u1.for_moderation(True).all()
for_mod2 = u2.for_moderation().all()
for_mod2_admin = u2.for_moderation(True).all()
self.assertTrue(len(for_mod1) == 1)
self.assertTrue(for_mod1[0] == c2)
self.assertTrue(for_mod1_admin == for_mod1)
self.assertTrue(len(for_mod2) == 0)
self.assertTrue(len(for_mod2_admin) == 1)
self.assertTrue(for_mod2_admin[0] == c2)
示例7: test_unsubscribe
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_unsubscribe(self):
db.create_all()
u = User(email='john@example.com', username='john', password='cat')
t = Talk(title='t', description='d', author=u)
c1 = Comment(talk=t, body='c1', author_name='n',
author_email='e@e.com', approved=True, notify=True)
c2 = Comment(talk=t, body='c2', author_name='n',
author_email='e2@e2.com', approved=False, notify=True)
c3 = Comment(talk=t, body='c3', author_name='n',
author_email='e@e.com', approved=False, notify=True)
db.session.add_all([u, t, c1, c2, c3])
db.session.commit()
token = t.get_unsubscribe_token(u'e@e.com')
Talk.unsubscribe_user(token)
comments = t.comments.all()
for comment in comments:
if comment.author_email == 'e@e.com':
self.assertTrue(comment.notify == False)
else:
self.assertTrue(comment.notify == True)
示例8: password_reset_request
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def password_reset_request():
if not current_user.is_anonymous:
return redirect(url_for('main.index'))
form = PasswordResetRequestForm()
if form.validate_on_submit():
user = User.query.filter_by(
email=form.email.data.lower().strip()).first()
if user:
token = user.generate_reset_token()
send_email(user.email, 'Reset Your Password',
'auth/email/reset_password',
user=user, token=token,
next=request.args.get('next'))
flash('An email with instructions to reset your password has been '
'sent to you.')
return redirect(url_for('auth.login'))
return render_template('auth/reset_password.html', form=form)
示例9: test_bad_auth
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_bad_auth(self):
# add a user
r = Role.query.filter_by(name='User').first()
self.assertIsNotNone(r)
u = User(email='john@example.com', password='cat', confirmed=True,
role=r)
db.session.add(u)
db.session.commit()
# authenticate with bad password
response = self.client.get(
url_for('api.get_posts'),
headers=self.get_api_headers('john@example.com', 'dog'))
self.assertTrue(response.status_code == 401)
示例10: test_token_auth
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_token_auth(self):
# add a user
r = Role.query.filter_by(name='User').first()
self.assertIsNotNone(r)
u = User(email='john@example.com', password='cat', confirmed=True,
role=r)
db.session.add(u)
db.session.commit()
# issue a request with a bad token
response = self.client.get(
url_for('api.get_posts'),
headers=self.get_api_headers('bad-token', ''))
self.assertTrue(response.status_code == 401)
# get a token
response = self.client.get(
url_for('api.get_token'),
headers=self.get_api_headers('john@example.com', 'cat'))
self.assertTrue(response.status_code == 200)
json_response = json.loads(response.data.decode('utf-8'))
self.assertIsNotNone(json_response.get('token'))
token = json_response['token']
# issue a request with the token
response = self.client.get(
url_for('api.get_posts'),
headers=self.get_api_headers(token, ''))
self.assertTrue(response.status_code == 200)
示例11: test_unconfirmed_account
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_unconfirmed_account(self):
# add an unconfirmed user
r = Role.query.filter_by(name='User').first()
self.assertIsNotNone(r)
u = User(email='john@example.com', password='cat', confirmed=False,
role=r)
db.session.add(u)
db.session.commit()
# get list of posts with the unconfirmed account
response = self.client.get(
url_for('api.get_posts'),
headers=self.get_api_headers('john@example.com', 'cat'))
self.assertTrue(response.status_code == 403)
示例12: test_password_setter
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_password_setter(self):
u = User(password='cat')
self.assertTrue(u.password_hash is not None)
示例13: test_password_verification
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_password_verification(self):
u = User(password='cat')
self.assertTrue(u.verify_password('cat'))
self.assertFalse(u.verify_password('dog'))
示例14: test_password_salts_are_random
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_password_salts_are_random(self):
u = User(password='cat')
u2 = User(password='cat')
self.assertTrue(u.password_hash != u2.password_hash)
示例15: test_valid_confirmation_token
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import User [as 別名]
def test_valid_confirmation_token(self):
u = User(password='cat')
db.session.add(u)
db.session.commit()
token = u.generate_confirmation_token()
self.assertTrue(u.confirm(token))