Started new transition to Framework 2.0

(cherry picked from commit b9ea425590)
This commit is contained in:
cesar991 2016-08-16 13:17:15 +02:00
parent 2294d825e3
commit af5b3ec31f
6 changed files with 196 additions and 219 deletions

178
tests/console/ACL.py Normal file
View File

@ -0,0 +1,178 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, is_element_present, click_menu_element, detect_and_pass_all_wizards, logout, gen_random_string, is_enterprise
from include.agent_functions import create_agent, search_agent, create_agent_group
from include.user_functions import create_user, create_user_profile
from include.module_functions import create_module
from include.reports_functions import create_report
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
class ACL(PandoraWebDriverTestCase):
test_name = u'ACL'
tickets_associated = []
def test_A_ACL_propagation(self):
u"""
ACL Propagation test: Creates one group "A" with ACL propagation, then a group "B" son of "A" with no ACL propagation, and finally group "C".
The test asserts if a user with privileges to "A" can see the agent of "B" but no agents of "C".
"""
print "funciono"
group_name_A = gen_random_string(6)
group_name_B = gen_random_string(6)
group_name_C = gen_random_string(6)
agent_name_A = gen_random_string(6)
agent_name_B = gen_random_string(6)
user_name = gen_random_string(6)
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
create_agent_group(driver,group_name_A,propagate_acl=True,description="Group A, with propagate ACL, son of ALL")
create_agent_group(driver,group_name_B,parent_group=group_name_A,description="Group B, son of A")
create_agent_group(driver,group_name_C,parent_group=group_name_B,description="Group C, son of B")
create_agent(driver,agent_name_A,description="Agent in group B",group=group_name_B)
create_agent(driver,agent_name_B,description="Agent in group C",group=group_name_C)
l=[("Chief Operator",group_name_A,[])]
create_user(driver,user_name,"pandora",profile_list=l)
self.logout()
self.login(user=user_name)
detect_and_pass_all_wizards(driver)
#Is the agent listed in the agent list?
search_agent(driver,agent_name_A,go_to_agent=False)
element = driver.find_element_by_xpath('//a[contains(.,"'+agent_name_A+'")]')
self.assertIsInstance(element,WebElement)
#Is the agent accesible for the user?
search_agent(driver,agent_name_A,go_to_agent=True)
element = driver.find_element_by_xpath('//*[@id="agent_contact_main"]/thead/tr/th')
self.assertIsInstance(element,WebElement)
#Is the agent invisible to the user? (It should be invisible)
search_agent(driver,agent_name_B,go_to_agent=False)
element = driver.find_elements_by_xpath('//a[contains(.,"'+agent_name_B+'")]')
self.assertEqual(element,[])
#We need to logout because we've loged in with a non-admin user
self.logout()
def test_B_ACL_reports(self):
u"""
Creates a user with Chief Operator permissions over the Applications group.
Then creates two reports: one in the Applications group and other in the Servers group. Then, it checks that the given user can only see the Application report
"""
user_name = gen_random_string(6)
report_name_A = agent_name = gen_random_string(6)
report_name_B = agent_name = gen_random_string(6)
driver = self.driver
self.login()
#Creates a user with Chief Operator - Applications profile
profile_list = []
profile_list.append(("Chief Operator","Applications",[]))
create_user(driver,user_name,user_name,email=user_name+'@pandorafms.com',profile_list=profile_list)
#Creates report
create_report(driver,report_name_A,"Applications")
create_report(driver,report_name_B,"Servers")
#Logout
self.logout()
#Login
self.login(user=user_name,passwd=user_name)
#Check that the report is visible
click_menu_element(driver,"Custom reporting")
driver.find_element_by_id('text-search').clear()
driver.find_element_by_id('text-search').send_keys(report_name_A)
driver.find_element_by_id('submit-search_submit').click()
self.assertEqual(is_element_present(driver, By.ID, 'report_list-0'),True)
#Check that the report is not visible
click_menu_element(driver,"Custom reporting")
driver.find_element_by_id('text-search').clear()
driver.find_element_by_id('text-search').send_keys(report_name_B)
driver.find_element_by_id('submit-search_submit').click()
time.sleep(6)
element = driver.find_element_by_xpath('//td[contains(.,"No data found.")]')
self.assertIsInstance(element,WebElement)
#Delete reports
self.logout()
def test_C_ACL_tag(self):
u"""Create agent and two modules, one without tag and with tag, create a user with tag and check this user can view module with tag and user can´t view module without tag"""
agent_name = gen_random_string(6)
module_name_A = gen_random_string(6)
module_name_B = gen_random_string(6)
user_name = gen_random_string(6)
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
create_agent(driver,agent_name,group="Applications",ip="192.168.50.50")
#We create a module without a tag
create_module("network_server",driver,agent_name=agent_name,module_name=module_name_A,component_group="Network Management",network_component="Host Alive",ip="192.168.50.50")
#We now create a modulo with tag "critical"
create_module("network_server",driver,agent_name=agent_name,module_name=module_name_B,component_group="Network Management",network_component="Host Alive",ip="192.168.50.50",tag_name="critical")
l = [("Operator (Read)","All",["critical"])]
create_user(driver,user_name,"pandora",profile_list=l)
self.logout()
self.login(user=user_name)
detect_and_pass_all_wizards(driver)
search_agent(driver,agent_name)
time.sleep(6)
#The user should be able to see the module with Tag
module = driver.find_element_by_xpath('//td[contains(.,"'+module_name_B+'")]')
self.assertIsInstance(module,WebElement)
#The user should NOT be able to see the module without tag
modules = driver.find_elements_by_xpath('//td[contains(.,"'+module_name_A+'")]')
self.assertEqual(modules,[])
if __name__ == "__main__":
unittest.main()

View File

@ -1,79 +0,0 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, refresh_N_times_until_find_element, detect_and_pass_all_wizards, is_element_present, logout
from selenium import webdriver
from include.reports_functions import delete_report, create_report
from include.user_functions import create_user
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import StaleElementReferenceException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
class PAN4(PandoraWebDriverTestCase):
test_name = u'PAN_4'
test_description = u'Creates a user with Chief Operator permissions over the Applications group. Then creates two reports: one in the Applications group and other in the Servers group. Then, it checks that the given user can only see the Application report'
tickets_associated = []
def test_pan4(self):
driver = self.driver
self.login()
#Creates a user with Chief Operator - Applications profile
profile_list = []
profile_list.append(("Chief Operator","Applications",[]))
create_user(driver,'PAN_4','PAN_4',email='pan_4@pandorafms.com',profile_list=profile_list)
#Creates report
create_report(driver,"PAN_4_Applications","Applications")
create_report(driver,"PAN_4_Servers","Servers")
#Logout
self.logout()
#Login
self.login(user='PAN_4',passwd='PAN_4')
#Check that the report is visible
click_menu_element(driver,"Custom reporting")
driver.find_element_by_id('text-search').clear()
driver.find_element_by_id('text-search').send_keys("PAN_4_Applications")
driver.find_element_by_id('submit-search_submit').click()
self.assertEqual(is_element_present(driver, By.ID, 'report_list-0'),True)
#Check that the report is not visible
click_menu_element(driver,"Custom reporting")
driver.find_element_by_id('text-search').clear()
driver.find_element_by_id('text-search').send_keys("PAN_4_Servers")
driver.find_element_by_id('submit-search_submit').click()
time.sleep(6)
try:
element = driver.find_element_by_xpath('//td[contains(.,"No data found.")]')
self.assertIsInstance(element,WebElement)
except AssertionError as e:
self.verificationErrors.append(str(e))
except NoSuchElementException as e:
self.verificationErrors.append(str(e))
#Delete reports
self.logout()
self.login(user="admin",passwd="pandora")
delete_report(driver,"PAN_4_Servers")
delete_report(driver,"PAN_4_Applications")
if __name__ == "__main__":
unittest.main()

View File

@ -1,68 +0,0 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout
from include.agent_functions import create_agent, search_agent
from include.user_functions import create_user
from include.module_functions import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class PAN8(PandoraWebDriverTestCase):
test_name = u'PAN_8'
test_description = u'Create agent and two modules, one without tag and with tag, create a user with tag and check this user can view module with tag and user can´t view module without tag'
tickets_associated = []
def test_pan8(self):
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
create_agent(driver,"PAN_8",group="Applications",ip="192.168.50.50")
#We create a module without a tag
create_module("network_server",driver,agent_name="PAN_8",module_name="Without tag",component_group="Network Management",network_component="Host Alive",ip="192.168.50.50")
#We now create a modulo with tag "critical"
create_module("network_server",driver,agent_name="PAN_8",module_name="With tag",component_group="Network Management",network_component="Host Alive",ip="192.168.50.50",tag_name="critical")
l = [("Operator (Read)","All",["critical"])]
create_user(driver,"PAN8_user","pandora",profile_list=l)
self.logout()
self.login(user="PAN8_user")
detect_and_pass_all_wizards(driver)
search_agent(driver,"PAN_8")
time.sleep(6)
try:
#The user should be able to see the module with Tag
module = driver.find_element_by_xpath('//td[contains(.,"With tag")]')
self.assertEqual("With tag" in driver.page_source,True)
except AssertionError as e:
self.verificationErrors.append(str(e))
try:
#The user should NOT be able to see the module without tag
self.assertEqual("Without tag" in driver.page_source,False)
except AssertionError as e:
self.verificationErrors.append(str(e))
if __name__ == "__main__":
unittest.main()

View File

@ -1,72 +0,0 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout
from include.agent_functions import create_agent, search_agent, create_agent_group
from include.user_functions import create_user, create_user_profile
from include.module_functions import create_network_server_module
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
class PAN9(PandoraWebDriverTestCase):
test_name = u'PAN_9'
test_description = u'ACL Propagation test: Creates one group "A" with ACL propagation, then a group "B" son of "A" with no ACL propagation, and finally group "C". The test asserts if a user with privileges to "A" can see the agent of "B" but no agents of "C". '
tickets_associated = []
def test_pan9(self):
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
create_agent_group(driver,"PAN9_A",propagate_acl=True,description="Group A, with propagate ACL, son of ALL")
create_agent_group(driver,"PAN9_B",parent_group="PAN9_A",description="Group B, son of A")
create_agent_group(driver,"PAN9_C",parent_group="PAN9_B",description="Group C, son of B")
create_agent(driver,"PAN9_agent_B",description="Agent in group B",group="PAN9_B")
create_agent(driver,"PAN9_agent_C",description="Agent in group C",group="PAN9_C")
l=[("Chief Operator","PAN9_A",[])]
create_user(driver,"PAN9_user","pandora",profile_list=l)
self.logout()
self.login(user="PAN9_user")
detect_and_pass_all_wizards(driver)
search_agent(driver,"PAN9_agent_B",go_to_agent=False)
time.sleep(6)
try:
element = driver.find_element_by_xpath('//a[contains(.,"PAN9_agent_B")]')
self.assertIsInstance(element,WebElement)
except AssertionError as e:
self.verificationErrors.append(str(e))
except NoSuchElementException as e:
self.verificationErrors.append(str(e))
search_agent(driver,"PAN9_agent",go_to_agent=False)
time.sleep(6)
try:
#self.assertEqual(False,u"PAN9_agent_C" in driver.page_source)
element = driver.find_elements_by_xpath('//a[contains(.,"PAN9_agent_C")]')
self.assertEqual(element,[])
except AssertionError as e:
self.verificationErrors.append(str(e))
if __name__ == "__main__":
unittest.main()

View File

@ -40,6 +40,7 @@ class PandoraWebDriverTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.is_development = os.getenv('DEVELOPMENT', False)
cls.is_enterprise = os.getenv('ENTERPRISE', False)
if cls.is_development != False:
cls.driver = webdriver.Firefox()
cls.base_url = os.getenv('DEVELOPMENT_URL')
@ -60,6 +61,7 @@ class PandoraWebDriverTestCase(TestCase):
self.driver.implicitly_wait(30)
self.verificationErrors = []
self.accept_next_alert = True
#self.is_development = self.is_development
super(PandoraWebDriverTestCase, self).setUp()
def is_element_present(self, how, what):

View File

@ -7,6 +7,22 @@ from selenium.webdriver.support import expected_conditions as EC
import random, time
import string
def is_enterprise(func):
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 func(*args,**kwargs)
return inner
def gen_random_string(size,preffix=None):
random_string = ''.join(random.SystemRandom().choice(string.ascii_uppercase+string.digits) for _ in range(size))
if preffix: