Refactorized create_module functions and create policy_functions

This commit is contained in:
cesar991 2016-07-15 14:27:40 +02:00
parent c43125a5db
commit 2b81c0bd6c
3 changed files with 91 additions and 5 deletions

0
tests/console/PAN6.py Normal file
View File

View File

@ -10,17 +10,24 @@ import random, time
import string
def create_network_server_module(driver,agent_name,module_name=None,component_group=None,type=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
def create_module(module_type,*args,**kwargs):
if module_type=='network_server':
create_network_server_module(*args,**kwargs)
elif module_type=='data_server':
create_data_server_module(*args,**kwargs)
def create_network_server_module(driver,agent_name=None,module_name=None,component_group=None,type=None,network_component=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,ip=None,tag_name=None,description=None):
# component_group -> Example: Remote ICMP network agent (latency)
# network_component -> Example: Host Alive
#The type variable is optional, but required if component_group and network_component variables are specified
search_agent(driver,agent_name)
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
if agent_name != None:
search_agent(driver,agent_name)
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new network server module")
driver.find_element_by_xpath('//*[@id="create_module_type"]/table/tbody/tr/td[5]/input').click()
@ -61,6 +68,7 @@ def create_network_server_module(driver,agent_name,module_name=None,component_gr
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
if module_name != None:
time.sleep(3)
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
@ -76,7 +84,62 @@ def create_network_server_module(driver,agent_name,module_name=None,component_gr
driver.find_element_by_id("submit-crtbutton").click()
def create_data_server_module(driver,module_name,agent_name=None,type=None,min_warning=None,max_warning=None,min_critical=None,max_critical=None,tag_name=None,description=None):
# type -> Example: Generic numeric
# The type variable is Generic numeric by default
if agent_name != None:
search_agent(driver,agent_name)
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Manage"]').click()
driver.find_element_by_xpath('//ul[@class="mn"]/li/a/img[@data-title="Modules"]').click()
Select(driver.find_element_by_id("moduletype")).select_by_visible_text("Create a new data server module")
driver.find_element_by_xpath('//*[@id="create_module_type"]/table/tbody/tr/td[5]/input').click()
driver.find_element_by_xpath('//a[contains(.,"Advanced options")]').click()
driver.find_element_by_id("text-name").clear()
driver.find_element_by_id("text-name").send_keys(module_name)
if type != None:
Select(driver.find_element_by_id("id_module_type")).select_by_visible_text(type)
if min_warning != None:
driver.find_element_by_id("text-min_warning").clear()
driver.find_element_by_id("text-min_warning").send_keys(min_warning)
if max_warning != None:
driver.find_element_by_id("text-max_warning").clear()
driver.find_element_by_id("text-max_warning").send_keys(min_warning)
if min_critical != None:
driver.find_element_by_id("text-min_critical").clear()
driver.find_element_by_id("text-min_critical").send_keys(min_critical)
if max_critical != None:
driver.find_element_by_id("text-max_critical").clear()
driver.find_element_by_id("text-max_critical").send_keys(max_critical)
if tag_name != None:
Select(driver.find_element_by_id("id_tag_available")).select_by_visible_text(tag_name)
driver.find_element_by_xpath('//*[@id="right"]').click()
if description != None:
driver.find_element_by_id("textarea_description").clear()
driver.find_element_by_id("textarea_description").send_keys(description)
driver.find_element_by_id("submit-crtbutton").click()
def delete_module (driver,agent_name,module_name):
search_agent(driver,agent_name)

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from common_classes_60 import PandoraWebDriverTestCase
from common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, logout
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
def create_policy(driver,policy_name,group,description=None):
click_menu_element(driver,"Manage policies")
driver.find_element_by_id("submit-crt").click()
driver.find_element_by_id("text-name").send_keys(policy_name)
driver.find_element_by_xpath('//option[contains(.,"'+group+'")]').click()
if description!= None:
driver.find_element_by_id("textarea_description").send_keys(description)
driver.find_element_by_id("submit-crt").click()