def test_save_in_user_check_permission():
    assert Role.query.all() == []
    create_user()
    role = Role.query.filter_by(name=app.config["USER_ROLE"])
    assert role.count() == 1
    with app.test_client() as c:
        assert getattr(g, "user", False) == False

        user = User.query.filter_by(email="*****@*****.**").first()
        assert user is not None

        user.set_password("test").save()
        Permissions.create(name="test_permissions")
        role = user.role
        role.permissions.append(Permissions(name="test_permissions_in_role"))
        role.save()

        login(c, "*****@*****.**", "test")
        assert getattr(g, "user").email == "*****@*****.**"

        c.get(url_for("account.sessions"))
        g_user = getattr(g, "user")
        assert g_user.email == "*****@*****.**"
        assert check_permission("test_permissions") == False
        assert check_permission("test_permissions_in_role") == True
示例#2
0
 def wrapper(*args, **kwargs):
     with app.test_request_context('/'):
         with app.test_client() as c:
             url_path = url_for(endpoint, **url_kwargs)
             kwargs.update({'url': url_path, 'client': c})
             response = func(*args, **kwargs)
     return response
示例#3
0
def test_valid_token_not_valid_data():
    url = url_for('account.confirm_reset', token=valid_user().create_token())
    with app.test_client() as c:
        resp = c.post(url, data={'password': '******', 'password_confirm': ''})
        assert resp.status_code == 200
        assert "Passwords don't match" in resp.data
        resp = c.post(url, data={'password': '', 'password_confirm': '111'})
        assert resp.status_code == 200
        assert "Passwords don't match" in resp.data
        resp = c.post(url, data={'password': '******', 'password_confirm': '222'})
        assert resp.status_code == 200
        assert "Passwords don't match" in resp.data
        resp = c.post(url, data={'password': '******', 'password_confirm': '111'})
        assert resp.status_code == 302
示例#4
0
def test_flask_invocation():
    with app.test_client() as c:
        resp = c.get('/')
        assert 'title' in resp.data
示例#5
0
def test_valid_token():
    url = url_for('account.confirm_reset', token=valid_user().create_token())
    with app.test_client() as c:
        resp = c.get(url)
        assert resp.status_code == 200