From 608f2c55d9fa8c1245786dea90cc07dca0e04ee3 Mon Sep 17 00:00:00 2001 From: Alan Malta Rodrigues Date: Thu, 5 Dec 2024 17:30:37 -0500 Subject: [PATCH] unit test changes --- test/python/Utils_t/Patterns_t.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/python/Utils_t/Patterns_t.py b/test/python/Utils_t/Patterns_t.py index 27320cb36a..f5a42eaa74 100644 --- a/test/python/Utils_t/Patterns_t.py +++ b/test/python/Utils_t/Patterns_t.py @@ -2,18 +2,17 @@ Patterns_t module provide unit tests for Patterns module Unittests for Utilities functions """ - - import time import unittest -from Utils.Patterns import Singleton +from Utils.Patterns import Singleton, getDomainName -class Test(object, metaclass=Singleton):#Test(with_metaclass(Singleton, object)): +class Test(object, metaclass=Singleton): "Example of Singleton class" def __init__(self): self.time = time.time() + class PatternsTests(unittest.TestCase): """ unittest for Patterns functions @@ -27,5 +26,19 @@ def testSingleton(self): self.assertEqual(obj1.time, obj2.time) self.assertEqual(id(obj1), id(obj2)) + + def testGetDomainName(self): + "Test the getDomainName function" + # test with http protocol + self.assertEqual(getDomainName("http://cmsweb.cern.ch/blah/two"), "cmsweb") + # test with https protocol + self.assertEqual(getDomainName("https://cmsweb.cern.ch/blah/two"), "cmsweb") + self.assertEqual(getDomainName("https://cmsweb-testbed.cern.ch"), "cmsweb-testbed") + self.assertEqual(getDomainName("https://cmsweb-preprod.cern.ch"), "cmsweb-preprod") + self.assertEqual(getDomainName("https://cmsweb-test3.cern.ch"), "cmsweb-test3") + # test with unexpected/wrong URL + self.assertEqual(getDomainName("https://cmsweb.blah.ch"), "") + + if __name__ == '__main__': unittest.main()