def test_create_user_already_exists(): username = '******' password = '******' mod.create_user(username, password) with pytest.raises(mod.UserAlreadyExists): mod.create_user(username, password)
def test_login_user_success(): old_session_id = mod.request.session.id username = '******' password = '******' mod.create_user(username, password) assert mod.login_user(username, password) assert mod.request.session.id != old_session_id assert mod.request.user.is_authenticated assert mod.request.user.username == username assert mod.request.user.options.to_native() == {}
def test_create_user(): username = '******' password = '******' mod.create_user(username, password) db = mod.request.db.sessions query = db.Select(sets='users', where='username = ?') db.query(query, username) user = db.result assert user.username == username assert user.is_superuser == 0 assert mod.is_valid_password(password, user.password)
def test_logout(): old_session_id = mod.request.session.id username = '******' password = '******' mod.create_user(username, password) assert mod.login_user(username, password) new_session_id = mod.request.session.id assert new_session_id != old_session_id assert mod.request.user.is_authenticated assert mod.request.user.username == username assert_session_count_is(1) mod.request.user.logout() assert mod.request.session.id != new_session_id assert_session_count_is(0)
def test_create_user_invalid_credentials(): with pytest.raises(mod.InvalidUserCredentials): mod.create_user('', '') with pytest.raises(mod.InvalidUserCredentials): mod.create_user(None, None) with pytest.raises(mod.InvalidUserCredentials): mod.create_user('mike', '') with pytest.raises(mod.InvalidUserCredentials): mod.create_user('', 'somepassword')
def test_login_user_invalid_username(): username = '******' password = '******' mod.create_user(username, password) assert mod.login_user('missing', 'invalid') is False assert not mod.request.user.is_authenticated