Created Services test to its new version (with API calls)

This commit is contained in:
cesar991 2016-08-30 16:27:38 +02:00
parent ff46f5c628
commit 6f2d18227c
3 changed files with 187 additions and 10 deletions

170
tests/console/Services.py Normal file
View File

@ -0,0 +1,170 @@
# -*- coding: utf-8 -*-
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_classes_60 import PandoraWebDriverTestCase
from include.common_functions_60 import login, click_menu_element, detect_and_pass_all_wizards, is_enterprise, gen_random_string
from include.agent_functions import *
from include.module_functions import *
from include.service_functions import *
from include.api_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
from selenium.webdriver.remote.webelement import WebElement
import unittest, time, re
class Service(PandoraWebDriverTestCase):
test_name = u'Service tests'
test_description = u''
tickets_associated = []
agent_name = gen_random_string(6)
module_critical_1_name = gen_random_string(6)
module_critical_2_name = gen_random_string(6)
module_critical_3_name = gen_random_string(6)
module_normal_1_name = gen_random_string(6)
module_normal_2_name = gen_random_string(6)
module_warning_1_name = gen_random_string(6)
@is_enterprise
def test_A_simple_service(self):
u"""
Add 3 modules in Simple service, two critical and one in warning, force service and check that service is warning.
"""
service_name = gen_random_string(6)
driver = self.driver
self.login()
detect_and_pass_all_wizards(driver)
activate_api(driver,"1234")
params = [self.agent_name,"127.0.0.1","0","4","0","300","2","pandorafms","2","0","0","pruebas"]
create_agent_api(driver,params,user="admin",pwd="pandora")
# creamos 3 modulos uno que este router ping (127.0.0.3) y otro ping printer (127.0.0.1) y Apache server -> Host latency min_warning 0.01
time.sleep(3)
params = [self.agent_name,self.module_critical_1_name,"0","6","1","0","0","0","0","0","0","0","0","129.99.40.1","0","0","180","0","0","0","0","Host_Alive"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
time.sleep(3)
params = [self.agent_name,self.module_critical_2_name,"0","6","1","0","0","0","0","0","0","0","0","129.99.40.1","0","0","180","0","0","0","0","Host_Alive"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
time.sleep(3)
params = [self.agent_name,self.module_critical_3_name,"0","6","1","0","0","0","0","0","0","0","0","129.99.40.1","0","0","180","0","0","0","0","Host_Alive"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
time.sleep(3)
params = [self.agent_name,self.module_normal_1_name,"0","6","1","0","0","0","0","0","0","0","0","127.0.0.1","0","0","180","0","0","0","0","Host_Alive"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
time.sleep(3)
params = [self.agent_name,self.module_normal_2_name,"0","6","1","0","0","0","0","0","0","0","0","127.0.0.1","0","0","180","0","0","0","0","Host_Alive"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
time.sleep(3)
params = [self.agent_name,self.module_warning_1_name,"0","7","1","-10","9999","0","0","0","0","0","0","127.0.0.1","0","0","180","0","0","0","0","Host_Latency"]
add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234")
lista = driver.current_url.split('/')
url = lista[0]+'//'+lista[2]+'/pandora_console'
driver.get(url)
#Creamos servicio en modo simple
create_service(driver,service_name,"Applications",self.agent_name,description=service_name,mode="simple")
# añadimos los 3 modulos al servicio un router y el warning router critico printer no critico y apache critico
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_1_name,description=self.module_critical_1_name,is_critical=True)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_2_name,description=self.module_critical_2_name)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_warning_1_name,description=self.module_warning_1_name,is_critical=True)
# Forzamos el servicio y comprobamos que el estado es warning
force_service(driver,service_name)
search_service(driver,service_name,go_to_service=False)
element = driver.find_element_by_xpath('//td/img[@data-title="Warning"]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_B_simple_service(self):
u"""
Add 3 modules in Simple service, two normal and one in critical, force service and check that service is critical.
"""
service_name = gen_random_string(6)
driver = self.driver
#Creamos servicio en modo simple
create_service(driver,service_name,"Applications",self.agent_name,description=service_name,mode="simple")
# añadimos los 3 modulos al servicio un router y el warning router critico printer no critico y apache critico
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_1_name,description=self.module_critical_1_name,is_critical=True)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_2_name,description=self.module_critical_2_name)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_3_name,description=self.module_critical_3_name,is_critical=True)
# Forzamos el servicio y comprobamos que el estado es warning
force_service(driver,service_name)
search_service(driver,service_name,go_to_service=False)
element = driver.find_element_by_xpath('//td/img[@data-title="Critical"]')
self.assertIsInstance(element,WebElement)
@is_enterprise
def test_C_simple_service(self):
u"""
Add 3 modules in Simple service, two normal and one in critical, force service and check that service is critical.
"""
service_name = gen_random_string(6)
driver = self.driver
#Creamos servicio en modo simple
create_service(driver,service_name,"Applications",self.agent_name,description=service_name,mode="simple")
# añadimos los 3 modulos al servicio un router y el warning router critico printer no critico y apache critico
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_normal_1_name,description=self.module_normal_1_name,is_critical=True)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_critical_2_name,description=self.module_critical_2_name)
add_elements_to_service(driver,service_name,"Module",agent_name=self.agent_name,module=self.module_normal_1_name,description=self.module_normal_1_name,is_critical=True)
# Forzamos el servicio y comprobamos que el estado es warning
force_service(driver,service_name)
search_service(driver,service_name,go_to_service=False)
element = driver.find_element_by_xpath('//td/img[@data-title="Ok"]')
self.assertIsInstance(element,WebElement)
if __name__ == "__main__":
unittest.main()

View File

@ -24,15 +24,22 @@ def activate_api(driver,api_pwd):
driver.find_element_by_id("submit-update_button").click()
def create_agent_api(driver,params,user="admin",pwd="pandora"):
def create_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234"):
driver.get ("http://127.0.0.1/pandora_console/include/api.php?op=set&op2=new_agent&other={0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|hola&other_mode=url_encode_separator_|&user="+user+"&pass="+pwd+"".format(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11]))
lista = driver.current_url.split('/')
base_url = lista[0]+'//'+lista[2]+'/'
url = base_url+"pandora_console/include/api.php?op=set&op2=new_agent&other={0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|hola&other_mode=url_encode_separator_|".format(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11])+"&user="+user+"&pass="+pwd+"&apipass="+apipwd
driver.get(url)
def add_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234"):
def add_network_module_to_agent_api(driver,params,user="admin",pwd="pandora",apipwd="1234"):
#Describir lista params
driver.get ("http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_network_module&id={0}&other={1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}|{20}|{21}|latency%20ping&other_mode=url_encode_separator_|&apipass="+apipwd+"1234&user="+user+"&pass="+pwd+"".format(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11],params[12],params[13],params[14],params[15],params[16],params[17],params[18],params[19],params[20],params[21]))
#params[3] = id_module_type, 6 para Host Alive, 7 para Host Latency
lista = driver.current_url.split('/')
base_url = lista[0]+'//'+lista[2]+'/'
url = base_url+"pandora_console/include/api.php?op=set&op2=create_network_module&id={0}&other={1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}|{20}|{21}|latency&other_mode=url_encode_separator_|".format(params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11],params[12],params[13],params[14],params[15],params[16],params[17],params[18],params[19],params[20],params[21])+"&apipass="+apipwd+"&user="+user+"&pass="+pwd
driver.get(url)

View File

@ -143,8 +143,8 @@ def add_elements_to_service(driver,service_name,type_element,agent_name=None,mod
if type_element == "Agent":
Select(driver.find_element_by_id("type_element")).select_by_visible_text("Agent")
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(agent_name)
driver.find_element_by_id("text-agent_name").clear()
driver.find_element_by_id("text-agent_name").send_keys(agent_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+agent_name+'")]').click() # In this line you click the drop-down box search
@ -162,8 +162,8 @@ def add_elements_to_service(driver,service_name,type_element,agent_name=None,mod
Select(driver.find_element_by_id("type_element")).select_by_visible_text("Module")
driver.find_element_by_id("text-text_agent").clear()
driver.find_element_by_id("text-text_agent").send_keys(agent_name)
driver.find_element_by_id("text-agent_name").clear()
driver.find_element_by_id("text-agent_name").send_keys(agent_name)
time.sleep(3)
driver.find_element_by_xpath('//a[@class="ui-corner-all"][contains(.,"'+agent_name+'")]').click() # In this line you click the drop-down box search