Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:22

0001 #!/usr/bin/env python
0002 #
0003 # Licensed under the Apache License, Version 2.0 (the "License");
0004 # You may not use this file except in compliance with the License.
0005 # You may obtain a copy of the License at
0006 # http://www.apache.org/licenses/LICENSE-2.0OA
0007 #
0008 # Authors:
0009 # - Wen Guan, <wen.guan@cern.ch>, 2019
0010 
0011 
0012 """
0013 Test Request.
0014 """
0015 
0016 import random
0017 import time
0018 import unittest2 as unittest
0019 from nose.tools import assert_equal
0020 
0021 from idds.common.utils import check_database, has_config, setup_logging
0022 from idds.orm.requests import (add_request, get_request, delete_requests)
0023 from idds.orm.transforms import (add_transform, get_transform, get_transform_ids, delete_transform)
0024 from idds.tests.common import get_request_properties, get_transform_properties
0025 
0026 setup_logging(__name__)
0027 
0028 
0029 class TestTransform(unittest.TestCase):
0030 
0031     @unittest.skipIf(not has_config(), "No config file")
0032     @unittest.skipIf(not check_database(), "Database is not defined")
0033     def test_create_and_check_for_request_transform_orm(self):
0034         """ Transform (ORM): Test to create and delete a Transform """
0035         req_properties = get_request_properties()
0036         req_properties['workload_id'] = int(time.time()) + random.randint(1, 1000000)
0037         trans_properties = get_transform_properties()
0038 
0039         request_id = add_request(**req_properties)
0040 
0041         trans_properties['request_id'] = request_id
0042         trans_id = add_transform(**trans_properties)
0043         transform = get_transform(transform_id=trans_id)
0044         for key in trans_properties:
0045             if key in ['request_id']:
0046                 continue
0047             assert_equal(transform[key], trans_properties[key])
0048 
0049         trans_ids1 = get_transform_ids(request_id=request_id)
0050         trans_ids2 = get_transform_ids(workload_id=req_properties['workload_id'])
0051         trans_ids3 = get_transform_ids(transform_id=trans_id)
0052         trans_ids4 = get_transform_ids(request_id=request_id, workload_id=req_properties['workload_id'])
0053         trans_ids5 = get_transform_ids(request_id=request_id, workload_id=req_properties['workload_id'], transform_id=trans_id)
0054         trans_ids6 = get_transform_ids(request_id=request_id, transform_id=trans_id)
0055         trans_ids7 = get_transform_ids(workload_id=req_properties['workload_id'], transform_id=trans_id)
0056         assert_equal(trans_ids1, trans_ids2)
0057         assert_equal(trans_ids2, trans_ids3)
0058         assert_equal(trans_ids3, trans_ids4)
0059         assert_equal(trans_ids4, trans_ids5)
0060         assert_equal(trans_ids5, trans_ids6)
0061         assert_equal(trans_ids6, trans_ids7)
0062 
0063         delete_transform(trans_id)
0064         delete_requests(request_id=request_id)
0065 
0066         req = get_request(request_id=request_id)
0067         assert_equal(req, None)
0068 
0069         trans = get_transform(transform_id=trans_id)
0070         assert_equal(trans, None)