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
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
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
def test_flask_invocation(): with app.test_client() as c: resp = c.get('/') assert 'title' in resp.data
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