def login(cls, email, password): try: u = Query(cls).equal_to('email', email).first() user.User().login(u.username, password) except Exception, e: print e return None
def test_cookie_session_middleware(): user = user_module.User() user._update_data(FAKE_USER_DATA) user_module.thread_locals.current_user = user app = CookieSessionMiddleware(application, b"wtf!", expires=3600, max_age=3600) add_wsgi_intercept(HOST, PORT, lambda: app) response = requests.get(URL) assert response.cookies["leancloud:session"] del user_module.thread_locals.current_user requests.get(URL, cookies=response.cookies) current = user_module.User.get_current() assert current.id == user.id assert current.get_session_token() == user.get_session_token() assert not current._attributes del user_module.thread_locals.current_user response = requests.get(URL + "/logout", cookies=response.cookies) assert "leancloud:session" not in response.cookies # TODO: try not using for..in to get cookie for cookie in response.cookies: if cookie.name == "leancloud:session": assert cookie.expires assert cookie.max_age break remove_wsgi_intercept()
def login_with_email(cls, email, password): try: username = Query(cls).equal_to('email', email).first().get('username') u = user.User(username=username, password=password) u.login() except LeanCloudError as e: print e.message return None else: return Query(cls).equal_to('username', username).first()
def test_set_and_get_read_access(): # type: () -> None user_acl = acl.ACL() user_acl.set_read_access("520", True) assert user_acl.permissions_by_id["520"]["read"] assert user_acl.get_read_access("520") user_acl = acl.ACL() test_user = user.User() test_user.id = "520" user_acl.set_read_access(test_user, True) assert user_acl.get_read_access(test_user) role_acl = acl.ACL() test_role = role.Role("520", role_acl) role_acl.set_read_access(test_role, True) assert role_acl.get_read_access(test_role)
def test_set_and_get_read_access(): user_acl = acl.ACL() user_acl.set_read_access(520, True) assert user_acl.permissions_by_id[520]['read'] assert user_acl.get_read_access(520) user_acl = acl.ACL() test_user = user.User() test_user.id = 520 user_acl.set_read_access(test_user, True) assert user_acl.get_read_access(test_user) role_acl = acl.ACL() test_role = role.Role('520', role_acl) role_acl.set_read_access(test_role, True) assert role_acl.get_read_access(test_role)
def test_set_and_get_read_access(): # type: () -> None user_acl = acl.ACL() user_acl.set_read_access('520', True) assert user_acl.permissions_by_id['520']['read'] assert user_acl.get_read_access('520') user_acl = acl.ACL() test_user = user.User() test_user.id = '520' user_acl.set_read_access(test_user, True) assert user_acl.get_read_access(test_user) role_acl = acl.ACL() test_role = role.Role('520', role_acl) role_acl.set_read_access(test_role, True) assert role_acl.get_read_access(test_role)
def register(cls, email, username, password): u = user.User(username=username, password=password, email=email) u.sign_up() u.login(username=username, password=password) return Query(cls).equal_to('username', username).first()