def test_state_wrong_auth(self):
        # This test agent is not in this auth
        url = 'http://testserver/XAPI/activities/state'
        testagent = '{"name":"joe","mbox":"mailto:joe@example.com"}'
        activityId = "http://www.iana.org/domains/example/"
        stateId = "id:the_state_id"
        activity = Activity(activity_id=activityId)
        activity.save()
        testparams = {"stateId": stateId, "activityId": activityId, "agent": testagent}
        teststate = {"test":"put activity state 1"}
        path = '%s?%s' % (url, urllib.urlencode(testparams))

        oauth_header_resource_params, access_token = self.oauth_handshake(scope_type='state')

        # 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 = self.client.put(path, data=teststate, content_type="application/json",
            Authorization=oauth_header_resource_params, X_Experience_API_Version=settings.XAPI_VERSION)
        self.assertEqual(put.status_code, 404)        
        self.assertEqual(put.content, "Agent in state cannot be found to match user in authorization")
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_OAuth.py/OAuthTests.test_state_wrong_auth/original