def test_define_scope_activity(self):
        url = 'http://testserver/XAPI/statements'
        guid = str(uuid.uuid1())
        stmt_data = {"id":guid,"actor":{"objectType": "Agent",
            "mbox":"mailto:bob@bob.com", "name":"bob"},"verb":{"id": "http://example.com/verbs/passed",
            "display": {"en-US":"passed"}},"object": {"id":"test://test/define/scope"},
            "authority":{"objectType":"Agent", "mbox":"mailto:jane@example.com"}}
        stmt_post = self.client.post(reverse('lrs:statements'), json.dumps(stmt_data), content_type="application/json",
            Authorization=self.jane_auth, X_Experience_API_Version=settings.XAPI_VERSION)
        self.assertEqual(stmt_post.status_code, 200)

        # build stmt data and path
        put_guid = str(uuid.uuid1())
        stmt = json.dumps({"actor":{"objectType": "Agent", "mbox":"mailto:bill@bill.com", "name":"bill"},
            "verb":{"id": "http://example.com/verbs/accessed","display": {"en-US":"accessed"}},
            "object": {"id":"test://test/define/scope",
            'definition': {'name': {'en-US':'testname', 'en-GB': 'altname'},
            'description': {'en-US':'testdesc', 'en-GB': 'altdesc'},'type': 'type:course',
            'interactionType': 'other', 'correctResponsesPattern':[]}}})

        param = {"statementId":put_guid}
        path = "%s?%s" % (url, urllib.urlencode(param))
        
        # START PUT STMT
        oauth_header_resource_params, access_token = self.oauth_handshake(scope_type='statements/write statements/read')
        
        # 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']

        # Create oauth request and add signature
        oauth_request = oauth.Request.from_token_and_callback(access_token, http_method='PUT',
            http_url=path, parameters=oauth_header_resource_params_dict)
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer, access_token)
        oauth_header_resource_params += ',oauth_signature="%s"' % signature
        
        # Put statements - does not have define scope, therefore it cannot update the activity
        resp = self.client.put(path, data=stmt, content_type="application/json",
            Authorization=oauth_header_resource_params, X_Experience_API_Version=settings.XAPI_VERSION)

        self.assertEqual(resp.status_code, 204)
        acts = Activity.objects.all()
        self.assertEqual(len(acts), 1)
        # ==========================================================

        # START GET STMT
        get_params = {"activity":"test://test/define/scope"}
        path = "%s?%s" % (url, urllib.urlencode(get_params)) 

        # User same oauth headers, change nonce
        oauth_header_resource_params_dict['oauth_nonce'] = 'get_differ_nonce'

        # Create oauth request and add signature
        oauth_request2 = oauth.Request.from_token_and_callback(access_token, http_method='GET',
            http_url=path, parameters=oauth_header_resource_params_dict)
        signature_method2 = oauth.SignatureMethod_HMAC_SHA1()
        signature2 = signature_method2.sign(oauth_request2, self.consumer, access_token)
        sig = oauth_header_resource_params.replace('"%s"' % signature, '"%s"' % signature2)
        new_oauth_headers = sig.replace('oauth_nonce="resource_nonce"','oauth_nonce="get_differ_nonce"')        

        get_resp = self.client.get(path, X_Experience_API_Version=settings.XAPI_VERSION, Authorization=new_oauth_headers)
        self.assertEqual(get_resp.status_code, 200)
        content = json.loads(get_resp.content)
        self.assertEqual(len(content['statements']), 2)
        self.client.logout()
        # ==========================================================

        # START OF POST WITH ANOTHER HANDSHAKE
        post_stmt = {"actor":{"objectType": "Agent", "mbox":"mailto:dom@dom.com", "name":"dom"},
            "verb":{"id": "http://example.com/verbs/tested","display": {"en-US":"tested"}},
            "object": {"id":"test://test/define/scope",
            'definition': {'name': {'en-US':'definename', 'en-GB': 'definealtname'},
            'description': {'en-US':'definedesc', 'en-GB': 'definealtdesc'},'type': 'type:course',
            'interactionType': 'other', 'correctResponsesPattern':[]}}}
        stmt_json = json.dumps(post_stmt)

        post_oauth_header_resource_params, post_access_token = self.oauth_handshake2(scope_type='define statements/write')

        # from_token_and_callback takes a dictionary        
        post_param_list = post_oauth_header_resource_params.split(",")
        post_oauth_header_resource_params_dict = {}
        for p in post_param_list:
            item = p.split("=")
            post_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 post_oauth_header_resource_params_dict['OAuth realm']
        
        # Create oauth request and add signature
        post_oauth_request = oauth.Request.from_token_and_callback(post_access_token, http_method='POST',
            http_url='http://testserver/XAPI/statements/',
            parameters=post_oauth_header_resource_params_dict)
        post_signature_method = oauth.SignatureMethod_HMAC_SHA1()
        post_signature = post_signature_method.sign(post_oauth_request, self.consumer2, post_access_token)
        post_oauth_header_resource_params += ',oauth_signature="%s"' % post_signature  

        # Even though dick has define scope, he didn't create the activity so he can't update it
        post = self.client.post('/XAPI/statements/', data=stmt_json, content_type="application/json",
            Authorization=post_oauth_header_resource_params, X_Experience_API_Version=settings.XAPI_VERSION)
        self.assertEqual(post.status_code, 200)
        acts = Activity.objects.all()
        self.assertEqual(len(acts), 1)
        self.assertNotIn("definition", acts[0].return_activity_with_lang_format().keys())
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_OAuth.py/OAuthTests.test_define_scope_activity/original