示例#1
0
def test_delete_user_with_notification():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    auth.User.delete(username='******',
                     message='Click http://mysite.com/delete/$url to confirm',
                     confirmation=False)
    assert not auth.User.get_user(username='******')
示例#2
0
def test_suspend_with_message():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    auth.User.suspend(username='******', message='Your account was suspended')
    user = auth.User.get_user(username='******')
    user.authenticate('abc123')
示例#3
0
def test_delete_user_with_confirmation():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    auth.User.delete(username='******',
                     message='Click http://mysite.com/delete/$url to confirm')
    user = auth.User.get_user(username='******')
    assert len(user._act_code) == 64
示例#4
0
def test_clear_interaction_clears_act_type():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    user.create()
    user = auth.User.get_user(username='******')
    user.clear_interaction()
    assert user._act_type is None
示例#5
0
def test_login_with_real_account():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create()
    login_form = authforms.login_form()
    assert not login_form.validates(
        web.storify({
            'username': '******',
            'password': '******',
        }))
    user.activate()
    user.store()
    assert login_form.validates(
        web.storify({
            'username': '******',
            'password': '******',
        })), login_form.note
    assert not login_form.validates(
        web.storify({
            'username': '******',
            'password': '******',
        }))
    assert not login_form.validates(
        web.storify({
            'username': '******',
            'password': '******',
        }))
示例#6
0
def test_suspend_account():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    auth.User.suspend(username='******')
    user = auth.User.get_user(username='******')
    user.authenticate('abc123')
示例#7
0
def test_registration_fails_if_user_exists():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    reg_form = authforms.register_form()
    assert not reg_form.validates(
        web.storify({
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'confirm': 'abc123',
        }))
    assert not reg_form.validates(
        web.storify({
            'username': '******',
            'email': '*****@*****.**',  # still the same e-mail
            'password': '******',
            'confirm': 'abc123',
        }))
    assert not reg_form.validates(
        web.storify({
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'confirm': 'abc123',
        }))
示例#8
0
def test_reset_password_old_pwd_still_valid():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    user = auth.User.get_user(username='******')
    user.reset_password('123abc',
                        message='Please visit http://mysite.com/confirm/$url')
    assert user.authenticate('abc123')
示例#9
0
def test_reset_password_with_confirmation():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    user = auth.User.get_user(username='******')
    user.reset_password('123abc',
                        message='Please visit http://mysite.com/confirm/$url')
    assert len(user._pending_pwd) == 81
示例#10
0
def test_reset_password_with_random_pwd():
    user = auth.User(username='******', email='*****@*****.**')
    user.create(activated=True)
    user = auth.User.get_user(username='******')
    user.reset_password()
    password = user._cleartext
    user = auth.User.get_user(username='******')
    assert user.authenticate(password)
示例#11
0
def test_reset_password():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    user = auth.User.get_user(username='******')
    user.reset_password('123abc')
    user = auth.User.get_user(username='******')
    assert user.authenticate('123abc')
示例#12
0
def test_store_modifications():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    user = auth.User.get_user(username='******')
    user.username = '******'
    user.store()
    user = auth.User.get_user(email='*****@*****.**')
    assert user.username == 'otheruser'
示例#13
0
def test_activation_code_in_db():
    user = auth.User(username='******', email='*****@*****.**')
    user.create(message='This is the activation mail')
    record = database.select('authenticationpy_users',
                             what='act_code',
                             where="username = '******'",
                             limit=1)[0]
    assert record.act_code == user._act_code
示例#14
0
def test_activation_on_create():
    user = auth.User(username='******', email='*****@*****.**')
    user.create(activated=True)
    record = database.select('authenticationpy_users',
                             what='active',
                             where="username = '******'",
                             limit=1)[0]
    assert record.active == True
示例#15
0
def test_reset_password_with_notification():
    user = auth.User(username='******', email='*****@*****.**')
    user.password = '******'
    user.create(activated=True)
    user = auth.User.get_user(username='******')
    user.reset_password('123abc',
                        message='Your password has been reset',
                        confirmation=False)
    assert user.authenticate('123abc')
示例#16
0
def test_user_exist():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    assert auth.User.exists(username='******')
    assert auth.User.exists(email='*****@*****.**')
    assert auth.User.exists(username='******', email='*****@*****.**')
    assert auth.User.exists(username='******', email='*****@*****.**')
    assert auth.User.exists(username='******', email='*****@*****.**')
    assert not auth.User.exists(username='******')
    assert not auth.User.exists(email='*****@*****.**')
示例#17
0
def test_data_to_store():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    user = auth.User.get_user(username='******')
    user.username = '******'
    user.email = '*****@*****.**'
    assert user._data_to_store == {
        'username': '******',
        'email': '*****@*****.**'
    }
示例#18
0
def test_email_belongs_to_account_validation():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    email_form = authforms.email_request_form()
    assert email_form.validates(web.storify({
        'email': user.email,
    })), email_form.note
    assert not email_form.validates(web.storify({
        'email': '*****@*****.**',
    }))
示例#19
0
def test_get_user_sets_cache():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    user = auth.User.get_user(username='******')
    assert web.ctx.auth_user_cache
    assert web.ctx.auth_user_cache.get('username')
    assert web.ctx.auth_user_cache.get('email')
    assert web.ctx.auth_user_cache.get('object')
    assert web.ctx.auth_user_cache.get('object') is user
    user = auth.User.get_user(username='******')
    assert web.ctx.auth_user_cache.get('object') is user
示例#20
0
def test_wrapper_reset_returns_code():
    user = auth.User(username='******', email='*****@*****.**')
    code = user.set_reset()
    assert code == user._act_code
示例#21
0
def test_create_user_missing_args():
    auth.User()
示例#22
0
def test_id_property_on_saved_account():
    user = auth.User(username='******', email='*****@*****.**')
    user.create()
    assert user.id == 1
示例#23
0
def test_id_property():
    user = auth.User(username='******', email='*****@*****.**')
    assert user.id is None
示例#24
0
def test_get_user_by_action_code():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    user.create()
    same_user = auth.User.get_user_by_act_code(user._act_code)
    assert same_user.username == 'myuser'
示例#25
0
def test_interaction_data_stored_properly():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    user.create()
    user = auth.User.get_user(username='******')
    assert user._act_type == 'a'
示例#26
0
def test_interaction_timely_when_no_interaction():
    user = auth.User(username='******', email='*****@*****.**')
    user.is_interaction_timely('a', 10)
示例#27
0
def test_interaction_with_wrong_type():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    user.is_interaction_timely('r', 10)
示例#28
0
def test_interaction_past_deadline():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    time.sleep(2)
    assert not user.is_interaction_timely('a', 1)
示例#29
0
def create_bad_username_check(string):
    auth.User(username=string, email="*****@*****.**")
示例#30
0
def test_interaction_timeout():
    user = auth.User(username='******', email='*****@*****.**')
    user.set_activation()
    assert user.is_interaction_timely(type='a', deadline=10)