本文整理汇总了Python中ziggurat_foundations.tests.conftest.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_generate_random_pass
def test_generate_random_pass(self, db_session):
rand_str = User.generate_random_pass()
assert len(rand_str) == 7
assert isinstance(rand_str, six.string_types)
rand_str = User.generate_random_pass(20)
assert len(rand_str) == 20
示例2: test_add_user
def test_add_user(self, db_session):
user = User(user_name='username', email='email', status=0)
db_session.add(user)
db_session.flush()
user = db_session.query(User).filter(User.user_name == 'username')
user = user.first()
assert user.user_name == 'username'
assert user.email == 'email'
assert user.status == 0
示例3: add_user
def add_user(db_session, user_name='username', email='email',
perms=['root', 'alter_users']):
user = User(user_name=user_name, email=email, status=0)
user.set_password('password')
for perm in perms:
u_perm = UserPermission(perm_name=perm)
user.user_permissions.append(u_perm)
db_session.add(user)
db_session.flush()
return user
示例4: test_delete_object_with_flush
def test_delete_object_with_flush(self, db_session):
user = User(user_name='some_new_user', email='foo')
assert user.id is None
user.persist(flush=True, db_session=db_session)
assert user.id is not None
uid = user.id
User.by_id(uid, db_session=db_session) is not None
user.delete()
assert User.by_id(uid, db_session=db_session) is None
示例5: test_by_user_names_like
def test_by_user_names_like(self, db_session):
user1 = add_user(db_session, 'user1', 'email1')
add_user(db_session, 'luser2', 'email2')
add_user(db_session, 'noname', 'email3')
queried_users = User.user_names_like('user%',
db_session=db_session).all()
assert len(queried_users) == 1
assert user1 == queried_users[0]
示例6: test_by_username_andsecurity_code_wrong_code
def test_by_username_andsecurity_code_wrong_code(self, db_session):
add_user(db_session)
queried_user = User.by_user_name_and_security_code(
user_name='username',
security_code='wrong_code',
db_session=db_session
)
assert queried_user is None
示例7: test_by_username_andsecurity_code_not_existing
def test_by_username_andsecurity_code_not_existing(self, db_session):
created_user = add_user(db_session)
security_code = created_user.security_code
queried_user = User.by_user_name_and_security_code(
user_name='not_existing_user',
security_code=security_code,
db_session=db_session
)
assert queried_user is None
示例8: test_by_username_andsecurity_code_none
def test_by_username_andsecurity_code_none(self, db_session):
created_user = add_user(db_session)
security_code = created_user.security_code
found = User.by_user_name_and_security_code(
user_name=None,
security_code=security_code,
db_session=db_session
)
assert found is None
示例9: test_by_user_names_one_none
def test_by_user_names_one_none(self, db_session):
user1 = add_user(db_session, 'user1', 'email1')
add_user(db_session, 'user2', 'email2')
user3 = add_user(db_session, 'user3', 'email3')
queried_users = User.by_user_names(['user1', None, 'user3'],
db_session=db_session).all()
assert len(queried_users) == 2
assert user1 == queried_users[0]
assert user3 == queried_users[1]
示例10: test_delete_user
def test_delete_user(self, db_session):
add_user(db_session)
to_delete = User.by_user_name('username', db_session=db_session)
db_session.delete(to_delete)
db_session.commit()
示例11: test_get_keys
def test_get_keys(self, db_session):
keys = User._get_keys()
assert len(keys) == 9
示例12: test_add_object_with_flush
def test_add_object_with_flush(self, db_session):
user = User(user_name='some_new_user', email='foo')
assert user.id is None
user.persist(flush=True, db_session=db_session)
assert user.id is not None
示例13: test_by_user_names_like_none
def test_by_user_names_like_none(self, db_session):
queried_users = User.user_names_like(None,
db_session=db_session).all()
assert [] == queried_users
示例14: test_users_for_perms
def test_users_for_perms(self, db_session):
user = User(user_name='aaa', email='aaa', status=0)
user.set_password('password')
aaa_perm = UserPermission(perm_name='aaa')
bbb_perm = UserPermission(perm_name='bbb')
bbb2_perm = UserPermission(perm_name='bbb')
user.user_permissions.append(aaa_perm)
user.user_permissions.append(bbb_perm)
user2 = User(user_name='bbb', email='bbb', status=0)
user2.set_password('password')
user2.user_permissions.append(bbb2_perm)
user3 = User(user_name='ccc', email='ccc', status=0)
user3.set_password('password')
group = add_group(db_session, )
group.users.append(user3)
db_session.add(user)
db_session.add(user2)
db_session.flush()
users = User.users_for_perms(['aaa'], db_session=db_session)
assert len(users.all()) == 1
assert users[0].user_name == 'aaa'
users = User.users_for_perms(['bbb'], db_session=db_session).all()
assert len(users) == 2
assert ['aaa', 'bbb'] == sorted([u.user_name for u in users])
users = User.users_for_perms(['aaa', 'bbb', 'manage_apps'],
db_session=db_session)
assert ['aaa', 'bbb', 'ccc'] == sorted([u.user_name for u in users])
示例15: test_by_email_none
def test_by_email_none(self, db_session):
add_user(db_session)
queried_user = User.by_email(None, db_session=db_session)
assert queried_user is None