Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zmops-test
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sanshi
zmops-test
Commits
e35dd58e
Commit
e35dd58e
authored
Dec 03, 2019
by
sanshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除主机
parent
0a1f22f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
184 additions
and
0 deletions
+184
-0
test_host_delete.py
WorkCase/API/Host/test_host_delete.py
+184
-0
No files found.
WorkCase/API/Host/test_host_delete.py
0 → 100644
View file @
e35dd58e
# -*- coding: utf-8 -*-
# 测试用例
# 作者: 陈磊
# 时间: 2019-12-02
from
__future__
import
division
from
WorkUtils.UtilsLog
import
UtilsLog
from
WorkUtils.UtilsDataBase
import
UtilsDataBase
from
WorkUtils.UtilsResponse
import
UtilsResponse
from
WorkApi.API.Host.host_create
import
HostCreate
from
WorkApi.API.Host.host_delete
import
HostDelete
from
WorkData.Zabbix.hosts
import
DataHosts
from
WorkData.Zabbix.items
import
DataItems
from
WorkCase
import
CaseBase
import
allure
@allure.feature
(
"测试模块:host.delete"
)
class
TestHostDelete
(
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_groupid
=
101
base_name
=
"SS TEST HOST DELETE"
base_ip
=
"10.0.0.10"
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
)
sql
=
DataHosts
()
.
select_like_name
(
session
=
session
,
name
=
cls
.
base_name
)
for
x
,
y
in
enumerate
(
sql
):
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
)
DataItems
()
.
delete_hostid
(
session
=
session
,
hostid
=
y
.
hostid
)
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_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
,
name
=
None
,
description
=
None
,
groupids
=
None
,
interfaces
=
None
,
tags
=
None
,
templateids
=
None
,
macros
=
None
,
inventory
=
None
,
status
=
None
,
inventory_mode
=
None
):
api
=
HostCreate
(
_host
=
self
.
host
)
api
.
host
=
host
api
.
name
=
name
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
.
inventory_mode
=
inventory_mode
api
.
tls_connect
=
1
api
.
tls_accept
=
1
api
.
tls_psk_identity
=
"Test"
api
.
tls_psk
=
"Test"
api
.
get_response
()
return
api
.
response
@allure.step
(
"调用接口:host.delete"
)
def
host_delete
(
self
,
hostids
=
None
):
api
=
HostDelete
(
_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
(
"查询表:hosts"
)
def
select_hosts
(
self
,
hostid
):
session
=
self
.
db_session
()
sql
=
DataHosts
()
.
select_all_from_allKeys
(
session
=
session
,
hostid
=
hostid
)
return
sql
@allure.step
(
"断言返回结果:校验排序"
)
def
check_sortfield
(
self
,
response
,
possible
):
result
=
UtilsResponse
()
.
get_result
(
response
=
response
)
UtilsResponse
()
.
check_sort
(
_list
=
result
,
key
=
"hostid"
,
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_select
(
self
,
hostid
):
sql
=
self
.
select_hosts
(
hostid
=
hostid
)
assert
sql
==
[]
@allure.step
(
"创建测试数据"
)
def
case_create
(
self
,
templateid
,
num
):
host
=
self
.
base_name
+
num
description
=
self
.
base_description
+
num
interfaces
=
{
"type"
:
2
,
"main"
:
1
,
"useip"
:
1
,
"ip"
:
self
.
base_ip
,
"dns"
:
""
,
"port"
:
100
,
"bulk"
:
1
}
response
=
self
.
host_create
(
host
=
host
,
description
=
description
,
groupids
=
[
self
.
base_groupid
],
interfaces
=
[
interfaces
],
status
=
0
,
templateids
=
[
templateid
],
macros
=
[{
"macro"
:
"{$SNMP_COMMUNITY}"
,
"value"
:
"public"
}])
self
.
check_code
(
response
=
response
,
code
=
0
)
self
.
hostid
=
UtilsResponse
()
.
get_result
(
response
=
response
)[
"hostids"
][
0
]
return
self
.
hostid
@allure.title
(
"host.delete:无参数调用"
)
@allure.story
(
"删除主机:无参数调用"
)
@allure.severity
(
"blocker"
)
def
test_case_01
(
self
):
response
=
self
.
host_delete
()
self
.
check_code
(
response
=
response
,
code
=
0
)
@allure.title
(
"host.delete:删除一个"
)
@allure.story
(
"删除主机:删除一个"
)
def
test_case_02
(
self
):
hostid
=
self
.
case_create
(
templateid
=
10001
,
num
=
"02"
)
response
=
self
.
host_delete
(
hostids
=
[
hostid
])
self
.
check_code
(
response
=
response
,
code
=
0
)
self
.
check_select
(
hostid
=
hostid
)
@allure.title
(
"host.delete:删除多个"
)
@allure.story
(
"删除主机:删除多个"
)
def
test_case_03
(
self
):
hostid_1
=
self
.
case_create
(
templateid
=
10001
,
num
=
"031"
)
hostid_2
=
self
.
case_create
(
templateid
=
10186
,
num
=
"032"
)
response
=
self
.
host_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 = TestHostDelete()
# a.setup_class()
# a.test_case_03()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment