Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:00

0001 # Description: Unit tests for the Statistics API methods
0002 import unittest
0003 
0004 from pandaserver.api.v1.http_client import HttpClient, api_url_ssl
0005 
0006 
0007 class TestTaskAPI(unittest.TestCase):
0008     def setUp(self):
0009         self.http_client = HttpClient()
0010 
0011     def test_job_stats_by_cloud(self):
0012         url = f"{api_url_ssl}/statistics/job_stats_by_cloud"
0013         print(f"Testing URL: {url}")
0014         data = {"type": "production"}
0015         status, output = self.http_client.get(url, data)
0016         print(output)
0017         output["status"] = status
0018 
0019         # Remove the data field from the response for comparison
0020         del output["data"]
0021 
0022         expected_response = {"success": True, "message": "", "status": 0}
0023 
0024         self.assertEqual(output, expected_response)
0025 
0026     def test_production_job_stats_by_cloud_and_processing_type(self):
0027         url = f"{api_url_ssl}/statistics/production_job_stats_by_cloud_and_processing_type"
0028         print(f"Testing URL: {url}")
0029         data = {}
0030         status, output = self.http_client.get(url, data)
0031         print(output)
0032         output["status"] = status
0033 
0034         # Remove the data field from the response for comparison
0035         del output["data"]
0036 
0037         expected_response = {"success": True, "message": "", "status": 0}
0038 
0039         self.assertEqual(output, expected_response)
0040 
0041     def test_active_job_stats_by_site(self):
0042         url = f"{api_url_ssl}/statistics/active_job_stats_by_site"
0043         print(f"Testing URL: {url}")
0044         data = {}
0045         status, output = self.http_client.get(url, data)
0046         print(output)
0047         output["status"] = status
0048 
0049         # Remove the data field from the response for comparison
0050         del output["data"]
0051 
0052         expected_response = {"success": True, "message": "", "status": 0}
0053 
0054         self.assertEqual(output, expected_response)
0055 
0056     def test_active_job_detailed_stats_by_site(self):
0057         url = f"{api_url_ssl}/statistics/active_job_detailed_stats_by_site"
0058         print(f"Testing URL: {url}")
0059         data = {}
0060         status, output = self.http_client.get(url, data)
0061         print(output)
0062         output["status"] = status
0063 
0064         # Remove the data field from the response for comparison
0065         del output["data"]
0066 
0067         expected_response = {"success": True, "message": "", "status": 0}
0068 
0069         self.assertEqual(output, expected_response)
0070 
0071     def test_job_stats_by_site_and_resource_type(self):
0072         url = f"{api_url_ssl}/statistics/job_stats_by_site_and_resource_type"
0073         print(f"Testing URL: {url}")
0074         data = {"time_window": 12 * 60}
0075         status, output = self.http_client.get(url, data)
0076         print(output)
0077         output["status"] = status
0078 
0079         # Remove the data field from the response for comparison
0080         del output["data"]
0081 
0082         expected_response = {"success": True, "message": "", "status": 0}
0083 
0084         self.assertEqual(output, expected_response)
0085 
0086     def test_job_stats_by_site_share_and_resource_type(self):
0087         url = f"{api_url_ssl}/statistics/job_stats_by_site_share_and_resource_type"
0088         print(f"Testing URL: {url}")
0089         data = {"time_window": 12 * 60}
0090         status, output = self.http_client.get(url, data)
0091         print(output)
0092         output["status"] = status
0093 
0094         # Remove the data field from the response for comparison
0095         del output["data"]
0096 
0097         expected_response = {"success": True, "message": "", "status": 0}
0098 
0099         self.assertEqual(output, expected_response)
0100 
0101 
0102 # Run tests
0103 if __name__ == "__main__":
0104     unittest.main()