当前位置: 首页>>代码示例>>Python>>正文


Python models.User方法代码示例

本文整理汇总了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') 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:26,代码来源:test_api.py

示例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 
开发者ID:usgo,项目名称:online-ratings,代码行数:23,代码来源:load_agagd_data.py

示例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 
开发者ID:alphagov,项目名称:notifications-api,代码行数:19,代码来源:test_users_dao.py

示例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) 
开发者ID:okomarov,项目名称:dash_on_flask,代码行数:20,代码来源:webapp.py

示例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) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:19,代码来源:test_user_model.py

示例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) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:24,代码来源:test_user_model.py

示例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) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:22,代码来源:test_talk_model.py

示例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) 
开发者ID:levlaz,项目名称:braindump,代码行数:19,代码来源:views.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:16,代码来源:test_api.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:31,代码来源:test_api.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:16,代码来源:test_api.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:5,代码来源:test_user_model.py

示例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')) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:6,代码来源:test_user_model.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:6,代码来源:test_user_model.py

示例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)) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:8,代码来源:test_user_model.py


注:本文中的app.models.User方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。