Пример #1
0
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"
Пример #2
0
    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)
Пример #3
0
  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 )
Пример #4
0
  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!")