def test_valid_properties(): theFile = File() theFile.FileID = 1 assert theFile.FileID == 1 theFile.Status = "Done" assert theFile.Status == "Done" theFile.LFN = "/some/path/somewhere" assert theFile.LFN == "/some/path/somewhere" theFile.PFN = "/some/path/somewhere" assert theFile.PFN == "/some/path/somewhere" theFile.Attempt = 1 assert theFile.Attempt == 1 theFile.Size = 1 assert theFile.Size == 1 theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66" assert theFile.GUID == "2bbabe80-e2f1-11e1-9b23-0800200c9a66" theFile.ChecksumType = "adler32" assert theFile.ChecksumType == "ADLER32" theFile.Checksum = "123456" assert theFile.Checksum == "123456"
def test02props(self): """ test props and attributes """ theFile = File() # valid props theFile.FileID = 1 self.assertEqual(theFile.FileID, 1) theFile.Status = "Done" self.assertEqual(theFile.Status, "Done") theFile.LFN = "/some/path/somewhere" self.assertEqual(theFile.LFN, "/some/path/somewhere") theFile.PFN = "/some/path/somewhere" self.assertEqual(theFile.PFN, "/some/path/somewhere") theFile.Attempt = 1 self.assertEqual(theFile.Attempt, 1) theFile.Size = 1 self.assertEqual(theFile.Size, 1) theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66" self.assertEqual(theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66") theFile.ChecksumType = "adler32" self.assertEqual(theFile.ChecksumType, "ADLER32") theFile.Checksum = "123456" self.assertEqual(theFile.Checksum, "123456") # # theFile.Checksum = None theFile.ChecksumType = None self.assertEqual(theFile.Checksum, "") self.assertEqual(theFile.ChecksumType, "") # # invalid props # FileID try: theFile.FileID = "foo" except Exception, error: self.assertEqual(isinstance(error, ValueError), True)
def test02props( self ): """ test props and attributes """ theFile = File() # valid props theFile.FileID = 1 self.assertEqual( theFile.FileID, 1 ) theFile.Status = "Done" self.assertEqual( theFile.Status, "Done" ) theFile.LFN = "/some/path/somewhere" self.assertEqual( theFile.LFN, "/some/path/somewhere" ) theFile.PFN = "/some/path/somewhere" self.assertEqual( theFile.PFN, "/some/path/somewhere" ) theFile.Attempt = 1 self.assertEqual( theFile.Attempt, 1 ) theFile.Size = 1 self.assertEqual( theFile.Size, 1 ) theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66" self.assertEqual( theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66" ) theFile.ChecksumType = "adler32" self.assertEqual( theFile.ChecksumType, "ADLER32" ) theFile.Checksum = "123456" self.assertEqual( theFile.Checksum, "123456" ) # # theFile.Checksum = None theFile.ChecksumType = None self.assertEqual( theFile.Checksum, "" ) self.assertEqual( theFile.ChecksumType, "" ) # # invalid props # FileID try: theFile.FileID = "foo" except Exception, error: self.assertEqual( isinstance( error, ValueError ), True )
def test_05FTS(self): """ FTS state machine """ req = Request() req.RequestName = "FTSTest" ftsTransfer = Operation() ftsTransfer.Type = "ReplicateAndRegister" ftsTransfer.TargetSE = "CERN-USER" ftsFile = File() ftsFile.LFN = "/a/b/c" ftsFile.Checksum = "123456" ftsFile.ChecksumType = "Adler32" ftsTransfer.addFile(ftsFile) req.addOperation(ftsTransfer) self.assertEqual(req.Status, "Waiting", "1. wrong request status: %s" % req.Status) self.assertEqual(ftsTransfer.Status, "Waiting", "1. wrong ftsStatus status: %s" % ftsTransfer.Status) # # scheduled ftsFile.Status = "Scheduled" self.assertEqual( ftsTransfer.Status, "Scheduled", "2. wrong status for ftsTransfer: %s" % ftsTransfer.Status) self.assertEqual(req.Status, "Scheduled", "2. wrong status for request: %s" % req.Status) # # add new operation before FTS insertBefore = Operation() insertBefore.Type = "RegisterReplica" insertBefore.TargetSE = "CERN-USER" insertFile = File() insertFile.LFN = "/a/b/c" insertFile.PFN = "http://foo/bar" insertBefore.addFile(insertFile) req.insertBefore(insertBefore, ftsTransfer) self.assertEqual( insertBefore.Status, "Waiting", "3. wrong status for insertBefore: %s" % insertBefore.Status) self.assertEqual( ftsTransfer.Status, "Scheduled", "3. wrong status for ftsStatus: %s" % ftsTransfer.Status) self.assertEqual(req.Status, "Waiting", "3. wrong status for request: %s" % req.Status) # # prev done insertFile.Status = "Done" self.assertEqual( insertBefore.Status, "Done", "4. wrong status for insertBefore: %s" % insertBefore.Status) self.assertEqual( ftsTransfer.Status, "Scheduled", "4. wrong status for ftsStatus: %s" % ftsTransfer.Status) self.assertEqual(req.Status, "Scheduled", "4. wrong status for request: %s" % req.Status) # # reschedule ftsFile.Status = "Waiting" self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status) self.assertEqual( ftsTransfer.Status, "Waiting", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status) self.assertEqual(req.Status, "Waiting", "5. wrong status for request: %s" % req.Status) # # fts done ftsFile.Status = "Done" self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status) self.assertEqual( ftsTransfer.Status, "Done", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status) self.assertEqual(req.Status, "Done", "5. wrong status for request: %s" % req.Status)
def test05FTS( self ): """ FTS state machine """ req = Request() req.RequestName = "FTSTest" ftsTransfer = Operation() ftsTransfer.Type = "ReplicateAndRegister" ftsTransfer.TargetSE = "CERN-USER" ftsFile = File() ftsFile.LFN = "/a/b/c" ftsFile.Checksum = "123456" ftsFile.ChecksumType = "Adler32" ftsTransfer.addFile( ftsFile ) req.addOperation( ftsTransfer ) self.assertEqual( req.Status, "Waiting", "1. wrong request status: %s" % req.Status ) self.assertEqual( ftsTransfer.Status, "Waiting", "1. wrong ftsStatus status: %s" % ftsTransfer.Status ) # # scheduled ftsFile.Status = "Scheduled" self.assertEqual( ftsTransfer.Status, "Scheduled", "2. wrong status for ftsTransfer: %s" % ftsTransfer.Status ) self.assertEqual( req.Status, "Scheduled", "2. wrong status for request: %s" % req.Status ) # # add new operation before FTS insertBefore = Operation() insertBefore.Type = "RegisterReplica" insertBefore.TargetSE = "CERN-USER" insertFile = File() insertFile.LFN = "/a/b/c" insertFile.PFN = "http://foo/bar" insertBefore.addFile( insertFile ) req.insertBefore( insertBefore, ftsTransfer ) self.assertEqual( insertBefore.Status, "Waiting", "3. wrong status for insertBefore: %s" % insertBefore.Status ) self.assertEqual( ftsTransfer.Status, "Scheduled", "3. wrong status for ftsStatus: %s" % ftsTransfer.Status ) self.assertEqual( req.Status, "Waiting", "3. wrong status for request: %s" % req.Status ) # # prev done insertFile.Status = "Done" self.assertEqual( insertBefore.Status, "Done", "4. wrong status for insertBefore: %s" % insertBefore.Status ) self.assertEqual( ftsTransfer.Status, "Scheduled", "4. wrong status for ftsStatus: %s" % ftsTransfer.Status ) self.assertEqual( req.Status, "Scheduled", "4. wrong status for request: %s" % req.Status ) # # reschedule ftsFile.Status = "Waiting" self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status ) self.assertEqual( ftsTransfer.Status, "Waiting", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status ) self.assertEqual( req.Status, "Waiting", "5. wrong status for request: %s" % req.Status ) # # fts done ftsFile.Status = "Done" self.assertEqual( insertBefore.Status, "Done", "5. wrong status for insertBefore: %s" % insertBefore.Status ) self.assertEqual( ftsTransfer.Status, "Done", "5. wrong status for ftsStatus: %s" % ftsTransfer.Status ) self.assertEqual( req.Status, "Done", "5. wrong status for request: %s" % req.Status )
def test02props(self): """ test props and attributes """ theFile = File() # valid props theFile.FileID = 1 self.assertEqual(theFile.FileID, 1) theFile.Status = "Done" self.assertEqual(theFile.Status, "Done") theFile.LFN = "/some/path/somewhere" self.assertEqual(theFile.LFN, "/some/path/somewhere") theFile.PFN = "/some/path/somewhere" self.assertEqual(theFile.PFN, "/some/path/somewhere") theFile.Attempt = 1 self.assertEqual(theFile.Attempt, 1) theFile.Size = 1 self.assertEqual(theFile.Size, 1) theFile.GUID = "2bbabe80-e2f1-11e1-9b23-0800200c9a66" self.assertEqual(theFile.GUID, "2bbabe80-e2f1-11e1-9b23-0800200c9a66") theFile.ChecksumType = "adler32" self.assertEqual(theFile.ChecksumType, "ADLER32") theFile.Checksum = "123456" self.assertEqual(theFile.Checksum, "123456") # # theFile.Checksum = None theFile.ChecksumType = None # self.assertEqual( theFile.Checksum, "" ) # self.assertEqual( theFile.ChecksumType, "" ) # # invalid props # FileID try: theFile.FileID = "foo" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) # parent parent = Operation({"OperationID": 99999}) parent += theFile theFile.FileID = 0 # self.assertEqual( parent.OperationID, theFile.OperationID ) try: theFile.OperationID = 111111 except Exception as error: self.assertEqual(isinstance(error, AttributeError), True) self.assertEqual(str(error), "can't set attribute") # LFN try: theFile.LFN = 1 except Exception as error: self.assertEqual(isinstance(error, TypeError), True) self.assertEqual(str(error), "LFN has to be a string!") try: theFile.LFN = "../some/path" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "LFN should be an absolute path!") # PFN try: theFile.PFN = 1 except Exception as error: self.assertEqual(isinstance(error, TypeError), True) self.assertEqual(str(error), "PFN has to be a string!") try: theFile.PFN = "snafu" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "Wrongly formatted PFN!") # Size try: theFile.Size = "snafu" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) try: theFile.Size = -1 except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "Size should be a positive integer!") # GUID try: theFile.GUID = "snafuu-uuu-uuu-uuu-uuu-u" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "'snafuu-uuu-uuu-uuu-uuu-u' is not a valid GUID!") try: theFile.GUID = 2233345 except Exception as error: self.assertEqual(isinstance(error, TypeError), True) self.assertEqual(str(error), "GUID should be a string!") # Attempt try: theFile.Attempt = "snafu" except Exception as error: self.assertEqual(isinstance(error, ValueError), True) try: theFile.Attempt = -1 except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "Attempt should be a positive integer!") # Status try: theFile.Status = None except Exception as error: self.assertEqual(isinstance(error, ValueError), True) self.assertEqual(str(error), "Unknown Status: None!") # Error try: theFile.Error = Exception("test") except Exception as error: self.assertEqual(isinstance(error, TypeError), True) self.assertEqual(str(error), "Error has to be a string!")