当前位置: 首页>>代码示例>>Python>>正文


Python JSONRequests.post方法代码示例

本文整理汇总了Python中WMCore.Services.Requests.JSONRequests.post方法的典型用法代码示例。如果您正苦于以下问题:Python JSONRequests.post方法的具体用法?Python JSONRequests.post怎么用?Python JSONRequests.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.Services.Requests.JSONRequests的用法示例。


在下文中一共展示了JSONRequests.post方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assignRequest

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import post [as 别名]
 def assignRequest(self,url,workflow,team,site,args={}):
     params = {"action": "Assign",
               "Team"+team: "checked",
               "SiteWhitelist": [],
               "SiteBlacklist": [],
               "MergedLFNBase": "/store/user",
               "UnmergedLFNBase": "/store/temp/user",
               "MinMergeSize": 1,
               "MaxMergeSize": 1,
               "MaxMergeEvents": 50000,
               #"AcquisitionEra": era,
               "maxRSS": 4294967296,
               "maxVSize": 4294967296,
               "dashboard": "CMSYAATAnalysis",
               "checkbox"+workflow: "checked"}
 
     request = JSONRequests(url)
     headers  =  {"Content-type": "application/x-www-form-urlencoded",
              "Accept": "text/plain"}
     request.post("/reqmgr/assign/handleAssignmentPage", params, headers)
     
     (data, status, reason, _) = request.getresponse()
     if status != 200:
         self.debugHttpError(data, status, reason)            
         raise RuntimeError, "POST failed with code %s" % status
     self.logger.info("Assigned the workflow %s" % workflow)
     
开发者ID:PerilousApricot,项目名称:CMSYAAT,代码行数:28,代码来源:WorkflowGenerator.py

示例2: makeRequest

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import post [as 别名]
    def makeRequest(self, url, params):
        request = JSONRequests(url)
        headers  =  {"Content-type": "application/x-www-form-urlencoded",
                 "Accept": "text/plain"}

        request.post("/reqmgr/create/makeSchema", params, headers)
    
        (data, status, reason, _) = request.getresponse()
        if status != 303:
            self.debugHttpError(data, status, reason)            
            raise RuntimeError, "POST failed with code %s" % status
            
        workflow=data.split("'")[1].split('/')[-1]
        self.logger.info('Injected workflow:',workflow,'into',url)
        return workflow
开发者ID:PerilousApricot,项目名称:CMSYAAT,代码行数:17,代码来源:WorkflowGenerator.py

示例3: ReqMgrTest

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import post [as 别名]

#.........这里部分代码省略.........
        return

    @attr("integration")
    def testB_ReReco(self):
        """
        _ReReco_

        Try a basic ReReco workflow
        """
        schema = self.setupSchema()
        schema["RequestNumEvents"] = 100
        schema["RequestEventSize"] = 101
        self.doRequest(schema)
        return

    def doRequest(self, schema):
        """
        _doRequest_

        Run all tests on a basic ReReco workflow
        """
        requestName = schema["RequestName"]
        self.assertRaises(HTTPException, self.jsonSender.delete, "request/%s" % requestName)
        result = self.jsonSender.put("request/%s" % (requestName), schema)
        self.assertEqual(result[1], 200)
        requestName = result[0]["RequestName"]

        self.assertEqual(self.jsonSender.get("request/%s" % requestName)[0]["RequestName"], requestName)

        self.jsonSender.put("request/%s?status=assignment-approved" % requestName)
        me = self.jsonSender.get("user/me")[0]
        self.assertTrue(requestName in me["requests"])
        self.assertEqual(self.jsonSender.put("request/%s?priority=5" % requestName)[1], 200)
        self.assertEqual(self.jsonSender.post("user/me?priority=6")[1], 200)
        self.assertEqual(self.jsonSender.post("group/PeopleLikeMe?priority=7")[1], 200)

        # default priority of group and user of 1
        request = self.jsonSender.get("request/%s" % requestName)[0]
        self.assertEqual(request["ReqMgrRequestBasePriority"], 5)
        self.assertEqual(request["ReqMgrRequestorBasePriority"], 6)
        self.assertEqual(request["ReqMgrGroupBasePriority"], 7)
        self.assertEqual(request["RequestPriority"], 5 + 6 + 7)

        # Check LFN Bases
        self.assertEqual(request["UnmergedLFNBase"], "/store/unmerged")
        self.assertEqual(request["MergedLFNBase"], "/store/data")

        # Check random other
        self.assertEqual(request["CustodialSite"], "US_T1_FNAL")

        # Check Num events
        self.assertEqual(request["RequestNumEvents"], 100)
        self.assertEqual(request["RequestEventSize"], 101)

        # only certain transitions allowed
        # self.assertEqual(self.jsonSender.put('request/%s?status=running' % requestName)[1], 400)
        self.assertRaises(HTTPException, self.jsonSender.put, "request/%s?status=running" % requestName)
        request = self.jsonSender.get("request/%s" % requestName)[0]
        self.assertEqual(request["RequestStatus"], "assignment-approved")

        self.assertTrue(self.jsonSender.put(urllib.quote("assignment/White Sox/%s" % requestName))[1] == 200)
        requestsAndSpecs = self.jsonSender.get(urllib.quote("assignment/White Sox"))[0]
        self.assertTrue(requestName in requestsAndSpecs[0])
        workloadHelper = WMWorkloadHelper()
        workloadHelper.load(requestsAndSpecs[0][1])
        self.assertEqual(workloadHelper.getOwner()["Requestor"], "me")
开发者ID:stuartw,项目名称:WMCore,代码行数:70,代码来源:ReqMgr_t.py

示例4: TestReqMgr

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import post [as 别名]
class TestReqMgr(RESTBaseUnitTest):
    """
    _TestReqMgr_

    Basic test for the ReqMgr services
    """

    def initialize(self):
        self.config = RequestManagerConfig(
                'WMCore.HTTPFrontEnd.RequestManager.ReqMgrRESTModel')
        dbUrl = os.environ.get("DATABASE", None)
        if dbUrl == None:
            raise RuntimeError, """The DATABASE environment is not set.  WARNING: setting this variable will cause the database to be deleted during cleanup! """
        self.config.setDBUrl(dbUrl)        
        self.config.setFormatter('WMCore.WebTools.RESTFormatter')
        self.config.setupRequestConfig()
        # mysql example
        #self.config.setDBUrl('mysql://[email protected]:3306/TestDB')
        #self.config.setDBSocket('/var/lib/mysql/mysql.sock')
        self.schemaModules = ["WMCore.RequestManager.RequestDB"]
        # Do this is you don't want to remake and delete the schema
        #self.schemaModules = []
        
    def setUp(self):
        """
        setUP global values
        """
        RESTBaseUnitTest.setUp(self)
        reqMgrHost = self.config.getServerUrl()
        self.requestSchema = getRequestSchema()
        print reqMgrHost
        self.jsonSender = JSONRequests(reqMgrHost)
        #self.requestTypes = ['ReReco', 'StoreResults', 'CmsGen', 'Reco']
        #self.requestTypes = ['ReReco', 'MonteCarlo']
        self.requestTypes = ['ReReco']

        if 'me' in self.jsonSender.get('user')[0]:
            self.jsonSender.delete('user/me')    
        self.assertFalse('me' in self.jsonSender.get('user')[0])
        self.assertEqual(self.jsonSender.put('user/[email protected]')[1], 200)
        self.assertTrue('me' in self.jsonSender.get('user')[0])

        if 'PeopleLikeMe' in self.jsonSender.get('group')[0]:
            self.jsonSender.delete('group/PeopleLikeMe')
        self.assertFalse('PeopleLikeMe' in self.jsonSender.get('group')[0])
        self.assertEqual(self.jsonSender.put('group/PeopleLikeMe')[1], 200)
        self.assertTrue( 'PeopleLikeMe' in self.jsonSender.get('group')[0])

        self.jsonSender.put('group/PeopleLikeMe/me')
        users = json.loads(self.jsonSender.get('group/PeopleLikeMe')[0])['users']
        self.assertTrue('me' in users)
        groups = json.loads(self.jsonSender.get('user/me')[0])['groups']
        self.assertTrue('PeopleLikeMe' in groups)
        groups2 = self.jsonSender.get('group?user=me')[0]
        self.assertTrue('PeopleLikeMe' in groups2)

        if 'White Sox' in self.jsonSender.get('team')[0]:
            self.jsonSender.delete(urllib.quote('team/White Sox'))
        self.assertFalse('White Sox' in self.jsonSender.get('team')[0])
        self.assertEqual(self.jsonSender.put(urllib.quote('team/White Sox'))[1], 200)
        self.assertTrue('White Sox' in self.jsonSender.get('team')[0])

        # some foreign key stuff to dealwith
        #self.assertFalse('CMSSW_X_Y_Z' in self.jsonSender.get('version')[0])
        self.assertTrue(self.jsonSender.put('version/CMSSW_3_5_8')[1] == 200)
        self.assertTrue('CMSSW_3_5_8' in self.jsonSender.get('version')[0])

    @attr("integration")
    def testReReco(self):
        schema = ReReco.getTestArguments()
        schema['RequestName'] = 'TestReReco'
        schema['RequestType'] = 'ReReco'
        schema['CmsPath'] = "/uscmst1/prod/sw/cms"
        self.doRequest(schema)

    def doRequest(self, schema):
        schema['CmsPath'] = "/uscmst1/prod/sw/cms"
        schema['Requestor'] = 'me'
        schema['Group'] = 'PeopleLikeMe'
        requestName = schema['RequestName']
        self.assertRaises(HTTPException, self.jsonSender.delete, 'request/%s' % requestName)
        self.assertEqual(self.jsonSender.put('request/%s' % requestName, schema)[1], 200)

        self.assertEqual(self.jsonSender.get('request/%s' % requestName)[0]['RequestName'], requestName)
        self.assertTrue(requestName in self.jsonSender.get('user/me')[0])

        self.jsonSender.put('request/%s?status=assignment-approved' % requestName)
        meJSON = self.jsonSender.get('user/me')[0]
        me = json.loads(meJSON)
        self.assertTrue(requestName in me['requests'])
        self.assertEqual(self.jsonSender.put('request/%s?priority=5' % requestName)[1], 200)
        self.assertEqual(self.jsonSender.post('user/me?priority=6')[1], 200)
        self.assertEqual(self.jsonSender.post('group/PeopleLikeMe?priority=7')[1], 200)

        # default priority of group and user of 1
        request = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(request['ReqMgrRequestBasePriority'], 5)
        self.assertEqual(request['ReqMgrRequestorBasePriority'], 6)
        self.assertEqual(request['ReqMgrGroupBasePriority'], 7)
        self.assertEqual(request['RequestPriority'], 5+6+7)
#.........这里部分代码省略.........
开发者ID:zhiwenuil,项目名称:WMCore,代码行数:103,代码来源:ReqMgr_t.py

示例5: ReqMgrTest

# 需要导入模块: from WMCore.Services.Requests import JSONRequests [as 别名]
# 或者: from WMCore.Services.Requests.JSONRequests import post [as 别名]

#.........这里部分代码省略.........

        request = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(request['RequestPriority'], 5)

        # Check LFN Bases
        self.assertEqual(request['UnmergedLFNBase'], '/store/unmerged')
        self.assertEqual(request['MergedLFNBase'], '/store/data')

        # Check Num events
        self.assertEqual(request['RequestNumEvents'], 100)
        self.assertEqual(request['SizePerEvent'], 101)

        # only certain transitions allowed
        #self.assertEqual(self.jsonSender.put('request/%s?status=running' % requestName)[1], 400)
        self.assertRaises(HTTPException, self.jsonSender.put,'request/%s?status=running' % requestName)
        request = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(request['RequestStatus'], 'assignment-approved')

        self.assertTrue(self.jsonSender.put(urllib.quote('assignment/White Sox/%s' % requestName))[1] == 200)
        requestsAndSpecs = self.jsonSender.get(urllib.quote('assignment/White Sox'))[0]
        self.assertTrue(requestName in requestsAndSpecs[0])
        workloadHelper = WMWorkloadHelper()
        workloadHelper.load(requestsAndSpecs[0][1]) 
        self.assertEqual(workloadHelper.getOwner()['Requestor'], "me")
        self.assertEqual(self.jsonSender.get('assignment?request=%s'% requestName)[0], ['White Sox'])
        self.assertEqual(self.jsonSender.get('request/%s' % requestName)[0]['teams'], ['White Sox'])

        agentUrl = 'http://cmssrv96.fnal.gov/workqueue'
        self.jsonSender.put('workQueue/%s?url=%s'% (requestName, urllib.quote(agentUrl)) )
        self.assertEqual(self.jsonSender.get('workQueue/%s' % requestName)[0][0], agentUrl)
        request = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(request['RequestStatus'], 'acquired')

        self.jsonSender.post('request/%s?events_written=10&files_merged=1' % requestName)
        self.jsonSender.post('request/%s?events_written=20&files_merged=2&percent_success=99.9' % requestName)
        request = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(len(request['RequestUpdates']), 2)
        self.assertEqual(request['RequestUpdates'][0]['files_merged'], 1)
        self.assertEqual(request['RequestUpdates'][1]['events_written'], 20)
        self.assertEqual(request['RequestUpdates'][1]['percent_success'], 99.9)

        message = "The sheriff is near"
        jsonMessage = json.dumps(message)
        self.jsonSender.put('message/%s' % requestName, message)
        messages = self.jsonSender.get('message/%s' % requestName)
        #self.assertEqual(messages[0][0][0], message)
        for status in ['running-open', 'running-closed', 'completed']:
            self.jsonSender.put('request/%s?status=%s' % (requestName, status))

        # campaign
        self.jsonSender.put('campaign/%s' % 'TestCampaign')
        campaigns = self.jsonSender.get('campaign')[0]
        self.assertTrue('TestCampaign' in campaigns.keys())
        self.jsonSender.put('campaign/%s/%s' % ('TestCampaign', requestName))
        requestsInCampaign = self.jsonSender.get('campaign/%s' % 'TestCampaign')[0]
        self.assertTrue(requestName in requestsInCampaign.keys())

        req = self.jsonSender.get('request/%s' % requestName)[0]
        self.assertEqual(req['Campaign'], 'TestCampaign')
        self.jsonSender.delete('request/%s' % requestName)
        

    @attr("integration")
    def testC_404Errors(self):
        """
        _404Errors_
开发者ID:BrunoCoimbra,项目名称:WMCore,代码行数:70,代码来源:ReqMgr_t.py


注:本文中的WMCore.Services.Requests.JSONRequests.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。