diff --git a/test/python/WMCore_t/ReqMgr_t/Utils_t/Validation_t.py b/test/python/WMCore_t/ReqMgr_t/Utils_t/Validation_t.py index 22723f27097..c4929b19251 100644 --- a/test/python/WMCore_t/ReqMgr_t/Utils_t/Validation_t.py +++ b/test/python/WMCore_t/ReqMgr_t/Utils_t/Validation_t.py @@ -7,8 +7,8 @@ import unittest -from WMCore.ReqMgr.Utils.Validation import validateOutputDatasets from WMCore.ReqMgr.DataStructs.RequestError import InvalidSpecParameterValue +from WMCore.ReqMgr.Utils.Validation import validateOutputDatasets, validate_request_priority class ValidationTests(unittest.TestCase): @@ -48,6 +48,43 @@ def testValidateOutputDatasets(self): with self.assertRaises(InvalidSpecParameterValue): validateOutputDatasets(outputDsets, dbsUrl) + def testRequestPriorityValidation(self): + """ + Test the `validate_request_priority` function, which validates the + RequestPriority parameter + :return: nothing, raises an exception if there are problems + """ + reqArgs = {'RequestPriority': "1234"} + # test an integer casted to string + validate_request_priority(reqArgs) + # test an integer + validate_request_priority(reqArgs) + # test a float (which is properly casted to int) + reqArgs = {'RequestPriority': 1234.25} + validate_request_priority(reqArgs) + + # test an integer casted to a string, in an invalid range + reqArgs = {'RequestPriority': "1e7"} + with self.assertRaises(InvalidSpecParameterValue): + validate_request_priority(reqArgs) + # test an integer in an invalid range + reqArgs = {'RequestPriority': 1e7} + with self.assertRaises(InvalidSpecParameterValue): + validate_request_priority(reqArgs) + # test an integer in an invalid range + reqArgs = {'RequestPriority': -5} + with self.assertRaises(InvalidSpecParameterValue): + validate_request_priority(reqArgs) + + # test a float casted to string + reqArgs = {'RequestPriority': "1234.25"} + with self.assertRaises(InvalidSpecParameterValue): + validate_request_priority(reqArgs) + # test a weird list + reqArgs = {'RequestPriority': [1234]} + with self.assertRaises(InvalidSpecParameterValue): + validate_request_priority(reqArgs) + if __name__ == '__main__': unittest.main()