def test_ctor(): """test constructors and (de)serialisation""" assert isinstance(Operation(), Operation), "empty ctor failed" # # using fromDict fromDict = { "Type": "replicateAndRegister", "TargetSE": "CERN-USER,PIC-USER", "SourceSE": None, } operation = Operation(fromDict) assert isinstance(operation, Operation), "fromDict ctor failed" for key, value in fromDict.items(): assert getattr(operation, key) == value, "wrong attr value %s (%s) %s" % ( key, getattr(operation, key), value) # # same with file operation = Operation(fromDict) operation.addFile( File({ "LFN": "/lhcb/user/c/cibak/testFile", "Checksum": "1234567", "ChecksumType": "ADLER32", "Size": 1024, "Status": "Waiting", })) for key, value in fromDict.items(): assert getattr(operation, key) == value, "wrong attr value %s (%s) %s" % ( key, getattr(operation, key), value) toJSON = operation.toJSON() assert toJSON["OK"], "JSON serialization failed"
def test01ctor(self): """ test constructors and (de)serialisation """ # # empty ctor self.assertEqual(isinstance(Operation(), Operation), True, "empty ctor failed") # # using fromDict operation = Operation(self.fromDict) self.assertEqual(isinstance(operation, Operation), True, "fromDict ctor failed") for key, value in self.fromDict.items(): self.assertEqual( getattr(operation, key), value, "wrong attr value %s (%s) %s" % (key, getattr(operation, key), value)) # # same with file operation = Operation(self.fromDict) operation.addFile(self.subFile) for key, value in self.fromDict.items(): self.assertEqual( getattr(operation, key), value, "wrong attr value %s (%s) %s" % (key, getattr(operation, key), value)) toJSON = operation.toJSON() self.assertEqual(toJSON["OK"], True, "JSON serialization failed")
def test01ctor( self ): """ test constructors and (de)serialisation """ # # empty ctor self.assertEqual( isinstance( Operation(), Operation ), True, "empty ctor failed" ) # # using fromDict operation = Operation( self.fromDict ) self.assertEqual( isinstance( operation, Operation ), True, "fromDict ctor failed" ) for key, value in self.fromDict.items(): self.assertEqual( getattr( operation, key ), value, "wrong attr value %s (%s) %s" % ( key, getattr( operation, key ), value ) ) # # same with file operation = Operation( self.fromDict ) operation.addFile( self.subFile ) for key, value in self.fromDict.items(): self.assertEqual( getattr( operation, key ), value, "wrong attr value %s (%s) %s" % ( key, getattr( operation, key ), value ) ) toJSON = operation.toJSON() self.assertEqual( toJSON["OK"], True, "JSON serialization failed" )
def test05List(self): """ getitem, setitem, delitem and dirty """ op = Operation() files = [] for i in range(5): f = File() files.append(f) op += f for i in range(len(op)): self.assertEqual(op[i], files[i], "__getitem__ failed") for i in range(len(op)): op[i] = File({"LFN": "/%s" % i}) self.assertEqual(op[i].LFN, "/%s" % i, "__setitem__ failed") del op[0] self.assertEqual(len(op), 4, "__delitem__ failed") # # opID set op.OperationID = 1 del op[0] self.assertEqual(op.cleanUpSQL(), None, "cleanUp failed after __delitem__") op[0].FileID = 1 del op[0] self.assertEqual( op.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1);\n", "cleanUp failed after __delitem__") op[0].FileID = 2 op[0] = File({"FileID": 2}) self.assertEqual( op.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1,2);\n", "cleanUp failed after __setitem__") json = op.toJSON() self.assertEqual("__dirty" in json["Value"], True, "missing __dirty") op2 = Operation(json["Value"]) self.assertEqual( op2.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1,2);\n", "cleanUp failed after JSON")
def test05List( self ): """ getitem, setitem, delitem and dirty """ op = Operation() files = [] for i in range( 5 ): f = File() files.append( f ) op += f for i in range( len( op ) ): self.assertEqual( op[i], files[i], "__getitem__ failed" ) for i in range( len( op ) ): op[i] = File( {"LFN": "/%s" % i } ) self.assertEqual( op[i].LFN, "/%s" % i, "__setitem__ failed" ) del op[0] self.assertEqual( len( op ), 4, "__delitem__ failed" ) # # opID set op.OperationID = 1 del op[0] self.assertEqual( op.cleanUpSQL(), None, "cleanUp failed after __delitem__" ) op[0].FileID = 1 del op[0] self.assertEqual( op.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1);\n", "cleanUp failed after __delitem__" ) op[0].FileID = 2 op[0] = File( {"FileID": 2 } ) self.assertEqual( op.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1,2);\n", "cleanUp failed after __setitem__" ) json = op.toJSON() self.assertEqual( "__dirty" in json["Value"], True, "missing __dirty" ) op2 = Operation( json["Value"] ) self.assertEqual( op2.cleanUpSQL(), "DELETE FROM `File` WHERE `OperationID` = 1 AND `FileID` IN (1,2);\n", "cleanUp failed after JSON" )
def test_valid_properties(): operation = Operation() operation.Arguments = "foobar" assert operation.Arguments == b"foobar", "wrong Arguments" operation.SourceSE = "CERN-RAW" assert operation.SourceSE == "CERN-RAW", "wrong SourceSE" operation.TargetSE = "CERN-RAW" assert operation.TargetSE == "CERN-RAW", "wrong TargetSE" operation.Catalog = "" assert operation.Catalog == "", "wrong Catalog" operation.Catalog = "BookkeepingDB" assert operation.Catalog == "BookkeepingDB", "wrong Catalog" operation.Error = "error" assert operation.Error == "error", "wrong Error" toJSON = operation.toJSON() assert toJSON["OK"]