Commit e4737c55 by sanshi

all

parent 17933444
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Action.action_get import ActionGet
import allure
# allure.label("")
@allure.feature("测试模块:action.get")
class TestActionGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:action.get")
def action_get(self, actionids=None, groupids=None, hostids=None, triggerids=None, mediatypeids=None, usrgrpids=None, userids=None,
scriptids=None, selectFilter=None, selectOperations=None, selectRecoveryOperations=None, selectAcknowledgeOperations=None,
countOutput=None, editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = ActionGet(_host=self.host)
api.actionids = actionids
api.groupids = groupids
api.hostids = hostids
api.triggerids = triggerids
api.mediatypeids = mediatypeids
api.usrgrpids = usrgrpids
api.userids = userids
api.scriptids = scriptids
api.selectFilter = selectFilter
api.selectOperations = selectOperations
api.selectRecoveryOperations = selectRecoveryOperations
api.selectAcknowledgeOperations = selectAcknowledgeOperations
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("action.get:无参数调用")
@allure.story("查询动作:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.action_get()
self.check_code(response=response, code=0)
@allure.title("action.get:countOutput=true")
@allure.story("查询动作:countOutput=true")
def test_case_02(self):
response = self.action_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("action.get:actionids=特定IDs")
@allure.story("查询动作:actionids=特定IDs")
def test_case_03(self):
response = self.action_get(actionids=[7])
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestActionGet()
# a.test_case_04()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.History.history_get import HistoryGet
import allure
# allure.label("")
@allure.feature("测试模块:history.get")
class TestHistoryGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:history.get")
def history_get(self, history=None, hostids=None, itemids=None, time_from=None, time_till=None, countOutput=None,
editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = HistoryGet(_host=self.host)
api.history = history
api.hostids = hostids
api.itemids = itemids
api.time_from = time_from
api.time_till = time_till
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("history.get:无参数调用")
@allure.story("查询历史:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.history_get()
self.check_code(response=response, code=0)
@allure.title("history.get:countOutput=true")
@allure.story("查询历史:countOutput=true")
def test_case_02(self):
response = self.history_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("history.get:history=0")
@allure.story("查询历史:history=0")
def test_case_03(self):
response = self.history_get(history=0)
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHistoryGet()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-11
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Host.host_create import HostCreate
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:host.create")
class TestHostCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "SS测试主机接口IP"
base_host = "SS测试主机"
base_description = "SS测试主机描述"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
# session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
# DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:host.create")
def host_create(self, host=None, description=None, groupids=None, interfaces=None, tags=None, templateids=None, macros=None, inventory=None, status=None,
tls_accept=None, tls_psk_identity=None, tls_psk=None):
api = HostCreate(_host=self.host)
api.host = host
api.description = description
api.groupids = groupids
api.interfaces = interfaces
api.tags = tags
api.templateids = templateids
api.macros = macros
api.inventory = inventory
api.status = status
api.tls_accept = tls_accept
api.tls_psk_identity = tls_psk_identity
api.tls_psk = tls_psk
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("校验查询结果")
def check_select(self, groupid, name, internal, flags):
sql = self.select_hstgrp(groupid=groupid)
for x, y in enumerate(sql):
assert y.groupid == groupid
assert y.name == name
assert y.flags == flags
assert y.internal == internal
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("host.create:IP地址相应信息")
@allure.story("创建主机接口:IP地址相应信息")
@allure.severity("blocker")
def test_case_01(self):
host = self.base_name + "01"
description = self.base_description + "01"
interfaces = {
"type": 1,
"main": 1,
"useip": 1,
"ip": "192.168.3.1",
"dns": "",
"port": "10050",
"bulk": 1
}
response = self.host_create(host=host, description=description, groupids=[87], interfaces=[interfaces], status=0,
tls_accept=1, tls_psk_identity="22", tls_psk="22")
self.check_code(response=response, code=0)
# groupid = UtilsResponse().get_result(response=response)["groupids"][0]
# self.check_select(groupid=groupid, name=name, flags=flags, internal=internal)
@allure.title("host.create:重复创建")
@allure.story("创建主机接口:重复创建")
def test_case_02(self):
name = self.base_name + "02"
flags = 0
internal = 0
response = self.host_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
self.check_select(groupid=groupid, name=name, flags=flags, internal=internal)
response = self.host_create(name=name, flags=flags, internal=internal)
self.check_code(response=response, code=100)
@allure.title("host.create:无参数调用")
@allure.story("创建主机接口:无参数调用")
def test_case_03(self):
response = self.host_create()
self.check_status(response=response, status=400)
@allure.title("host.create:name=空字符串")
@allure.story("创建主机接口:name=空字符串")
def test_case_04(self):
response = self.host_create(name="")
self.check_status(response=response, status=400)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
# case_info = os.path.split(__file__)
# case = UtilsCmd().pytest_cmd()
# r = UtilsPyTest(version=case["version"])
# r.run_main(case_info=case_info)
a = TestHostCreate()
# a.setup_class()
a.test_case_01()
# a.test_case_02()
# a.test_case_03()
# a.test_case_04()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-06
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkData.Zabbix.hstgrp import DataHstGrp
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.create")
class TestHostGroupCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("校验查询结果")
def check_select(self, groupid, name, internal, flags):
sql = self.select_hstgrp(groupid=groupid)
for x, y in enumerate(sql):
assert y.groupid == groupid
assert y.name == name
assert y.flags == flags
assert y.internal == internal
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostgroup.create:name=字符串")
@allure.story("创建主机组:name=字符串")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
flags = 0
internal = 0
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
self.check_select(groupid=groupid, name=name, flags=flags, internal=internal)
@allure.title("hostgroup.create:重复创建")
@allure.story("创建主机组:重复创建")
def test_case_02(self):
name = self.base_name + "02"
flags = 0
internal = 0
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
self.check_select(groupid=groupid, name=name, flags=flags, internal=internal)
response = self.hostgroup_create(name=name, flags=flags, internal=internal)
self.check_code(response=response, code=100)
@allure.title("hostgroup.create:无参数调用")
@allure.story("创建主机组:无参数调用")
def test_case_03(self):
response = self.hostgroup_create()
self.check_status(response=response, status=400)
@allure.title("hostgroup.create:name=空字符串")
@allure.story("创建主机组:name=空字符串")
def test_case_04(self):
response = self.hostgroup_create(name="")
self.check_status(response=response, status=400)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupCreate()
# a.setup_class()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-07
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkApi.API.HostGroup.hostGroup_delete import HostGroupDelete
from WorkData.Zabbix.hstgrp import DataHstGrp
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.delete")
class TestHostGroupDelete(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.delete")
def hostgroup_delete(self, groupids=None):
api = HostGroupDelete(_host=self.host)
api.groupids = groupids
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, name):
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
return groupid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("校验查询结果")
def check_select(self, groupid):
sql = self.select_hstgrp(groupid=groupid)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回结果")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.title("hostgroup.delete:删除的ID存在")
@allure.story("删除主机组:删除的ID存在")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
groupid = self.case_create(name=name)
response = self.hostgroup_delete(groupids=[groupid])
self.check_code(response=response, code=0)
self.check_select(groupid=groupid)
@allure.title("hostgroup.delete:删除的ID不存在 100")
@allure.story("删除主机组:删除的ID不存在 100")
def test_case_02(self):
name = self.base_name + "02"
groupid = self.case_create(name=name)
response = self.hostgroup_delete(groupids=[groupid])
self.check_code(response=response, code=0)
self.check_select(groupid=groupid)
response = self.hostgroup_delete(groupids=[groupid])
self.check_code(response=response, code=100)
self.check_msg(response=response, msg="No permissions to referred object or it does not exist!")
@allure.title("hostgroup.delete:删除多个ID")
@allure.story("删除主机组:删除多个ID")
def test_case_03(self):
name_1 = self.base_name + "031"
name_2 = self.base_name + "032"
name_3 = self.base_name + "033"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
response = self.hostgroup_delete(groupids=[groupid_1, groupid_2, groupid_3])
self.check_code(response=response, code=0)
self.check_select(groupid=groupid_1)
self.check_select(groupid=groupid_2)
self.check_select(groupid=groupid_3)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupDelete()
# a.setup_class()
# a.test_case_03()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-15
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkApi.API.HostGroup.hostGroup_massadd import HostGroupMassadd
from WorkData.Zabbix.hstgrp import DataHstGrp
from WorkData.Zabbix.hosts_groups import DataHostsGroups
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.massadd")
class TestHostGroupMassadd(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
base_hostids = [10266, 10269, 10272]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.massadd")
def hostgroup_massadd(self, groups=None, hosts=None, templates=None):
api = HostGroupMassadd(_host=self.host)
api.groups = groups
api.hosts = hosts
api.templates = templates
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, name):
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
return groupid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("查询表:hosts_groups")
def select_hosts_groups(self, groupid=None, hostid=None):
session = self.db_session()
sql = DataHostsGroups().select_all_from_allKeys(session=session, groupid=groupid, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, groupids, hostids):
for x, y in enumerate(groupids):
for q, w in enumerate(hostids):
sql = self.select_hosts_groups(groupid=y, hostid=w)
assert sql != []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("hostgroup.massadd:一个主机组 批量添加 一个主机")
@allure.story("批量添加主机组:一个主机组 批量添加 一个主机")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
groupid = self.case_create(name=name)
response = self.hostgroup_massadd(groups=[groupid], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0]], groupids=[groupid])
@allure.title("hostgroup.massadd:多个主机组 批量添加 一个主机")
@allure.story("批量添加主机组:多个主机组 批量添加 一个主机")
def test_case_02(self):
name_1 = self.base_name + "021"
name_2 = self.base_name + "022"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
response = self.hostgroup_massadd(groups=[groupid_1, groupid_2], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0]], groupids=[groupid_1, groupid_2])
@allure.title("hostgroup.massadd:多个主机组 批量添加 多个主机")
@allure.story("批量添加主机组:多个主机组 批量添加 多个主机")
def test_case_03(self):
name_1 = self.base_name + "031"
name_2 = self.base_name + "032"
name_3 = self.base_name + "033"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
response = self.hostgroup_massadd(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]], groupids=[groupid_1, groupid_2, groupid_3])
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupMassadd()
# a.setup_class()
# a.test_case_03()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-15
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkApi.API.HostGroup.hostGroup_massadd import HostGroupMassadd
from WorkApi.API.HostGroup.hostGroup_massremove import HostGroupMassremove
from WorkData.Zabbix.hstgrp import DataHstGrp
from WorkData.Zabbix.hosts_groups import DataHostsGroups
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.massremove")
class TestHostGroupMassremove(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
base_hostids = [10266, 10272, 10296]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.massadd")
def hostgroup_massadd(self, groups=None, hosts=None, templates=None):
api = HostGroupMassadd(_host=self.host)
api.groups = groups
api.hosts = hosts
api.templates = templates
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.massremove")
def hostgroup_massremove(self, groups=None, hosts=None, templates=None):
api = HostGroupMassremove(_host=self.host)
api.groups = groups
api.hosts = hosts
api.templates = templates
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, name):
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
return groupid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("查询表:hosts_groups")
def select_hosts_groups(self, groupid=None, hostid=None):
session = self.db_session()
sql = DataHostsGroups().select_all_from_allKeys(session=session, groupid=groupid, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, groupids, hostids):
for x, y in enumerate(groupids):
for q, w in enumerate(hostids):
sql = self.select_hosts_groups(groupid=y, hostid=w)
assert sql != []
@allure.step("校验查询结果")
def check_select_delete(self, groupids, hostids):
for x, y in enumerate(groupids):
for q, w in enumerate(hostids):
sql = self.select_hosts_groups(groupid=y, hostid=w)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("hostgroup.massremove:一个主机组 批量删除 一个主机")
@allure.story("批量删除主机组:一个主机组 批量删除 一个主机")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
groupid = self.case_create(name=name)
self.hostgroup_massadd(groups=[groupid], hosts=[self.base_hostids[0]])
response = self.hostgroup_massremove(groups=[groupid], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select_delete(hostids=[self.base_hostids[0]], groupids=[groupid])
@allure.title("hostgroup.massremove:多个主机组 批量删除 一个主机")
@allure.story("批量删除主机组:多个主机组 批量删除 一个主机")
def test_case_02(self):
name_1 = self.base_name + "021"
name_2 = self.base_name + "022"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
self.hostgroup_massadd(groups=[groupid_1, groupid_2], hosts=[self.base_hostids[0]])
response = self.hostgroup_massremove(groups=[groupid_1, groupid_2], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select_delete(hostids=[self.base_hostids[0]], groupids=[groupid_1, groupid_2])
@allure.title("hostgroup.massremove:多个主机组 批量删除 多个主机")
@allure.story("批量删除主机组:多个主机组 批量删除 多个主机")
def test_case_03(self):
name_1 = self.base_name + "031"
name_2 = self.base_name + "032"
name_3 = self.base_name + "033"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
self.hostgroup_massadd(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
response = self.hostgroup_massremove(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
self.check_code(response=response, code=0)
self.check_select_delete(hostids=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]], groupids=[groupid_1, groupid_2, groupid_3])
@allure.title("hostgroup.massremove:多个主机组 批量删除 部分多个主机")
@allure.story("批量删除主机组:多个主机组 批量删除 部分多个主机")
def test_case_04(self):
name_1 = self.base_name + "041"
name_2 = self.base_name + "042"
name_3 = self.base_name + "043"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
self.hostgroup_massadd(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
response = self.hostgroup_massremove(groups=[groupid_1, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1]])
self.check_code(response=response, code=0)
self.check_select_delete(hostids=[self.base_hostids[0], self.base_hostids[1]], groupids=[groupid_1, groupid_3])
self.check_select(hostids=[self.base_hostids[2]], groupids=[groupid_1, groupid_2, groupid_3])
self.check_select(hostids=[self.base_hostids[0], self.base_hostids[1]], groupids=[groupid_2])
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupMassremove()
# a.setup_class()
# a.test_case_04()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-15
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkApi.API.HostGroup.hostGroup_massadd import HostGroupMassadd
from WorkApi.API.HostGroup.hostGroup_massupdate import HostGroupMassupdate
from WorkData.Zabbix.hstgrp import DataHstGrp
from WorkData.Zabbix.hosts_groups import DataHostsGroups
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.massupdate")
class TestHostGroupMassupdate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
base_hostids = [10266, 10272, 10296]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.massadd")
def hostgroup_massadd(self, groups=None, hosts=None, templates=None):
api = HostGroupMassadd(_host=self.host)
api.groups = groups
api.hosts = hosts
api.templates = templates
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.massupdate")
def hostgroup_massupdate(self, groups=None, hosts=None, templates=None):
api = HostGroupMassupdate(_host=self.host)
api.groups = groups
api.hosts = hosts
api.templates = templates
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, name):
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
return groupid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("查询表:hosts_groups")
def select_hosts_groups(self, groupid=None, hostid=None):
session = self.db_session()
sql = DataHostsGroups().select_all_from_allKeys(session=session, groupid=groupid, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, groupids, hostids):
for x, y in enumerate(groupids):
for q, w in enumerate(hostids):
sql = self.select_hosts_groups(groupid=y, hostid=w)
assert sql != []
@allure.step("校验查询结果")
def check_select_delete(self, groupids, hostids):
import time
time.sleep(1)
for x, y in enumerate(groupids):
for q, w in enumerate(hostids):
sql = self.select_hosts_groups(groupid=y, hostid=w)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("hostgroup.massupdate:一个主机组 批量更新 一个主机")
@allure.story("批量更新主机组:一个主机组 批量更新 一个主机")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
groupid = self.case_create(name=name)
# self.hostgroup_massadd(groups=[groupid], hosts=[self.base_hostids[0]])
response = self.hostgroup_massupdate(groups=[groupid], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0]], groupids=[groupid])
@allure.title("hostgroup.massupdate:多个主机组 批量更新 一个主机")
@allure.story("批量更新主机组:多个主机组 批量更新 一个主机")
def test_case_02(self):
name_1 = self.base_name + "021"
name_2 = self.base_name + "022"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
response = self.hostgroup_massupdate(groups=[groupid_1, groupid_2], hosts=[self.base_hostids[0]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0]], groupids=[groupid_1, groupid_2])
@allure.title("hostgroup.massupdate:多个主机组 批量更新 多个主机")
@allure.story("批量更新主机组:多个主机组 批量更新 多个主机")
def test_case_03(self):
name_1 = self.base_name + "031"
name_2 = self.base_name + "032"
name_3 = self.base_name + "033"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
response = self.hostgroup_massupdate(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]], groupids=[groupid_1, groupid_2, groupid_3])
@allure.title("hostgroup.massupdate:多个主机组 批量更新 部分多个主机")
@allure.story("批量更新主机组:多个主机组 批量更新 部分多个主机")
def test_case_04(self):
name_1 = self.base_name + "041"
name_2 = self.base_name + "042"
name_3 = self.base_name + "043"
groupid_1 = self.case_create(name=name_1)
groupid_2 = self.case_create(name=name_2)
groupid_3 = self.case_create(name=name_3)
self.hostgroup_massadd(groups=[groupid_1, groupid_2, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1], self.base_hostids[2]])
response = self.hostgroup_massupdate(groups=[groupid_1, groupid_3], hosts=[self.base_hostids[0], self.base_hostids[1]])
self.check_code(response=response, code=0)
self.check_select(hostids=[self.base_hostids[0], self.base_hostids[1]], groupids=[groupid_1, groupid_3])
self.check_select(hostids=[self.base_hostids[2]], groupids=[groupid_1, groupid_2, groupid_3])
self.check_select(hostids=[self.base_hostids[0], self.base_hostids[1]], groupids=[groupid_2])
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupMassupdate()
# a.setup_class()
# a.test_case_04()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-07
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostGroup.hostGroup_create import HostGroupCreate
from WorkApi.API.HostGroup.hostGroup_update import HostGroupUpdate
from WorkData.Zabbix.hstgrp import DataHstGrp
import allure
# allure.label("")
@allure.feature("测试模块:hostgroup.update")
class TestHostGroupUpdate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机组"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHstGrp().delete_like_name(session=session, name=cls.base_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostgroup.create")
def hostgroup_create(self, name=None, groupid=None, flags=None, internal=None):
api = HostGroupCreate(_host=self.host)
api.name = name
api.groupid = groupid
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("调用接口:hostgroup.update")
def hostgroup_update(self, groupid=None, name=None, flags=None, internal=None):
api = HostGroupUpdate(_host=self.host)
api.groupid = groupid
api.name = name
api.flags = flags
api.internal = internal
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, name):
response = self.hostgroup_create(name=name)
self.check_code(response=response, code=0)
groupid = UtilsResponse().get_result(response=response)["groupids"][0]
return groupid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hstgrp")
def select_hstgrp(self, groupid=None, name=None, internal=None, flags=None):
session = self.db_session()
sql = DataHstGrp().select_all_from_allKeys(session=session, groupid=groupid, name=name, internal=internal, flags=flags)
return sql
@allure.step("校验查询结果")
def check_select(self, groupid, name, internal, flags):
sql = self.select_hstgrp(groupid=groupid)
for x, y in enumerate(sql):
assert y.groupid == groupid
assert y.name == name
assert y.flags == flags
assert y.internal == internal
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("hostgroup.update:修改name")
@allure.story("修改主机组:修改name")
@allure.severity("blocker")
def test_case_01(self):
name = self.base_name + "01"
new_name = self.base_name + "NEW01"
groupid = self.case_create(name=name)
response = self.hostgroup_update(groupid=groupid, name=new_name)
self.check_code(response=response, code=0)
self.check_select(groupid=groupid, name=new_name, internal=0, flags=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostGroupUpdate()
# a.setup_class()
# a.test_case_02()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-11
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.create")
class TestHostInterfaceCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid)
return sql
@allure.step("校验查询结果")
def check_select(self, interfaceid, hostid, main, port, _type, useip, bulk, dns, ip):
sql = self.select_interface(interfaceid=interfaceid)
for x, y in enumerate(sql):
assert y.hostid == hostid
assert y.main == main
assert y.port == port
assert y.type == _type
assert y.useip == useip
assert y.bulk == bulk
if dns != "" and ip == "":
assert y.dns == dns
elif ip != "" and dns == "":
assert y.ip == ip
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.create:IP地址相应信息")
@allure.story("创建主机接口:IP地址相应信息")
@allure.severity("blocker")
def test_case_01(self):
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
@allure.title("hostinterface.create:DNS地址相应信息")
@allure.story("创建主机接口:DNS地址相应信息")
def test_case_02(self):
response = self.hostinterface_create(ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=0, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=0, bulk=1)
@allure.title("hostinterface.create:默认接口重复添加")
@allure.story("创建主机接口:默认接口重复添加")
def test_case_03(self):
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_msg(response=response, msg="主机不能拥有多个同种类型的默认接口")
@allure.title("hostinterface.create:此类型已有默认 可添加非默认接口")
@allure.story("创建主机接口:此类型已有默认 可添加非默认接口")
def test_case_04(self):
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=4, useip=1, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=4, useip=1, bulk=1)
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
@allure.title("hostinterface.create:此类型未有默认 无法添加非默认接口")
@allure.story("创建主机接口:此类型未有默认 无法添加非默认接口")
def test_case_05(self):
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=5, useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_msg(response=response, msg="主机11的类型[Unknown interface type]没有默认接口")
@allure.title("hostinterface.create:useip=0, bulk=1")
@allure.story("创建主机接口:useip=0, bulk=1")
def test_case_06(self):
response = self.hostinterface_create(ip=self.base_ip, dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.base_port, _type=6, useip=0, bulk=1)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=6, useip=0, bulk=1)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostInterfaceCreate()
# a.setup_class()
# a.test_case_02()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-12
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_delete import HostInterfaceDelete
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.delete")
class TestHostInterfaceDelete(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.delete")
def hostinterface_delete(self, interfaceids=None):
api = HostInterfaceDelete(_host=self.host)
api.interfaceids = interfaceids
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, ip, hostid, main, port, _type, useip, bulk, dns):
response = self.hostinterface_create(ip=ip, hostid=hostid, main=main, port=port, _type=_type, useip=useip, bulk=bulk, dns=dns)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
return interfaceid
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid)
return sql
@allure.step("校验查询结果")
def check_select(self, interfaceid):
sql = self.select_interface(interfaceid=interfaceid)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.delete:删除的ID存在")
@allure.story("删除主机接口:删除的ID存在")
@allure.severity("blocker")
def test_case_01(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid])
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid)
@allure.title("hostinterface.delete:删除的ID不存在 500")
@allure.story("删除主机接口:删除的ID不存在 500")
def test_case_02(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid])
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid)
response = self.hostinterface_delete(interfaceids=[interfaceid])
self.check_status(response=response, status=500)
@allure.title("hostinterface.delete:删除多个ID")
@allure.story("删除主机接口:删除多个ID")
def test_case_03(self):
interfaceid_1 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_2 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_3 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid_1, interfaceid_2, interfaceid_3])
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid_1)
self.check_select(interfaceid=interfaceid_2)
self.check_select(interfaceid=interfaceid_3)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostInterfaceDelete()
# a.setup_class()
# a.test_case_03()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-12
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_massadd import HostInterfaceMassadd
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.massadd")
class TestHostInterfaceMassadd(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostids = [10266, 10286, 10507]
base_dns = "sanshi.zmops.cn"
base_port = "127"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[0])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[1])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[2])
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.massadd")
def hostinterface_massadd(self, hosts=None, dns=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceMassadd(_host=self.host)
api.hosts = hosts
api.interfaces_dns = dns
api.interfaces_ip = ip
api.interfaces_main = main
api.interfaces_port = port
api.interfaces_type = _type
api.interfaces_useip = useip
api.interfaces_bulk = bulk
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, ip, hostid, main, port, _type, useip, bulk, dns):
response = self.hostinterface_create(ip=ip, hostid=hostid, main=main, port=port, _type=_type, useip=useip, bulk=bulk, dns=dns)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
return interfaceid
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None, hostid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid, hostid=hostid)
return sql
@allure.step("公共测试方法")
def case_main(self, hosts, ips, dnss, mains, ports, _types, useips, bulks):
response = self.hostinterface_massadd(hosts=hosts, ip=ips, dns=dnss, main=mains,
port=ports, _type=_types, useip=useips, bulk=bulks)
self.check_code(response=response, code=0)
interfaceids = UtilsResponse().get_result(response=response)["interfaceids"]
i = 0
for q, w in enumerate(hosts):
for x, y in enumerate(ips):
self.check_select(interfaceid=interfaceids[i], hostid=hosts[q], ip=ips[x], dns=dnss[x], main=mains[x], port=ports[x],
_type=_types[x], useip=useips[x], bulk=bulks[x])
i = i + 1
@allure.step("校验查询结果")
def check_select(self, interfaceid, hostid, main, port, _type, useip, bulk, dns, ip):
sql = self.select_interface(hostid=hostid, interfaceid=interfaceid)
for x, y in enumerate(sql):
assert y.main == main
assert y.port == port
assert y.type == _type
assert y.useip == useip
assert y.bulk == bulk
if dns != "" and ip == "":
assert y.dns == dns
elif ip != "" and dns == "":
assert y.ip == ip
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.massadd:一个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:一个主机批量创建多个主机接口")
@allure.severity("blocker")
def test_case_01(self):
self.case_main(hosts=[self.base_hostids[0]], ips=[self.base_ip, self.base_ip], dnss=["", ""], mains=[1, 0], ports=["110", "111"], _types=[1, 1],
useips=[1, 1], bulks=[1, 1])
@allure.title("hostinterface.massadd:多个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:多个主机批量创建多个主机接口")
def test_case_02(self):
self.case_main(hosts=[self.base_hostids[1], self.base_hostids[2]], ips=[self.base_ip, self.base_ip], dnss=["", ""], mains=[1, 0], ports=["110", "111"], _types=[1, 1],
useips=[1, 1], bulks=[1, 1])
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
# case_info = os.path.split(__file__)
# case = UtilsCmd().pytest_cmd()
# r = UtilsPyTest(case=case)
# r.run_main()
a = TestHostInterfaceMassadd()
a.setup_class()
a.test_case_02()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-14
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_massadd import HostInterfaceMassadd
from WorkApi.API.HostInterface.hostInterface_massremove import HostInterfaceMassremove
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.massremove")
class TestHostInterfaceMassremove(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostids = [10266, 10286, 10507]
base_dns = "sanshi.zmops.cn"
base_port = "127"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[0])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[1])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[2])
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.massadd")
def hostinterface_massadd(self, hosts=None, dns=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceMassadd(_host=self.host)
api.hosts = hosts
api.interfaces_dns = dns
api.interfaces_ip = ip
api.interfaces_main = main
api.interfaces_port = port
api.interfaces_type = _type
api.interfaces_useip = useip
api.interfaces_bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.massremove")
def hostinterface_massremove(self, hostids=None, dns=None, ip=None, port=None, _type=None):
api = HostInterfaceMassremove(_host=self.host)
api.hostids = hostids
api.interfaces_dns = dns
api.interfaces_ip = ip
api.interfaces_port = port
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, ip, hostid, main, port, _type, useip, bulk, dns):
response = self.hostinterface_create(ip=ip, hostid=hostid, main=main, port=port, _type=_type, useip=useip, bulk=bulk, dns=dns)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
return interfaceid
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None, hostid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid, hostid=hostid)
return sql
@allure.step("公共测试方法")
def case_main(self, hosts, ips, dnss, mains, ports, _types, useips, bulks):
response = self.hostinterface_massadd(hosts=hosts, ip=ips, dns=dnss, main=mains,
port=ports, _type=_types, useip=useips, bulk=bulks)
self.check_code(response=response, code=0)
interfaceids = UtilsResponse().get_result(response=response)["interfaceids"]
i = 0
for q, w in enumerate(hosts):
for x, y in enumerate(ips):
self.check_select(interfaceid=interfaceids[i], hostid=hosts[q], ip=ips[x], dns=dnss[x], main=mains[x], port=ports[x],
_type=_types[x], useip=useips[x], bulk=bulks[x])
i = i + 1
return interfaceids
@allure.step("校验查询结果")
def check_select(self, interfaceid, hostid, main, port, _type, useip, bulk, dns, ip):
sql = self.select_interface(hostid=hostid, interfaceid=interfaceid)
for x, y in enumerate(sql):
assert y.main == main
assert y.port == port
assert y.type == _type
assert y.useip == useip
assert y.bulk == bulk
if dns != "" and ip == "":
assert y.dns == dns
elif ip != "" and dns == "":
assert y.ip == ip
@allure.step("校验查询结果")
def check_delete(self, interfaceids):
for x, y in enumerate(interfaceids):
sql = self.select_interface(interfaceid=y)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.massadd:一个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:一个主机批量创建多个主机接口")
@allure.severity("blocker")
def test_case_01(self):
interfaceids = self.case_main(hosts=[self.base_hostids[0]], ips=[self.base_ip, self.base_ip, self.base_ip], dnss=["", "", ""],
mains=[1, 0, 0], ports=["110", "111", "112"], _types=[1, 1, 1], useips=[1, 1, 1], bulks=[1, 1, 1])
self.hostinterface_massremove(hostids=[self.base_hostids[0]], ip=[self.base_ip, self.base_ip], dns=["", ""], port=["111", "112"])
self.hostinterface_massremove(hostids=[self.base_hostids[0]], ip=[self.base_ip], dns=[""], port=["110"])
self.check_delete(interfaceids=interfaceids)
@allure.title("hostinterface.massadd:多个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:多个主机批量创建多个主机接口")
def test_case_02(self):
interfaceids = self.case_main(hosts=[self.base_hostids[1], self.base_hostids[2]], ips=[self.base_ip, self.base_ip], dnss=["", ""],
mains=[1, 0], ports=["110", "111"], _types=[1, 1], useips=[1, 1], bulks=[1, 1])
# 先删除所有非默认的接口
self.hostinterface_massremove(hostids=[self.base_hostids[1], self.base_hostids[2]], ip=[self.base_ip], dns=[""], port=["111"])
# 才能删除所有默认的接口
self.hostinterface_massremove(hostids=[self.base_hostids[1], self.base_hostids[2]], ip=[self.base_ip], dns=[""], port=["110"])
self.check_delete(interfaceids=interfaceids)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
# case_info = os.path.split(__file__)
# case = UtilsCmd().pytest_cmd()
# r = UtilsPyTest(case=case, case_info=case_info)
# r.run_main()
a = TestHostInterfaceMassremove()
a.setup_class()
a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-14
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_massadd import HostInterfaceMassadd
from WorkApi.API.HostInterface.hostInterface_replace import HostInterfaceReplace
from WorkData.Zabbix.interface import DataInterface
import allure
import pytest
# allure.label("")
@pytest.importorskip("test_hostinterface_replace")
@allure.feature("测试模块:hostinterface.replace")
class TestHostInterfaceReplace(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostids = [10266, 10286, 10507]
base_dns = "sanshi.zmops.cn"
base_port = "127"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[0])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[1])
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostids[2])
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.massadd")
def hostinterface_massadd(self, hosts=None, dns=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceMassadd(_host=self.host)
api.hosts = hosts
api.interfaces_dns = dns
api.interfaces_ip = ip
api.interfaces_main = main
api.interfaces_port = port
api.interfaces_type = _type
api.interfaces_useip = useip
api.interfaces_bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.replace")
def hostinterface_replace(self, hostids=None, dns=None, ip=None, port=None, _type=None):
api = HostInterfaceReplace(_host=self.host)
api.hostids = hostids
api.interfaces_dns = dns
api.interfaces_ip = ip
api.interfaces_port = port
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, ip, hostid, main, port, _type, useip, bulk, dns):
response = self.hostinterface_create(ip=ip, hostid=hostid, main=main, port=port, _type=_type, useip=useip, bulk=bulk, dns=dns)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
return interfaceid
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None, hostid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid, hostid=hostid)
return sql
@allure.step("公共测试方法")
def case_main(self, hosts, ips, dnss, mains, ports, _types, useips, bulks):
response = self.hostinterface_massadd(hosts=hosts, ip=ips, dns=dnss, main=mains,
port=ports, _type=_types, useip=useips, bulk=bulks)
self.check_code(response=response, code=0)
interfaceids = UtilsResponse().get_result(response=response)["interfaceids"]
i = 0
for q, w in enumerate(hosts):
for x, y in enumerate(ips):
self.check_select(interfaceid=interfaceids[i], hostid=hosts[q], ip=ips[x], dns=dnss[x], main=mains[x], port=ports[x],
_type=_types[x], useip=useips[x], bulk=bulks[x])
i = i + 1
return interfaceids
@allure.step("校验查询结果")
def check_select(self, interfaceid, hostid, main, port, _type, useip, bulk, dns, ip):
sql = self.select_interface(hostid=hostid, interfaceid=interfaceid)
for x, y in enumerate(sql):
assert y.main == main
assert y.port == port
assert y.type == _type
assert y.useip == useip
assert y.bulk == bulk
if dns != "" and ip == "":
assert y.dns == dns
elif ip != "" and dns == "":
assert y.ip == ip
@allure.step("校验查询结果")
def check_delete(self, interfaceids):
for x, y in enumerate(interfaceids):
sql = self.select_interface(interfaceid=y)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.massadd:一个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:一个主机批量创建多个主机接口")
@allure.severity("blocker")
def test_case_01(self):
interfaceids = self.case_main(hosts=[self.base_hostids[0]], ips=[self.base_ip, self.base_ip], dnss=["", ""], mains=[1, 0],
ports=["110", "111"], _types=[1, 1], useips=[1, 1], bulks=[1, 1])
self.hostinterface_replace(hostids=[self.base_hostids[0]], ip=[self.base_ip], dns=[""], port=["112"])
# self.check_delete(interfaceids=interfaceids)
@allure.title("hostinterface.massadd:多个主机批量创建多个主机接口")
@allure.story("批量创建主机接口:多个主机批量创建多个主机接口")
def test_case_02(self):
interfaceids = self.case_main(hosts=[self.base_hostids[1], self.base_hostids[2]], ips=[self.base_ip, self.base_ip], dnss=["", ""],
mains=[1, 0], ports=["110", "111"], _types=[1, 1], useips=[1, 1], bulks=[1, 1])
# 先删除所有非默认的接口
self.hostinterface_replace(hostids=[self.base_hostids[1], self.base_hostids[2]], ip=[self.base_ip], dns=[""], port=["111"])
# 才能删除所有默认的接口
self.hostinterface_replace(hostids=[self.base_hostids[1], self.base_hostids[2]], ip=[self.base_ip], dns=[""], port=["110"])
self.check_delete(interfaceids=interfaceids)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
# case_info = os.path.split(__file__)
# case = UtilsCmd().pytest_cmd()
# r = UtilsPyTest(case=case, case_info=case_info)
# r.run_main()
a = TestHostInterfaceReplace()
a.setup_class()
a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-12
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_update import HostInterfaceUpdate
from WorkData.Zabbix.interface import DataInterface
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.update")
class TestHostInterfaceUpdate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostinterface.create")
def hostinterface_create(self, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceCreate(_host=self.host)
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("调用接口:hostinterface.update")
def hostinterface_update(self, interfaceid=None, dns=None, hostid=None, ip=None, main=None, port=None, _type=None, useip=None, bulk=None):
api = HostInterfaceUpdate(_host=self.host)
api.interfaceid = interfaceid
api.dns = dns
api.hostid = hostid
api.ip = ip
api.main = main
api.port = port
api.type = _type
api.useip = useip
api.bulk = bulk
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, ip, hostid, main, port, _type, useip, bulk, dns):
response = self.hostinterface_create(ip=ip, hostid=hostid, main=main, port=port, _type=_type, useip=useip, bulk=bulk, dns=dns)
self.check_code(response=response, code=0)
interfaceid = UtilsResponse().get_result(response=response)["interfaceids"][0]
return interfaceid
@allure.step("查询表:interface")
def select_interface(self, interfaceid=None):
session = self.db_session()
sql = DataInterface().select_all_from_allKeys(session=session, interfaceid=interfaceid)
return sql
@allure.step("校验查询结果")
def check_select(self, interfaceid, hostid, main, port, _type, useip, bulk, dns, ip):
sql = self.select_interface(interfaceid=interfaceid)
for x, y in enumerate(sql):
assert y.hostid == hostid
assert y.main == main
assert y.port == port
assert y.type == _type
assert y.useip == useip
assert y.bulk == bulk
if dns != "" and ip == "":
assert y.dns == dns
elif ip != "" and dns == "":
assert y.ip == ip
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostinterface.update:修改ip, port")
@allure.story("更新主机接口:修改ip, port")
@allure.severity("blocker")
def test_case_01(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=1,
useip=1, bulk=1)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=1, useip=1, bulk=1)
@allure.title("hostinterface.update:修改dns")
@allure.story("更新主机接口:修改dns")
def test_case_02(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.new_port, _type=2,
useip=1, bulk=1)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.new_port, _type=2, useip=1, bulk=1)
@allure.title("hostinterface.update:默认接口无法修改成非默认接口")
@allure.story("更新主机接口:默认接口无法修改成非默认接口")
def test_case_03(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=0, port=self.new_port, _type=3,
useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
@allure.title("hostinterface.update:非默认接口无法修改成默认接口")
@allure.story("更新主机接口:非默认接口无法修改成默认接口")
def test_case_04(self):
self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=4, useip=1, bulk=1)
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=4,
useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
@allure.title("hostinterface.update:修改useip, bulk")
@allure.story("更新主机接口:修改useip, bulk")
def test_case_05(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5,
useip=0, bulk=0)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5, useip=0, bulk=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostInterfaceUpdate()
# a.setup_class()
# a.test_case_05()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-11
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostPrototype.hostPrototype_create import HostPrototypeCreate
from WorkData.Zabbix.hosts import DataHosts
from WorkData.Zabbix.group_prototype import DataGroupPrototype
from WorkData.Zabbix.host_discovery import DataHostDiscovery
import allure
# allure.label("")
@allure.feature("测试模块:hostprototype.create")
class TestHostPrototypeCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_hosts = ["{#VM.NAME}", "{#HM.NAME}", "{#VM.UUID}", "{#HV.UUID}"]
base_ruleid = 10009
groupLinks_groupid = 46
new_name = "修改SS测试主机原型"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.base_name)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.new_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostprototype.create")
def hostprototype_create(self, host=None, name=None, ruleid=None, templateids=None, groupLinks_groupid=None, groupPrototypes_name=None):
api = HostPrototypeCreate(_host=self.host)
api.host = host
api.name = name
api.ruleid = ruleid
api.templateids = templateids
api.groupLinks_groupid = groupLinks_groupid
api.groupPrototypes_name = groupPrototypes_name
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self, host, group_prototypes_name, ruleid):
response = self.hostprototype_create(host=host, name=self.base_name, ruleid=ruleid, groupLinks_groupid=[self.groupLinks_groupid],
groupPrototypes_name=[group_prototypes_name])
self.check_code(response=response, code=0)
hostid = UtilsResponse().get_result(response=response)["hostids"][0]
return hostid
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:hosts")
def select_hosts(self, hostid=None):
session = self.db_session()
sql = DataHosts().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("查询表:group_prototype")
def select_group_prototype(self, hostid=None):
session = self.db_session()
sql = DataGroupPrototype().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("查询表:host_discovery")
def select_host_discovery(self, hostid=None):
session = self.db_session()
sql = DataHostDiscovery().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, hostid, host, name, flags, groupPrototypes_name, groupid, parent_itemid):
sql = self.select_hosts(hostid=hostid)
for x, y in enumerate(sql):
assert y.host == host
assert y.name == name
assert y.flags == flags
sql = self.select_group_prototype(hostid=hostid)
assert sql != []
for x, y in enumerate(sql):
if y.name is not "":
# self.log.debug(y.name)
# self.log.debug(groupPrototypes_name)
assert y.name == groupPrototypes_name
elif y.groupid is not "":
assert y.groupid == groupid
sql = self.select_host_discovery(hostid=hostid)
for x, y in enumerate(sql):
assert y.parent_itemid == parent_itemid
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostprototype.create:在指定规则下新增主机原型,并链接到主机组")
@allure.story("创建主机原型:在指定规则下新增主机原型,并链接到主机组")
@allure.severity("blocker")
def test_case_01(self):
host = self.base_hosts[0]
group_prototypes_name = self.base_hosts[0]
response = self.hostprototype_create(host=host, name=self.base_name, ruleid=self.base_ruleid, groupLinks_groupid=[self.groupLinks_groupid],
groupPrototypes_name=[group_prototypes_name])
self.check_code(response=response, code=0)
hostid = UtilsResponse().get_result(response=response)["hostids"][0]
self.check_select(hostid=hostid, host=host, name=self.base_name, flags=2,
groupPrototypes_name=group_prototypes_name, groupid=self.groupLinks_groupid, parent_itemid=self.base_ruleid)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostPrototypeCreate()
# a.setup_class()
# a.test_case_01()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-13
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostPrototype.hostPrototype_create import HostPrototypeCreate
from WorkApi.API.HostPrototype.hostPrototype_delete import HostPrototypeDelete
from WorkData.Zabbix.hosts import DataHosts
import allure
# allure.label("")
@allure.feature("测试模块:hostprototype.delete")
class TestHostPrototypeDelete(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_hosts = ["{#VM.NAME}", "{#HM.NAME}", "{#VM.UUID}", "{#HV.UUID}"]
base_ruleids = [10009, 10010, 10013, 10014]
groupLinks_groupid = 46
new_name = "修改SS测试主机原型"
new_ip = "192.168.1.28"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.base_name)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.new_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostprototype.create")
def hostprototype_create(self, host=None, name=None, ruleid=None, templateids=None, groupLinks_groupid=None, groupPrototypes_name=None):
api = HostPrototypeCreate(_host=self.host)
api.host = host
api.name = name
api.ruleid = ruleid
api.templateids = templateids
api.groupLinks_groupid = groupLinks_groupid
api.groupPrototypes_name = groupPrototypes_name
api.get_response()
return api.response
@allure.step("调用接口:hostprototype.delete")
def hostprototype_delete(self, hostids=None):
api = HostPrototypeDelete(_host=self.host)
api.hostids = hostids
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, host, group_prototypes_name, ruleid):
response = self.hostprototype_create(host=host, name=self.base_name, ruleid=ruleid, groupLinks_groupid=[self.groupLinks_groupid],
groupPrototypes_name=[group_prototypes_name])
self.check_code(response=response, code=0)
hostid = UtilsResponse().get_result(response=response)["hostids"][0]
return hostid
@allure.step("查询表:hosts")
def select_hosts(self, hostid=None):
session = self.db_session()
sql = DataHosts().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, hostid):
sql = self.select_hosts(hostid=hostid)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostprototype.delete:删除的ID存在")
@allure.story("删除主机原型:删除的ID存在")
@allure.severity("blocker")
def test_case_01(self):
host = self.base_hosts[0]
group_prototypes_name = self.base_hosts[0]
ruleid = self.base_ruleids[0]
hostid = self.case_create(host=host, group_prototypes_name=group_prototypes_name, ruleid=ruleid)
response = self.hostprototype_delete(hostids=[hostid])
self.check_code(response=response, code=0)
self.check_select(hostid=hostid)
@allure.title("hostprototype.delete:删除的ID不存在 500")
@allure.story("删除主机原型:删除的ID不存在 500")
def test_case_02(self):
host = self.base_hosts[1]
group_prototypes_name = self.base_hosts[1]
ruleid = self.base_ruleids[1]
hostid = self.case_create(host=host, group_prototypes_name=group_prototypes_name, ruleid=ruleid)
response = self.hostprototype_delete(hostids=[hostid])
self.check_code(response=response, code=0)
self.check_select(hostid=hostid)
response = self.hostprototype_delete(hostids=[hostid])
self.check_code(response=response, code=100)
@allure.title("hostprototype.delete:删除多个ID")
@allure.story("删除主机原型:删除多个ID")
def test_case_03(self):
hostid_1 = self.case_create(host=self.base_hosts[2], group_prototypes_name=self.base_hosts[2], ruleid=self.base_ruleids[2])
hostid_2 = self.case_create(host=self.base_hosts[3], group_prototypes_name=self.base_hosts[3], ruleid=self.base_ruleids[3])
response = self.hostprototype_delete(hostids=[hostid_1, hostid_2])
self.check_code(response=response, code=0)
self.check_select(hostid=hostid_1)
self.check_select(hostid=hostid_2)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostPrototypeDelete()
# a.setup_class()
# a.test_case_01()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-12
from __future__ import division
from WorkCase import CaseBase
from WorkData.Zabbix.group_prototype import DataGroupPrototype
from WorkData.Zabbix.host_discovery import DataHostDiscovery
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.HostPrototype.hostPrototype_create import HostPrototypeCreate
from WorkApi.API.HostPrototype.hostPrototype_update import HostPrototypeUpdate
from WorkData.Zabbix.hosts import DataHosts
import allure
# allure.label("")
@allure.feature("测试模块:hostprototype.update")
class TestHostPrototypeUpdate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_ip = "10.0.0.28"
base_hostid = 10266
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_hosts = ["{#VM.NAME}", "{#HM.NAME}", "{#VM.UUID}", "{#HV.UUID}"]
base_ruleids = [10009, 10010, 10013, 10014]
groupLinks_groupid = 46
new_name = "修改SS测试主机原型"
new_port = "721"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.base_name)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_name(session=session, name=cls.new_name)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:hostprototype.create")
def hostprototype_create(self, host=None, name=None, ruleid=None, templateids=None, groupLinks_groupid=None, groupPrototypes_name=None):
api = HostPrototypeCreate(_host=self.host)
api.host = host
api.name = name
api.ruleid = ruleid
api.templateids = templateids
api.groupLinks_groupid = groupLinks_groupid
api.groupPrototypes_name = groupPrototypes_name
api.get_response()
return api.response
@allure.step("调用接口:hostprototype.update")
def hostprototype_update(self, hostid=None, host=None, name=None, status=None, templateids=None,
groupLinks_groupid=None, groupPrototypes_name=None):
api = HostPrototypeUpdate(_host=self.host)
api.hostid = hostid
api.host = host
api.name = name
api.status = status
api.templateids = templateids
api.groupLinks_groupid = groupLinks_groupid
api.groupPrototypes_name = groupPrototypes_name
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("创建测试数据")
def case_create(self, host, group_prototypes_name, ruleid):
response = self.hostprototype_create(host=host, name=self.base_name, ruleid=ruleid, groupLinks_groupid=[self.groupLinks_groupid],
groupPrototypes_name=[group_prototypes_name])
self.check_code(response=response, code=0)
hostid = UtilsResponse().get_result(response=response)["hostids"][0]
return hostid
@allure.step("查询表:hosts")
def select_hosts(self, hostid=None):
session = self.db_session()
sql = DataHosts().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("查询表:group_prototype")
def select_group_prototype(self, hostid=None):
session = self.db_session()
sql = DataGroupPrototype().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("查询表:host_discovery")
def select_host_discovery(self, hostid=None):
session = self.db_session()
sql = DataHostDiscovery().select_all_from_allKeys(session=session, hostid=hostid)
return sql
@allure.step("校验查询结果")
def check_select(self, hostid, host, name, status, flags, groupPrototypes_name, groupid, parent_itemid):
sql = self.select_hosts(hostid=hostid)
for x, y in enumerate(sql):
assert y.host == host
assert y.name == name
assert y.flags == flags
assert y.status == status
sql = self.select_group_prototype(hostid=hostid)
assert sql != []
for x, y in enumerate(sql):
if y.name is not "":
self.log.debug(y.name)
self.log.debug(groupPrototypes_name)
assert y.name == groupPrototypes_name
elif y.groupid is not "":
assert y.groupid == groupid
sql = self.select_host_discovery(hostid=hostid)
for x, y in enumerate(sql):
assert y.parent_itemid == parent_itemid
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("hostprototype.update:修改name")
@allure.story("更新主机原型:修改name")
@allure.severity("blocker")
def test_case_01(self):
host = self.base_hosts[0]
group_prototypes_name = self.base_hosts[0]
ruleid = self.base_ruleids[0]
hostid = self.case_create(host=host, group_prototypes_name=group_prototypes_name, ruleid=ruleid)
response = self.hostprototype_update(hostid=hostid, name=self.new_name, host=host)
self.check_code(response=response, code=0)
self.check_select(hostid=hostid, host=host, name=self.new_name, flags=2, status=0,
groupPrototypes_name=group_prototypes_name, groupid=self.groupLinks_groupid, parent_itemid=ruleid)
@allure.title("hostprototype.update:修改status")
@allure.story("更新主机原型:修改status")
def test_case_02(self):
host = self.base_hosts[1]
group_prototypes_name = self.base_hosts[1]
ruleid = self.base_ruleids[1]
hostid = self.case_create(host=host, group_prototypes_name=group_prototypes_name, ruleid=ruleid)
response = self.hostprototype_update(hostid=hostid, name=self.base_name, host=host, status=1)
self.check_code(response=response, code=0)
self.check_select(hostid=hostid, host=host, name=self.base_name, flags=2, status=1,
groupPrototypes_name=group_prototypes_name, groupid=self.groupLinks_groupid, parent_itemid=ruleid)
@allure.title("hostprototype.update:修改host, groupPrototypes_name")
@allure.story("更新主机原型:修改host, groupPrototypes_name")
def test_case_03(self):
host = self.base_hosts[2]
group_prototypes_name = self.base_hosts[2]
ruleid = self.base_ruleids[2]
hostid = self.case_create(host=host, group_prototypes_name=group_prototypes_name, ruleid=ruleid)
response = self.hostprototype_update(hostid=hostid, name=self.base_name, host=self.base_hosts[3], status=1, groupPrototypes_name=[self.base_hosts[3]])
self.check_code(response=response, code=0)
self.check_select(hostid=hostid, host=self.base_hosts[3], name=self.base_name, flags=2, status=1,
groupPrototypes_name=self.base_hosts[3], groupid=self.groupLinks_groupid, parent_itemid=self.base_ruleids[2])
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestHostPrototypeUpdate()
# a.setup_class()
# a.test_case_03()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Maintenance.maintenance_get import MaintenanceGet
import allure
# allure.label("")
@allure.feature("测试模块:mmaintenance.get")
class TestMaintenanceGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:maintenance.get")
def maintenance_get(self, groupids=None, hostids=None, maintenanceids=None, selectGroups=None, selectHosts=None,
selectTimeperiods=None, selectTags=None, countOutput=None, editable=None, excludeSearch=None,
_filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = MaintenanceGet(_host=self.host)
api.groupids = groupids
api.hostids = hostids
api.maintenanceids = maintenanceids
api.selectGroups = selectGroups
api.selectHosts = selectHosts
api.selectTimeperiods = selectTimeperiods
api.selectTags = selectTags
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("maintenance.get:无参数调用")
@allure.story("查询维护:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.maintenance_get()
self.check_code(response=response, code=0)
@allure.title("maintenance.get:countOutput=true")
@allure.story("查询维护:countOutput=true")
def test_case_02(self):
response = self.maintenance_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("maintenance.get:maintenanceids=特定IDs")
@allure.story("查询维护:maintenanceids=特定IDs")
def test_case_03(self):
response = self.maintenance_get(maintenanceids=[1, 2])
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestMaintenanceGet()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.MediaType.mediatype_create import MediaTypeCreate
import allure
# allure.label("")
@allure.feature("测试模块:mediatype.create")
class TestMediaTypeCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_description = "SS测试媒体"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:mediatype.create")
def mediatype_create(self, description=None, _type=None, exec_path=None, gsm_modem=None, passwd=None, smtp_email=None,
smtp_helo=None, smtp_server=None, smtp_port=None, smtp_security=None, smtp_verify_host=None, smtp_verify_peer=None,
smtp_authentication=None, status=None, username=None, exec_params=None, maxsessions=None, maxattempts=None,
attempt_interval=None, content_type=None, countOutput=None,
editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None,
searchByAny=None, searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = MediaTypeCreate(_host=self.host)
api.description = description
api.type = _type
api.exec_path = exec_path
api.gsm_modem = gsm_modem
api.passwd = passwd
api.smtp_email = smtp_email
api.smtp_helo = smtp_helo
api.smtp_server = smtp_server
api.smtp_port = smtp_port
api.smtp_security = smtp_security
api.smtp_verify_host = smtp_verify_host
api.smtp_verify_peer = smtp_verify_peer
api.smtp_authentication = smtp_authentication
api.status = status
api.username = username
api.exec_params = exec_params
api.maxsessions = maxsessions
api.maxattempts = maxattempts
api.attempt_interval = attempt_interval
api.content_type = content_type
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("mediatype.create:description=字符串, _type=0")
@allure.story("创建媒体:description=字符串, _type=0")
@allure.severity("blocker")
def test_case_01(self):
description = self.base_description + "01"
_type = 0
response = self.mediatype_create(description=description, _type=_type)
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestMediaTypeCreate()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.MediaType.mediatype_get import MediaTypeGet
import allure
# allure.label("")
@allure.feature("测试模块:mediatype.get")
class TestMediaTypeGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:mediatype.get")
def mediatype_get(self, mediatypeids=None, mediaids=None, userids=None, selectUsers=None, countOutput=None,
editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None,
searchByAny=None, searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = MediaTypeGet(_host=self.host)
api.mediatypeids = mediatypeids
api.mediaids = mediaids
api.userids = userids
api.selectUsers = selectUsers
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("mediatype.get:无参数调用")
@allure.story("查询维护:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.mediatype_get()
self.check_code(response=response, code=0)
@allure.title("mediatype.get:countOutput=true")
@allure.story("查询维护:countOutput=true")
def test_case_02(self):
response = self.mediatype_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("mediatype.get:mediatypeids=特定IDs")
@allure.story("查询维护:mediatypeids=特定IDs")
def test_case_03(self):
response = self.mediatype_get(mediatypeids=[1, 5])
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestMediaTypeGet()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-14
from __future__ import division
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Problem.problem_get import ProblemGet
from WorkData.Zabbix.problem import DataProblem
from WorkCase import CaseBase
import allure
# allure.label("")
@allure.feature("测试模块:problem.get")
class TestProblemGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_description = "SS测试触发器原型"
base_expression = "{Zabbix server:vfs.fs.size[{#FSNAME},pfree].last()}<20"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
# session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
# DataTriggers().delete_description(session=session, description=cls.base_description)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:problem.get")
def problem_get(self, eventids=None, groupids=None, hostids=None, objectids=None, applicationids=None,
source=None, _object=None, acknowledged=None, suppressed=None, severities=None, evaltype=None,
tags=None, recent=None, eventid_from=None, eventid_till=None, time_from=None,
time_till=None, selectAcknowledges=None, selectTags=None, selectSuppressionData=None,
countOutput=None, editable=None, excludeSearch=None,
_filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = ProblemGet(_host=self.host)
api.eventids = eventids
api.groupids = groupids
api.hostids = hostids
api.objectids = objectids
api.applicationids = applicationids
api.source = source
api.object = _object
api.acknowledged = acknowledged
api.suppressed = suppressed
api.severities = severities
api.evaltype = evaltype
api.tags = tags
api.recent = recent
api.eventid_from = eventid_from
api.eventid_till = eventid_till
api.time_from = time_from
api.time_till = time_till
api.selectAcknowledges = selectAcknowledges
api.selectTags = selectTags
api.selectSuppressionData = selectSuppressionData
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:problem")
def select_problem(self, eventid=None):
session = self.db_session()
sql = DataProblem().select_all_from_allKeys(session=session, eventid=eventid)
return sql
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="eventid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回结果:与数据库结果是否一致")
def check_sql(self, response):
result = UtilsResponse().get_result(response=response)
for x, y in enumerate(result):
sql = self.select_problem(eventid=y["eventid"])
assert y["source"] in UtilsResponse().get_values_from_sql(_sql=sql, key="source")
assert y["object"] in UtilsResponse().get_values_from_sql(_sql=sql, key="object")
assert y["objectid"] in UtilsResponse().get_values_from_sql(_sql=sql, key="objectid")
assert y["name"] in UtilsResponse().get_values_from_sql(_sql=sql, key="name")
assert y["severity"] in UtilsResponse().get_values_from_sql(_sql=sql, key="severity")
@allure.title("problem.get:无参数调用")
@allure.story("查询告警:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.problem_get()
self.check_code(response=response, code=0)
@allure.title("problem.get:countOutput=true")
@allure.story("查询告警:countOutput=true")
def test_case_02(self):
response = self.problem_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("problem.get:output=[name]")
@allure.story("查询告警:output=[name]")
def test_case_03(self):
response = self.problem_get(output=["name"])
self.check_code(response=response, code=0)
@allure.title("triggerprototype.get:output=[source, object, objectid, name, severity]")
@allure.story("查询触发器原型:output=[source, object, objectid, name, severity]")
def test_case_05(self):
response = self.problem_get(output=["source", "object", "objectid", "name", "severity"])
self.check_code(response=response, code=0)
self.check_sql(response=response)
@allure.title("problem.get:sortfield=eventid")
@allure.story("查询告警:sortfield=eventid")
def test_case_07(self):
response = self.problem_get(sortfield=["eventid"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible=True)
@allure.title("problem.get:sortfield=eventid, sortorder=ASC")
@allure.story("查询告警:sortfield=eventid, sortorder=ASC")
def test_case_8(self):
response = self.problem_get(sortfield=["eventid"], sortorder=["ASC"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible="ASC")
@allure.title("problem.get:sortfield=eventid, sortorder=DESC")
@allure.story("查询告警:sortfield=eventid, sortorder=DESC")
def test_case_9(self):
response = self.problem_get(sortfield=["eventid"], sortorder=["DESC"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible="DESC")
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestProblemGet()
# a.setup_class()
# a.test_case_05()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-04
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Proxy.proxy_get import ProxyGet
import allure
# allure.label("")
@allure.feature("测试模块:proxy.get")
class TestProxyGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:proxy.get")
def proxy_get(self, proxyids=None, selectHosts=None, selectInterface=None, countOutput=None,
editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None,
searchByAny=None, searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = ProxyGet(_host=self.host)
api.proxyids = proxyids
api.selectHosts = selectHosts
api.selectInterface = selectInterface
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("proxy.get:无参数调用")
@allure.story("查询代理:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.proxy_get()
self.check_code(response=response, code=0)
@allure.title("proxy.get:countOutput=true")
@allure.story("查询代理:countOutput=true")
def test_case_02(self):
response = self.proxy_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("proxy.get:proxyids=特定IDs")
@allure.story("查询代理:proxyids=特定IDs")
def test_case_03(self):
response = self.proxy_get(proxyids=[10283, 10284])
self.check_code(response=response, code=0)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestProxyGet()
# a.test_case_01()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-01
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.Script.script_get import ScriptGet
import allure
# allure.label("")
@allure.feature("测试模块:script.get")
class TestScriptGet(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:script.get")
def script_get(self, groupids=None, hostids=None, scriptids=None, usrgrpids=None, selectGroups=None, selectHosts=None, countOutput=None,
editable=None, excludeSearch=None, _filter=None, limit=None, output=None, preservekeys=None, search=None, searchByAny=None,
searchWildcardsEnabled=None, sortfield=None, sortorder=None, startSearch=None):
api = ScriptGet(_host=self.host)
api.groupids = groupids
api.hostids = hostids
api.scriptids = scriptids
api.usrgrpids = usrgrpids
api.selectGroups = selectGroups
api.selectHosts = selectHosts
api.countOutput = countOutput
api.editable = editable
api.excludeSearch = excludeSearch
api.filter = _filter
api.limit = limit
api.output = output
api.preservekeys = preservekeys
api.search = search
api.searchByAny = searchByAny
api.searchWildcardsEnabled = searchWildcardsEnabled
api.sortfield = sortfield
api.sortorder = sortorder
api.startSearch = startSearch
api.get_response()
return api.response
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.title("script.get:无参数调用")
@allure.story("查询脚本:无参数调用")
@allure.severity("blocker")
def test_case_01(self):
response = self.script_get()
self.check_code(response=response, code=0)
@allure.title("script.get:countOutput=true")
@allure.story("查询脚本:countOutput=true")
def test_case_02(self):
response = self.script_get(countOutput="true")
self.check_code(response=response, code=0)
@allure.title("script.get:scriptids=特定IDs")
@allure.story("查询脚本:scriptids=特定IDs")
def test_case_03(self):
response = self.script_get(scriptids=[5])
self.check_code(response=response, code=0)
@allure.title("script.get:output=[name]")
@allure.story("查询脚本:output=[name]")
def test_case_04(self):
response = self.script_get(output=["name"])
self.check_code(response=response, code=0)
@allure.title("script.get:groupids=特定IDs, output=[name, internal, flags]")
@allure.story("查询脚本:groupids=特定IDs, output=[name, internal, flags]")
def test_case_05(self):
response = self.script_get(groupids=[5], output=["name", "internal", "flags"])
self.check_code(response=response, code=0)
self.check_sql(response=response, groupid=5)
@allure.title("script.get:limit=1")
@allure.story("查询脚本:limit=1")
def test_case_06(self):
response = self.script_get(limit=1)
self.check_code(response=response, code=0)
result = UtilsResponse().get_result(response=response)
assert len(result) == 1
@allure.title("script.get:精确搜索")
@allure.story("查询脚本:精确搜索")
def test_case_07(self):
response = self.script_get(search={"name": ["Zabbix servers"]})
self.check_code(response=response, code=0)
result = UtilsResponse().get_result(response=response)
assert len(result) == 1
@allure.title("script.get:模糊搜索")
@allure.story("查询脚本:模糊搜索")
def test_case_08(self):
response = self.script_get(search={"name": ["*Zabbix*"]}, searchByAny=True, searchWildcardsEnabled=True)
self.check_code(response=response, code=0)
result = UtilsResponse().get_result(response=response)
assert len(result) == 1
@allure.title("script.get:sortfield=groupid")
@allure.story("查询脚本:sortfield=groupid")
@allure.severity("blocker")
def test_case_09(self):
response = self.script_get(sortfield=["groupid"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible=True)
@allure.title("script.get:sortfield=groupid, sortorder=ASC")
@allure.story("查询脚本:sortfield=groupid, sortorder=ASC")
@allure.severity("blocker")
def test_case_10(self):
response = self.script_get(sortfield=["groupid"], sortorder=["ASC"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible="ASC")
@allure.title("script.get:sortfield=groupid, sortorder=DESC")
@allure.story("查询脚本:sortfield=groupid, sortorder=DESC")
@allure.severity("blocker")
def test_case_11(self):
response = self.script_get(sortfield=["groupid"], sortorder=["DESC"])
self.check_code(response=response, code=0)
self.check_sortfield(response=response, possible="DESC")
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
# case_info = os.path.split(__file__)
# case = UtilsCmd().pytest_cmd()
# r = UtilsPyTest(version=case["version"])
# r.run_main(case_info=case_info)
a = TestScriptGet()
a.setup_class()
a.test_case_04()
a.test_case_05()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-11
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.TriggerPrototype.triggerPrototype_create import TriggerPrototypeCreate
from WorkData.Zabbix.triggers import DataTriggers
from WorkData.Zabbix.trigger_tag import DataTriggerTag
import allure
# allure.label("")
@allure.feature("测试模块:triggerprototype.create")
class TestTriggerPrototypeCreate(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_description = "SS测试触发器原型"
base_expression = "{Zabbix server:vfs.fs.size[{#FSNAME},pfree].last()}<20"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataTriggers().delete_description(session=session, description=cls.base_description)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:triggerprototype.create")
def triggerprototype_create(self, description=None, expression=None, tags_tag=None, tags_value=None):
api = TriggerPrototypeCreate(_host=self.host)
api.description = description
api.expression = expression
api.tags_tag = tags_tag
api.tags_value = tags_value
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:triggers")
def select_triggers(self, triggerid=None):
session = self.db_session()
sql = DataTriggers().select_all_from_allKeys(session=session, triggerid=triggerid)
return sql
@allure.step("查询表:trigger_tag")
def select_trigger_tag(self, triggerid=None):
session = self.db_session()
sql = DataTriggerTag().select_all_from_allKeys(session=session, triggerid=triggerid)
return sql
@allure.step("校验查询结果")
def check_select(self, triggerid, description, tags_tag, tags_value):
sql = self.select_triggers(triggerid=triggerid)
for x, y in enumerate(sql):
assert y.description == description
assert y.status == 0
assert y.value == 0
sql = self.select_trigger_tag(triggerid=triggerid)
assert sql != []
for x, y in enumerate(sql):
assert y.tag == tags_tag[x]
assert y.value == tags_value[x]
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("triggerprototype.create:创建一个触发器")
@allure.story("创建触发器原型:创建一个触发器")
@allure.severity("blocker")
def test_case_01(self):
tags_tag = ["volume"]
tags_value = ["{#FSNAME}"]
response = self.triggerprototype_create(description=self.base_description, expression=self.base_expression, tags_tag=tags_tag, tags_value=tags_value)
self.check_code(response=response, code=0)
triggerid = UtilsResponse().get_result(response=response)["triggerids"][0]
self.check_select(triggerid=triggerid, description=self.base_description, tags_tag=tags_tag, tags_value=tags_value)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestTriggerPrototypeCreate()
# a.setup_class()
# a.test_case_01()
# a.test_case_02()
# a.test_case_03()
# a.test_case_06()
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-11-13
from __future__ import division
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
from WorkApi.API.TriggerPrototype.triggerPrototype_create import TriggerPrototypeCreate
from WorkApi.API.TriggerPrototype.triggerPrototype_delete import TriggerPrototypeDelete
from WorkData.Zabbix.triggers import DataTriggers
import allure
# allure.label("")
@allure.feature("测试模块:triggerprototype.delete")
class TestTriggerPrototypeDelete(object):
log = UtilsLog()
env = CaseBase().environment
host = env["host"]
db_url = env["db_url"]
db_port = env["db_port"]
db_user = env["db_user"]
db_pw = env["db_pw"]
db_base = env["db_base"]
base_name = "SS测试主机原型"
base_description = "SS测试触发器原型"
base_expression = "{Zabbix server:vfs.fs.size[{#FSNAME},pfree].last()}<20"
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataTriggers().delete_description(session=session, description=cls.base_description)
@classmethod
def teardown_class(cls):
cls.log.debug("结束执行测试套件.......")
def setup_method(self):
self.log.debug("测试用例执行开始...")
def teardown_method(self):
self.log.debug("测试用例执行结束...")
@allure.step("调用接口:triggerprototype.create")
def triggerprototype_create(self, description=None, expression=None, tags_tag=None, tags_value=None):
api = TriggerPrototypeCreate(_host=self.host)
api.description = description
api.expression = expression
api.tags_tag = tags_tag
api.tags_value = tags_value
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_create(self):
tags_tag = ["volume"]
tags_value = ["{#FSNAME}"]
response = self.triggerprototype_create(description=self.base_description, expression=self.base_expression, tags_tag=tags_tag, tags_value=tags_value)
self.check_code(response=response, code=0)
triggerid = UtilsResponse().get_result(response=response)["triggerids"][0]
return triggerid
@allure.step("调用接口:triggerprototype.delete")
def triggerprototype_delete(self, triggerids=None):
api = TriggerPrototypeDelete(_host=self.host)
api.triggerids = triggerids
api.get_response()
return api.response
@allure.step("连接数据库:zabbix")
def db_session(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
return session
@allure.step("查询表:triggers")
def select_hosts(self, triggerid=None):
session = self.db_session()
sql = DataTriggers().select_all_from_allKeys(session=session, triggerid=triggerid)
return sql
@allure.step("校验查询结果")
def check_select(self, triggerid):
sql = self.select_hosts(triggerid=triggerid)
assert sql == []
@allure.step("断言返回结果:校验排序")
def check_sortfield(self, response, possible):
result = UtilsResponse().get_result(response=response)
UtilsResponse().check_sort(_list=result, key="groupid", possible=possible)
@allure.step("断言返回结果:校验返回数据的数量")
def check_num(self, response, num):
result = UtilsResponse().get_result(response=response)
assert len(result) == num
@allure.step("断言返回结果")
def check_code(self, response, code):
_code = UtilsResponse().get_code(response=response)
assert _code == code
@allure.step("断言返回错误信息")
def check_msg(self, response, msg):
_msg = UtilsResponse().get_msg(response=response)
assert _msg == msg
@allure.step("断言返回错误结果")
def check_status(self, response, status):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.title("triggerprototype.delete:删除的ID存在")
@allure.story("删除触发器原型:删除的ID存在")
@allure.severity("blocker")
def test_case_01(self):
triggerid = self.case_create()
response = self.triggerprototype_delete(triggerids=[triggerid])
self.check_code(response=response, code=0)
self.check_select(triggerid=triggerid)
@allure.title("triggerprototype.delete:删除的ID不存在 500")
@allure.story("删除触发器原型:删除的ID不存在 500")
def test_case_02(self):
triggerid = self.case_create()
response = self.triggerprototype_delete(triggerids=[triggerid])
self.check_code(response=response, code=0)
self.check_select(triggerid=triggerid)
response = self.triggerprototype_delete(triggerids=[triggerid])
self.check_code(response=response, code=100)
@allure.title("triggerprototype.delete:删除多个ID")
@allure.story("删除触发器原型:删除多个ID")
def test_case_03(self):
triggerid_1 = self.case_create()
triggerid_2 = self.case_create()
triggerid_3 = self.case_create()
response = self.triggerprototype_delete(triggerids=[triggerid_1, triggerid_2, triggerid_3])
self.check_code(response=response, code=0)
self.check_select(triggerid=triggerid_1)
self.check_select(triggerid=triggerid_2)
self.check_select(triggerid=triggerid_3)
if __name__ == "__main__":
from WorkUtils.UtilsPyTest import UtilsPyTest
from WorkUtils.UtilsCmd import UtilsCmd
import os
# 执行自动化测试用例
case_info = os.path.split(__file__)
case = UtilsCmd().pytest_cmd()
r = UtilsPyTest(case=case, case_info=case_info)
r.run_main()
# a = TestTriggerPrototypeDelete()
# a.setup_class()
# a.test_case_03()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment