def test_create_permissions_string(self): permissions1 = ['read_stream','user_birthday','user_hometown'] permissions2 = [' read_stream','user_birthday ',' user_hometown '] permissions3 = [] permissions1 = _create_permissions_string(permissions1) permissions2 = _create_permissions_string(permissions2) permissions3 = _create_permissions_string(permissions3) self.assertEquals('read_stream,user_birthday,user_hometown', permissions1) self.assertEquals('read_stream,user_birthday,user_hometown', permissions2) self.assertEquals('', permissions3)
def test_create_permissions_string(self): permissions1 = ['read_stream', 'user_birthday', 'user_hometown'] permissions2 = [' read_stream', 'user_birthday ', ' user_hometown '] permissions3 = [] permissions1 = _create_permissions_string(permissions1) permissions2 = _create_permissions_string(permissions2) permissions3 = _create_permissions_string(permissions3) self.assertEquals('read_stream,user_birthday,user_hometown', permissions1) self.assertEquals('read_stream,user_birthday,user_hometown', permissions2) self.assertEquals('', permissions3)
def _create_test_user_on_facebook(app_installed=True, name=None, permissions=None, access_token=None): """ Creates a test user on facebook. Returns a dict of the json response from facebook. """ test_user_template = "https://graph.facebook.com/%s/accounts/test-users?installed=%s&permissions=%s&method=post&access_token=%s" # Generate the request URL if app_installed == True: app_installed = "true" else: app_installed = "false" if permissions is None: permissions = settings.FACEBOOK_APPLICATION_INITIAL_PERMISSIONS permissions = _create_permissions_string(permissions) if access_token is None: access_token = _get_app_access_token() test_user_url = test_user_template % (settings.FACEBOOK_APPLICATION_ID, app_installed, permissions, access_token) if name: test_user_url = '%s&name=%s' % (test_user_url, urllib.quote(name)) # Request a new test user from facebook for attempts in range(3, 0, -1): r = requests.get(test_user_url) try: data = json.loads(r.content) except: data = None if r.status_code != 200 or data is None or data == False or 'error' in data: continue return data else: try: raise CreateTestUserError(data['error']['message']) except CreateTestUserError: raise except: try: raise CreateTestUserError( "Request to create test user failed (status_code=%s and content=\"%s\")" % (r.status_code, r.content)) except CreateTestUserError: raise except: raise CreateTestUserError( "Request to create test user failed (status_code=%s)" % r.status_code) raise CreateTestUserError("Request to create test user failed")
def _create_test_user_on_facebook(app_installed=True, name=None, permissions=None, access_token=None): """ Creates a test user on facebook. Returns a dict of the json response from facebook. """ test_user_template = "https://graph.facebook.com/%s/accounts/test-users?installed=%s&permissions=%s&method=post&access_token=%s" # Generate the request URL if app_installed == True: app_installed = "true" else: app_installed = "false" if permissions is None: permissions = settings.FACEBOOK_APPLICATION_INITIAL_PERMISSIONS permissions = _create_permissions_string(permissions) if access_token is None: access_token = _get_app_access_token() test_user_url = test_user_template % (settings.FACEBOOK_APPLICATION_ID, app_installed, permissions, access_token) if name: test_user_url = '%s&name=%s' % (test_user_url,urllib.quote(name)) # Request a new test user from facebook for attempts in range(3, 0, -1): r = requests.get(test_user_url) try: data = json.loads(r.content) except: data = None if r.status_code != 200 or data is None or data == False or 'error' in data: continue return data else: try: raise CreateTestUserError(data['error']['message']) except CreateTestUserError: raise except: try: raise CreateTestUserError("Request to create test user failed (status_code=%s and content=\"%s\")" % (r.status_code, r.content)) except CreateTestUserError: raise except: raise CreateTestUserError("Request to create test user failed (status_code=%s)" % r.status_code) raise CreateTestUserError("Request to create test user failed")