Fixing testing framework

This commit is contained in:
axl89 2016-08-19 16:56:48 +02:00
parent bfa03fbf74
commit 8ff0e773e2
5 changed files with 41 additions and 38 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import click_menu_element, detect_and_pass_all_wizards, gen_random_string, is_enterprise
from include.common_functions_60 import click_menu_element, detect_and_pass_all_wizards, gen_random_string, is_enterprise, enterprise_class
from include.module_functions import create_module
from include.agent_functions import create_agent_group
from include.policy_functions import *
@ -14,7 +14,7 @@ from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
@enterprise_class
class Collections(PandoraWebDriverTestCase):
test_name = u'Collections'
@ -24,7 +24,6 @@ class Collections(PandoraWebDriverTestCase):
collection_name = gen_random_string(6)
new_collection_name = gen_random_string(6)
@is_enterprise
def test_A_create_collection(self):
driver = self.driver
@ -38,7 +37,6 @@ class Collections(PandoraWebDriverTestCase):
element = driver.find_element_by_xpath('//a[contains(.,self.collection_name)]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_B_edit_collection(self):
driver = self.driver
@ -51,7 +49,6 @@ class Collections(PandoraWebDriverTestCase):
element = driver.find_element_by_xpath('//a[contains(.,self.new_collection_name)]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_C_create_text_collection(self):
driver = self.driver
@ -62,7 +59,6 @@ class Collections(PandoraWebDriverTestCase):
element = driver.find_element_by_xpath('//a[contains(.,"file_collectionPAN11")]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_D_directory_collection(self):
driver = self.driver
@ -73,7 +69,6 @@ class Collections(PandoraWebDriverTestCase):
element = driver.find_element_by_xpath('//a[contains(.,"directory_collectionPAN11")]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_E_delete_collection(self):
driver = self.driver

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import detect_and_pass_all_wizards, gen_random_string, is_enterprise
from include.common_functions_60 import detect_and_pass_all_wizards, gen_random_string, is_enterprise, enterprise_class
from include.policy_functions import *
from include.agent_functions import *
from include.collection_functions import *
@ -13,6 +13,7 @@ from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
@enterprise_class
class Policies(PandoraWebDriverTestCase):
test_name = u'Policies'
@ -23,7 +24,6 @@ class Policies(PandoraWebDriverTestCase):
network_server_module_name = gen_random_string(6)
@is_enterprise
def test_A_create_policy(self):
u"""
@ -41,7 +41,6 @@ class Policies(PandoraWebDriverTestCase):
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_B_add_network_server_module_to_policy(self):
u"""
@ -56,7 +55,6 @@ class Policies(PandoraWebDriverTestCase):
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_C_add_collection_to_policy(self):
u"""
@ -81,7 +79,6 @@ class Policies(PandoraWebDriverTestCase):
@is_enterprise
def test_D_Apply_policy_to_agents(self):
u"""

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import click_menu_element, detect_and_pass_all_wizards, gen_random_string
from include.common_functions_60 import click_menu_element, detect_and_pass_all_wizards, gen_random_string, enterprise_class
from include.planned_downtime_functions import *
from include.alert_functions import *
from include.module_functions import *
@ -15,7 +15,6 @@ from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re, datetime
class QuietTest(PandoraWebDriverTestCase):
test_name = u'Planned downtime quiet type test'

View File

@ -25,6 +25,24 @@ def is_enterprise(func):
raise unittest.SkipTest("Skipping test")
return inner
def enterprise_class(cls):
u"""
This decorator is intended to be used for Enterprise tests only
"""
def inner(*args,**kwargs):
is_enterprise = 0
try:
is_enterprise = args[0].is_enterprise == '1'
except:
pass
if is_enterprise:
return cls
else:
return object
return inner
def gen_random_string(size,preffix=None):
random_string = ''.join(random.SystemRandom().choice(string.ascii_uppercase+string.digits) for _ in range(size))

View File

@ -23,33 +23,29 @@ class ArticaTestLoader(TestLoader):
super(ArticaTestLoader, self).__init__(*args,**kwargs)
""" Splits a Test Suite so that no more than 'n' threads will execute the tests """
def split_suite_into_chunks(num_threads, suite):
# Compute num_threads such that the number of threads does not exceed the value passed to the function
# Keep num_threads to a reasonable number of threads
if num_threads < 0: num_threads = 1
if num_threads > 8: num_threads = 8
num_tests = suite.countTestCases()
print "num_tests: "+str(num_tests)
def split_suite_into_chunks(n, suite):
import math
# Keep n to a reasonable number of threads
if n < 0:
n = 1
if n > 8:
n = 8
# Compute n such that the number of threads does not exceed the value passed to the function
n = math.ceil(suite.countTestCases() / n)
s = []
i = 0
s_tmp = ArticaTestSuite()
n = round(num_tests / num_threads)
for case in suite:
if n <= 0 and s_tmp.countTestCases() > 0:
if i < n:
s_tmp.addTest(case)
i += 1
if i == n:
s.append([s_tmp, None])
num_threads -= 1
num_tests -= s_tmp.countTestCases()
i = 0
s_tmp = ArticaTestSuite()
print "num_tests: "+str(num_tests)
print "num_threads: "+str(num_threads)
n = round(num_tests / num_threads)
s_tmp.addTest(case)
n -= 1
if s_tmp.countTestCases() > 0:
if s_tmp.countTestCases() > 0: s.append([s_tmp, None])
num_tests -= s_tmp.countTestCases()
if num_tests != 0: print("Error: num_tests should be 0 but is %s!" % num_tests)
print "The length of s is: "+str(len(s))
if (i > 0):
s.append([s_tmp, None])
return s
class TracingStreamResult(testtools.StreamResult):
@ -95,10 +91,8 @@ print str(tests.countTestCases())+" tests found"
print "Using "+str(num_threads)+" threads"
concurrent_suite = testtools.ConcurrentStreamTestSuite(lambda: (split_suite_into_chunks(num_threads, tests)))
#concurrent_suite = testtools.ConcurrentStreamTestSuite(tests)
result = TracingStreamResult()
try:
result.startTestRun()
finally: