def test_unicode(self):
        # All client requests have the auth as unicode
        # ============= INITIATE =============
        param = {
                    'scope':'all',
                    'consumer_name':'new_client'
                }
        request_token_path = "%s?%s" % (INITIATE_ENDPOINT, urllib.urlencode(param)) 
        # Header params we're passing in
        oauth_header_request_token_params = "OAuth realm=\"test\","\
               "oauth_consumer_key=\"%s\","\
               "oauth_signature_method=\"HMAC-SHA1\","\
               "oauth_timestamp=\"%s\","\
               "oauth_nonce=\"12345678\","\
               "oauth_version=\"1.0\","\
               "oauth_callback=\"http://example.com/access_token_ready\"" % (self.consumer.key,str(int(time.time())))

        # Make the params into a dict to pass into from_consumer_and_token
        request_token_param_list = oauth_header_request_token_params.split(",")
        oauth_header_request_token_params_dict = {}
        for p in request_token_param_list:
            item = p.split("=")
            oauth_header_request_token_params_dict[str(item[0]).strip()] = str(item[1]).strip('"')
        
        # get_oauth_request in views ignores realm, must remove so not input to from_token_and_callback
        del oauth_header_request_token_params_dict['OAuth realm']

        # add scope to the existing params
        oauth_request = oauth.Request.from_consumer_and_token(self.consumer, token=None, http_method='GET',
            http_url=request_token_path, parameters=oauth_header_request_token_params_dict)
        
        # create signature and add it to the header params
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer, None)
        oauth_header_request_token_params = oauth_header_request_token_params + ",oauth_signature=%s" % signature

        request_resp = self.client.get(request_token_path, Authorization=unicode(oauth_header_request_token_params))
        self.assertEqual(request_resp.status_code, 200)
        self.assertIn('oauth_token_secret', request_resp.content)
        self.assertIn('oauth_token', request_resp.content)
        self.assertIn('oauth_callback_confirmed', request_resp.content)
        token = Token.objects.get(consumer=self.consumer)
        # ============= END INITIATE =============

        # ============= AUTHORIZE =============
        param = {'oauth_token': token.key}
        authorize_path = "%s?%s" % (AUTHORIZATION_ENDPOINT, urllib.urlencode(param)) 

        auth_resp = self.client.get(authorize_path)
        self.assertEqual(auth_resp.status_code, 302)
        self.assertIn('/accounts/login?next=/XAPI/OAuth/authorize%3F', auth_resp['Location'])
        self.assertIn(token.key, auth_resp['Location'])    
        self.client.login(username='jane', password='toto')
        self.assertEqual(token.is_approved, False)
        # After being redirected to login and logging in again, try get again
        auth_resp = self.client.get(authorize_path)
        self.assertEqual(auth_resp.status_code, 200) # Show return/display OAuth authorized view
        
        auth_form = auth_resp.context['form']
        data = auth_form.initial
        data['authorize_access'] = 1
        data['oauth_token'] = token.key

        auth_post = self.client.post(AUTHORIZATION_ENDPOINT, data)
        self.assertEqual(auth_post.status_code, 302)
        # Check if oauth_verifier and oauth_token are returned
        self.assertIn('http://example.com/access_token_ready?oauth_verifier=', auth_post['Location'])
        self.assertIn('oauth_token=', auth_post['Location'])
        request_token = Token.objects.get(consumer=self.consumer)
        self.assertIn(request_token.key, auth_post['Location'])
        self.assertEqual(request_token.is_approved, True)
        #  ============= END AUTHORIZE =============

        # ============= ACCESS TOKEN =============
        oauth_header_access_params = "OAuth realm=\"test\","\
            "oauth_consumer_key=\"%s\","\
            "oauth_token=\"%s\","\
            "oauth_signature_method=\"HMAC-SHA1\","\
            "oauth_timestamp=\"%s\","\
            "oauth_nonce=\"87654321\","\
            "oauth_version=\"1.0\","\
            "oauth_verifier=\"%s\"" % (self.consumer.key,token.key,str(int(time.time())),request_token.verifier)

        # from_token_and_callback takes a dictionary        
        param_list = oauth_header_access_params.split(",")
        oauth_header_access_params_dict = {}
        for p in param_list:
            item = p.split("=")
            oauth_header_access_params_dict[str(item[0]).strip()] = str(item[1]).strip('"')
        
        # from_request ignores realm, must remove so not input to from_token_and_callback
        del oauth_header_access_params_dict['OAuth realm']
        oauth_request = oauth.Request.from_token_and_callback(request_token, http_method='GET',
            http_url=TOKEN_ENDPOINT, parameters=oauth_header_access_params_dict)

        # Create signature and add it to the headers
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer, request_token)
        oauth_header_access_params += ',oauth_signature="%s"' % signature

        access_resp = self.client.get(TOKEN_ENDPOINT, Authorization=unicode(oauth_header_access_params))
        self.assertEqual(access_resp.status_code, 200)
        content = access_resp.content.split('&')
        access_token_secret = content[0].split('=')[1]
        access_token_key = content[1].split('=')[1]
        access_token = Token.objects.get(secret=access_token_secret, key=access_token_key)
        #  ============= END ACCESS TOKEN =============

        # ============= ACCESS RESOURCE =============
        oauth_header_resource_params = "OAuth realm=\"test\", "\
            "oauth_consumer_key=\"%s\","\
            "oauth_token=\"%s\","\
            "oauth_signature_method=\"HMAC-SHA1\","\
            "oauth_timestamp=\"%s\","\
            "oauth_nonce=\"accessresourcenonce\","\
            "oauth_version=\"1.0\"" % (self.consumer.key, access_token.key, str(int(time.time())))

        # from_token_and_callback takes a dictionary        
        param_list = oauth_header_resource_params.split(",")
        oauth_header_resource_params_dict = {}
        for p in param_list:
            item = p.split("=")
            oauth_header_resource_params_dict[str(item[0]).strip()] = str(item[1]).strip('"')
        
        # from_request ignores realm, must remove so not input to from_token_and_callback
        del oauth_header_resource_params_dict['OAuth realm']

        path = TEST_SERVER + "/XAPI/statements"
        oauth_request = oauth.Request.from_token_and_callback(access_token, http_method='GET',
            http_url=path, parameters=oauth_header_resource_params_dict)

        # Create signature and add it to the headers
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer, access_token)
        oauth_header_resource_params += ',oauth_signature="%s"' % signature

        resp = self.client.get(path, Authorization=unicode(oauth_header_resource_params), X_Experience_API_Version=settings.XAPI_VERSION)
        self.assertEqual(resp.status_code, 200)
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_OAuth.py/OAuthTests.test_unicode/original