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


Python Request.toJSON方法代码示例

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


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

示例1: test01CtorSerilization

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
  def test01CtorSerilization( self ):
    """ c'tor and serialization """
    # # empty c'tor
    req = Request()
    self.assertEqual( isinstance( req, Request ), True )
    self.assertEqual( req.JobID, 0 )
    self.assertEqual( req.Status, "Waiting" )

    req = Request( self.fromDict )
    self.assertEqual( isinstance( req, Request ), True )
    self.assertEqual( req.RequestName, "test" )
    self.assertEqual( req.JobID, 12345 )
    self.assertEqual( req.Status, "Waiting" )

    toJSON = req.toJSON()
    self.assertEqual( toJSON["OK"], True, "JSON serialization failed" )

    fromJSON = toJSON["Value"]
    req = Request( fromJSON )

    toSQL = req.toSQL()
    self.assertEqual( toSQL["OK"], True )
    toSQL = toSQL["Value"]
    self.assertEqual( toSQL.startswith( "INSERT" ), True )

    req.RequestID = 1

    toSQL = req.toSQL()
    self.assertEqual( toSQL["OK"], True )
    toSQL = toSQL["Value"]
    self.assertEqual( toSQL.startswith( "UPDATE" ), True )
开发者ID:IgorPelevanyuk,项目名称:DIRAC,代码行数:33,代码来源:RequestTests.py

示例2: RequestTaskTests

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
class RequestTaskTests( unittest.TestCase ):
  """
  .. class:: RequestTaskTests

  """

  def setUp( self ):
    """ test case set up """
    self.handlersDict = { "ForwardDISET" : "DIRAC/RequestManagementSystem/private/ForwardDISET" }
    self.req = Request()
    self.req.RequestName = "foobarbaz"
    self.req.OwnerGroup = "lhcb_user"
    self.req.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=chaen/CN=705305/CN=Christophe Haen"
    self.op = Operation( { "Type": "ForwardDISET", "Arguments" : "tts10:helloWorldee" } )
    self.req.addOperation( self.op )
    self.task = None
    self.mockRC = MagicMock()

    self.mockObjectOps = MagicMock()
    self.mockObjectOps.getSections.return_value = {'OK': True,
                                                   'Value': ['DataProcessing',
                                                             'DataManager']}
    self.mockObjectOps.getOptionsDict.return_value = {'OK': True,
                                                      'Value': {'Group': 'lhcb_user', 'User': 'fstagni'}}
    self.mockOps = MagicMock()
    self.mockOps.return_value = self.mockObjectOps


  def tearDown( self ):
    """ test case tear down """
    del self.req
    del self.op
    del self.task

  def testAPI( self ):
    """ test API
    """
    rt = importlib.import_module( 'DIRAC.RequestManagementSystem.private.RequestTask' )
    rt.gMonitor = MagicMock()
    rt.Operations = self.mockOps
    rt.CS = MagicMock()

    self.task = RequestTask( self.req.toJSON()["Value"], self.handlersDict, 'csPath', 'RequestManagement/RequestExecutingAgent',
                             requestClient = self.mockRC )
    self.task.requestClient = Mock( return_value = Mock( spec = ReqClient ) )
    self.task.requestClient().updateRequest = Mock()
    self.task.requestClient().updateRequest.return_value = { "OK" : True, "Value" : None }
    ret = self.task()
    self.assertEqual( ret["OK"], True , "call failed" )

    ret = self.task.setupProxy()
    print ret
开发者ID:DIRACGrid-test,项目名称:DIRAC,代码行数:54,代码来源:RequestTaskTests.py

示例3: ReqClientTestCase

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
class ReqClientTestCase(unittest.TestCase):
  """
  .. class:: ReqClientTestCase

  """

  def setUp(self):
    """ test case set up """

    gLogger.setLevel('INFO')

    self.file = File()
    self.file.LFN = "/lhcb/user/c/cibak/testFile"
    self.file.Checksum = "123456"
    self.file.ChecksumType = "ADLER32"

    self.file2 = File()
    self.file2.LFN = "/lhcb/user/f/fstagni/testFile"
    self.file2.Checksum = "654321"
    self.file2.ChecksumType = "ADLER32"

    self.operation = Operation()
    self.operation.Type = "ReplicateAndRegister"
    self.operation.TargetSE = "CERN-USER"
    self.operation.addFile(self.file)
    self.operation.addFile(self.file2)

    proxyInfo = getProxyInfo()['Value']
    self.request = Request()
    self.request.RequestName = "RequestManagerHandlerTests"
    self.request.OwnerDN = proxyInfo['identity']
    self.request.OwnerGroup = proxyInfo['group']
    self.request.JobID = 123
    self.request.addOperation(self.operation)

    # # JSON representation of a whole request
    self.jsonStr = self.request.toJSON()['Value']
    # # request client
    self.requestClient = ReqClient()

    self.stressRequests = 1000
    self.bulkRequest = 1000

  def tearDown(self):
    """ clean up """
    del self.request
    del self.operation
    del self.file
    del self.jsonStr
开发者ID:marianne013,项目名称:DIRAC,代码行数:51,代码来源:Test_Client_Req.py

示例4: ReqClientTestCase

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
class ReqClientTestCase( unittest.TestCase ):
  """
  .. class:: ReqClientTestCase

  """

  def setUp( self ):
    """ test case set up """

    gLogger.setLevel( 'NOTICE' )

    self.file = File()
    self.file.LFN = "/lhcb/user/c/cibak/testFile"
    self.file.Checksum = "123456"
    self.file.ChecksumType = "ADLER32"

    self.file2 = File()
    self.file2.LFN = "/lhcb/user/f/fstagni/testFile"
    self.file2.Checksum = "654321"
    self.file2.ChecksumType = "ADLER32"

    self.operation = Operation()
    self.operation.Type = "ReplicateAndRegister"
    self.operation.TargetSE = "CERN-USER"
    self.operation.addFile( self.file )
    self.operation.addFile( self.file2 )

    self.request = Request()
    self.request.RequestName = "RequestManagerHandlerTests"
    self.request.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
    self.request.OwnerGroup = "dirac_user"
    self.request.JobID = 123
    self.request.addOperation( self.operation )

    # # JSON representation of a whole request
    self.jsonStr = self.request.toJSON()['Value']
    # # request client
    self.requestClient = ReqClient()

    self.stressRequests = 1000
    self.bulkRequest = 1000


  def tearDown( self ):
    """ clean up """
    del self.request
    del self.operation
    del self.file
    del self.jsonStr
开发者ID:zimmerst,项目名称:TestDIRAC,代码行数:51,代码来源:TestClientReq.py

示例5: test07List

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
  def test07List( self ):
    """ setitem, delitem, getitem and dirty """

    r = Request()

    ops = [ Operation() for i in range( 5 ) ]

    for op in ops:
      r.addOperation( op )

    for i, op in enumerate( ops ):
      self.assertEqual( op, r[i], "__getitem__ failed" )

    op = Operation()
    r[0] = op
    self.assertEqual( op, r[0], "__setitem__ failed" )

    del r[0]
    self.assertEqual( len( r ), 4, "__delitem__ failed" )

    r.RequestID = 1
    del r[0]
    self.assertEqual( r.cleanUpSQL(), None, "cleanUpSQL failed after __delitem__ (no opId)" )

    r[0].OperationID = 1
    del r[0]
    clean = r.cleanUpSQL()
    self.assertEqual( clean,
                      ['DELETE FROM `Operation` WHERE `RequestID`=1 AND `OperationID` IN (1);\n',
                       'DELETE FROM `File` WHERE `OperationID`=1;\n'],
                      "cleanUpSQL failed after __delitem__ (opId set)\n%s" % clean )

    r[0].OperationID = 2
    r[0] = Operation()
    clean = r.cleanUpSQL()
    self.assertEqual( clean,
                      ['DELETE FROM `Operation` WHERE `RequestID`=1 AND `OperationID` IN (1,2);\n',
                      'DELETE FROM `File` WHERE `OperationID`=1;\n', 'DELETE FROM `File` WHERE `OperationID`=2;\n'],
                      "cleanUpSQL failed after __setitem_ (opId set):\n%s" % clean )

    json = r.toJSON()
    self.assertEqual( "__dirty" in json["Value"], True, "__dirty missing in json" )

    r2 = Request( json["Value"] )
    self.assertEqual( r.cleanUpSQL(), r2.cleanUpSQL(), "wrong cleanUpSQL after json" )
开发者ID:Teddy22,项目名称:DIRAC,代码行数:47,代码来源:RequestTests.py

示例6: test04Operations

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
  def test04Operations( self ):
    """ operations arithmetic and state machine """
    req = Request()
    self.assertEqual( len( req ), 0 )

    transfer = Operation()
    transfer.Type = "ReplicateAndRegister"
    transfer.addFile( File( { "LFN" : "/a/b/c", "Status" : "Waiting" } ) )

    getWaiting = req.getWaiting()
    self.assertEqual( getWaiting["OK"], True )
    self.assertEqual( getWaiting["Value"], None )

    req.addOperation( transfer )
    self.assertEqual( len( req ), 1 )
    self.assertEqual( transfer.Order, req.Order )
    self.assertEqual( transfer.Status, "Waiting" )

    getWaiting = req.getWaiting()
    self.assertEqual( getWaiting["OK"], True )
    self.assertEqual( getWaiting["Value"], transfer )

    removal = Operation( { "Type" : "RemoveFile" } )
    removal.addFile( File( { "LFN" : "/a/b/c", "Status" : "Waiting" } ) )

    req.insertBefore( removal, transfer )

    getWaiting = req.getWaiting()
    self.assertEqual( getWaiting["OK"], True )
    self.assertEqual( getWaiting["Value"], removal )

    self.assertEqual( len( req ), 2 )
    self.assertEqual( [ op.Status for op in req ], ["Waiting", "Queued"] )
    self.assertEqual( req.subStatusList() , ["Waiting", "Queued"] )


    self.assertEqual( removal.Order, 0 )
    self.assertEqual( removal.Order, req.Order )

    self.assertEqual( transfer.Order, 1 )

    self.assertEqual( removal.Status, "Waiting" )
    self.assertEqual( transfer.Status, "Queued" )

    for subFile in removal:
      subFile.Status = "Done"
    removal.Status = "Done"

    self.assertEqual( removal.Status, "Done" )

    self.assertEqual( transfer.Status, "Waiting" )
    self.assertEqual( transfer.Order, req.Order )

    # # len, looping
    self.assertEqual( len( req ), 2 )
    self.assertEqual( [ op.Status for op in req ], ["Done", "Waiting"] )
    self.assertEqual( req.subStatusList() , ["Done", "Waiting"] )

    digest = req.toJSON()
    self.assertEqual( digest["OK"], True )

    getWaiting = req.getWaiting()
    self.assertEqual( getWaiting["OK"], True )
    self.assertEqual( getWaiting["Value"], transfer )
开发者ID:JanEbbing,项目名称:DIRAC,代码行数:66,代码来源:RequestTests.py

示例7: ReqClient

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.Request import Request [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.Request.Request import toJSON [as 别名]
requestClient = ReqClient()
requestOperation = 'replicateAndRegister'

for lfnList in breakListIntoChunks( lfns, 100 ):

  oRequest = Request()
  oRequest.RequestName = "%s_%s" % ( md5( repr( time.time() ) ).hexdigest()[:16], md5( repr( time.time() ) ).hexdigest()[:16] )

  replicateAndRegister = Operation()
  replicateAndRegister.Type = 'ReplicateAndRegister'
  replicateAndRegister.TargetSE = targetSE

  for lfn in lfnList:
    rarFile = File()
    rarFile.LFN = lfn
    replicateAndRegister.addFile( rarFile )

  oRequest.addOperation( replicateAndRegister )
  isValid = gRequestValidator.validate( oRequest )
  if not isValid['OK']:
    print "Request is not valid: ", isValid['Message']
    DIRAC.exit( 1 )

  DIRAC.gLogger.info( oRequest.toJSON()['Value'] )

  result = requestClient.putRequest( oRequest )
  if result['OK']:
    print 'Submitted Request:', result['Value']
  else:
    print 'Failed to submit Request', result['Message']
开发者ID:graciani,项目名称:DIRAC,代码行数:32,代码来源:dirac-dms-create-replication-request.py


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