def test_auth_correct(self):
        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=\"PLAINTEXT\","\
               "oauth_timestamp=\"%s\","\
               "oauth_nonce=\"requestnonce\","\
               "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_PLAINTEXT()
        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=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)
        # ===================================================

        # Test 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'])
        access_token = Token.objects.get(consumer=self.consumer)
        self.assertIn(access_token.key, auth_post['Location'])
        self.assertEqual(access_token.is_approved, True)
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_OAuth.py/OAuthTests.test_auth_correct/original