1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
# -*- coding: UTF-8 -*-
import time
import pytest
from common.ui_common.profiles.service_functions import ServiceFunctions
from common.ui_common.profiles.service_function_forwardes import ServiceFunctionForwardes
from common.read_data.read_data import ReadData
from cases.conftest import demo_fixture
from common.ui_common.profiles.profiles_public_operations import download_file
import configparser
import os
import copy
from config.workpath import workdir
data = ReadData()
class TestServiceFunctions:
@pytest.mark.parametrize("data", data.read_data_profiles("service_functions.json"), ids=data.generate_id)
def test_serviceFunctions(self, demo_fixture, data):
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions.service_functions_case(data)
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_layer2switch_数据再修改数据",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "Layer_2_Switch:random:random->VXLAN-G:random",
"health_check": "None->BFD:600:6",
"enable": "on->off"
}
],
ids=["创建service_function_layer2switch_数据再修改数据"]
)
def test_serviceFunctions_modify(self, demo_fixture, data):
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions_name = serviceFunctions.create(data)
serviceFunctions_id = serviceFunctions.query(data, require_assertion=1, Name=serviceFunctions_name)
serviceFunctions.modify(data)
serviceFunctions.query(data, require_assertion=2, ID=serviceFunctions_id)
serviceFunctions.delete()
# ip 不允许重复反向测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_IP全局唯一case",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:35.35.35.135->",
"health_check": "BFD:600:6->",
"enable": "on->"
}
],
ids=["创建service_function_IP全局唯一测试用例"]
)
def test_serviceFunctions_ip_only_one_case(self, demo_fixture, data):
# 创建第一个
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions.serviceFunctions_vlanId_and_ip_onlyOne(data)
# vxlan-g不允许是ipv6格式地址反向测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_IP_VXLAN-G_是ipv6格式的反向用例",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"reverse_case": "VXLAN-G-ipv6",
"connectivity": "VXLAN-G:random->",
"health_check": "BFD:600:6->",
"enable": "on->"
},
{
"ids": "创建service_function_IP_VXLAN-G_是错误的ipv6格式的反向用例",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"reverse_case": "VXLAN-G-ipv6",
"connectivity": "VXLAN-G:234532->",
"health_check": "BFD:600:6->",
"enable": "on->"
},
{
"ids": "创建service_function_xvlan_数据_ip格式错误测试用例_1",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:253.159.452.365->",
"health_check": "BFD:600:6->",
"enable": "on->"
},
{
"ids": "创建service_function_xvlan_数据_ip格式错误测试用例_2",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:253.159->",
"health_check": "BFD:600:6->",
"enable": "on->"
},
{
"ids": "创建service_function_xvlan_数据_ip格式为空测试用例_1",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:空->",
"health_check": "BFD:600:6->",
"enable": "on->"
},
{
"ids": "创建service_function_layer2switch_vlan格式为空测试用例_2",
"model": "create",
"device_group": "Device_Group:GROUP 香山->",
"connectivity": "Layer_2_Switch:空:空->",
"health_check": "None->",
"enable": "on->"
},
],
ids=["创建service_function_IP_VXLAN-G_是ipv6格式的反向用例", "创建service_function_IP_VXLAN-G_是错误的ipv6格式的反向用例",
"创建service_function_xvlan_数据_ip格式错误测试用例_1", "创建service_function_xvlan_数据_ip格式错误测试用例_2",
"创建service_function_xvlan_数据_ip格式为空测试用例_1", "创建service_function_layer2switch_vlan格式为空测试用例_2"]
)
def test_serviceFunctions_vxlan_ipError_case(self, demo_fixture, data):
# 创建第一个
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions.create(data)
#列设置测试
def test_column_setting(self, demo_fixture):
column_current_name = ['Name', 'Device Tag', 'Enabled', 'Health Status', 'Connectivity', 'Health Check', 'Usage', 'Modified Time', 'Last Modified By']
column_default_dname = ["Name"]
column_custom_name = ["Name", "Enabled", "Health Check"]
column_all_name = ['Vsys ID', 'Name', 'UUID', 'Device Tag', 'Enabled', 'Health Status', 'Connectivity', 'Health Check', 'Usage', 'Modified Time', 'Last Modified By']
serviceFunctions = ServiceFunctions(demo_fixture)
# column_flags: 0---保持当前状态 1---仅显示默认列 2---显示所有列 3---显示自定义列
serviceFunctions.column_setting(column_current_name, column_flags=0)
serviceFunctions.column_setting(column_default_dname, column_flags=1)
serviceFunctions.column_setting(column_custom_name, column_flags=3)
serviceFunctions.column_setting(column_all_name, column_flags=2)
# 未生效service functions右侧详情查看测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_侧详情查看测试用例",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:random->",
"health_check": "BFD:600:6->",
"enable": "on->"
}
],
ids=["创建service_function_侧详情查看测试用例"]
)
def test_serviceFunctions_viewDetailsOnTheRight_case(self, demo_fixture, data):
# 未生效service functions右侧详情查看测试用例
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions.serviceFunctions_viewDetailsOnTheRight(data)
# 列表页Enabled按钮点击测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_xvlan_数据_listPage_enabledButton_测试用例",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:random->",
"health_check": "BFD:600:6->",
"enable": "on->"
}
],
ids=["创建service_function_xvlan_数据_listPage_enabledButton_测试用例"]
)
def test_serviceFunctions_listPageEnabledButton_case(self, demo_fixture, data):
# 未生效service functions右侧详情查看测试用例
serviceFunctions = ServiceFunctions(demo_fixture)
serviceFunctions.listPage_EnabledButton_case(data)
# SF引用数量测试用例,使用SFF数据结果
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_forwarders包含单个sf数据001",
"model": "create",
"type": "Mirroring",
"load_balance_method": "Hash_Int-IP->",
"load_balance_localization": "Nearby->",
"failure_action": "Re-dispatch:Bypass:1->",
"service_functions": [
{
"ids": "创建service_function_xvlan_g数据001",
"model": "create",
"device_group": "Data_Center:Center 香山->",
"connectivity": "VXLAN-G:random->",
"health_check": "BFD:600:6->",
"enable": "on->"
}
]
}
],
ids=["创建service_function的引用数量测试用例"]
)
def test_ServiceFunctions_referenceCount(self, demo_fixture, data):
# SF引用数量测试
# 引用为0测试
sf = ServiceFunctions(demo_fixture)
sf_data = data["service_functions"][0]
sf_name_1 = sf.create(sf_data)
time.sleep(3)
sf.query(sf_data, Name=sf_name_1)
sf.referenceCount_view(reference_count_except=0)
sf.delete()
# 引用为1测试
sff = ServiceFunctionForwardes(demo_fixture)
sff_name_1 = sff.create(data) # sff创建,包含了sf的创建
time.sleep(3)
sff_id_1 = sff.query(data, Name=sff_name_1)
sf.query(sf_data, ID=sff.serviceFunctions_id_refer)
sf.referenceCount_view(reference_count_except=1) # sf的引用计数判断
sff.query(data, ID=sff_id_1)
sff.delete()
# 右侧详情中Audit Logs查看测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_layer2switch_数据再修改数据",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "Layer_2_Switch:random:random->VXLAN-G:random",
"health_check": "None->BFD:600:6",
"enable": "on->off"
}
],
ids=["创建service_function_layer2switch_数据再修改数据"]
)
def test_auditLogs_viewDetailsOnTheRight(self, demo_fixture, data):
# 右侧详情中Audit Logs查看测试用例
sf = ServiceFunctions(demo_fixture)
sf.auditLogs_viewDetailsOnTheRight(data)
#翻页测试
def test_turn_pages(self, demo_fixture):
sf = ServiceFunctions(demo_fixture)
sf.turn_pages("random_page_num")
#切换语言测试
def test_language_change(self, demo_fixture):
sf = ServiceFunctions(demo_fixture)
sf.language_change(2)
sf.language_change(1)
sf.language_change(0)
# 列表页底部All 按钮测试
def test_listPageBottom_allSelect_case(self, demo_fixture):
sf = ServiceFunctions(demo_fixture)
sf.listPageBottom_allSelect()
# create edit 页面元素校验测试用例
@pytest.mark.parametrize(
"data",
[
{
"ids": "创建service_function_layer2switch_数据再修改数据",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "Layer_2_Switch:random:random->VXLAN-G:random",
"health_check": "None->BFD:600:6",
"enable": "on->off"
}
],
ids=["创建service_function_layer2switch_数据再修改数据"]
)
def test_check_createAndEditPageElement(self, demo_fixture, data):
sf = ServiceFunctions(demo_fixture)
sf.check_createAndEditPageElement(data)
# clear counter 功能测试
@pytest.mark.parametrize(
"data", [
{
"ids": "创建service_function_layer2switch__clear_counter功能测试",
"model": "create",
"device_group": "Device_Group:GROUP 香山->",
"connectivity": "Layer_2_Switch:random:random->",
"health_check": "None->",
"enable": "on->"
}
],
ids=["创建service_function_layer2switch__clear_counter功能测试"]
)
def test_check_clearCounter_case(self, demo_fixture, data):
sf = ServiceFunctions(demo_fixture)
sf.check_clearCounter(data)
# link功能测试用例
@pytest.mark.parametrize(
"data", [
{
"ids": "创建service_function_layer2switch_link测试用例",
"model": "create",
"device_group": "Device_Group:GROUP 香山->",
"connectivity": "Layer_2_Switch:random:random->",
"health_check": "None->",
"enable": "on->"
}
],
ids=["创建service_function_layer2switch_link测试用例"]
)
def test_link_case(self, demo_fixture, data):
link_parse = configparser.ConfigParser()
link_parse_dir = os.path.join(workdir, "config", "linkcluster.ini")
link_parse.read(link_parse_dir, encoding="utf-8")
link_list_dict = []
link_list = [2] # 可取值 1、2、 3、4、5 #这些取值来自linkcluster.ini配置文件
for i in link_list:
tmp_dict = {}
link_index = "link_{}".format(i)
tmp_dict["link_dst_cluster"] = link_parse.get(link_index, "link_dst_cluster")
tmp_dict["link_dst_vsys"] = link_parse.get(link_index, "link_dst_vsys")
tmp_dict["url"] = link_parse.get(link_index, "url")
tmp_dict["username"] = link_parse.get(link_index, "username")
tmp_dict["passwd"] = link_parse.get(link_index, "passwd")
link_list_dict.append(copy.deepcopy(tmp_dict))
print(link_list_dict)
""" 传参查考
link_list_dict = [
{
"link_dst_cluster": "42.49-User4Link",
"link_dst_vsys": "Vsys2test",
"url": "http://192.168.42.49/#/login",
"username": "admin",
"passwd": "admin"
},
]
"""
sf = ServiceFunctions(demo_fixture)
sf.check_link_case(data, link_list_dict=link_list_dict)
@pytest.mark.parametrize(
"data", [
{
"ids": "创建service_function_layer2switch_数据再修改数据",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "VXLAN-G:random->VXLAN-G:random",
"health_check": "BFD:600:6->BFD:500:5",
"enable": "on->off"
}
],
ids=["创建service_function_layer2switch_数据再修改数据"]
)
@pytest.mark.linktest
def test_lnk_extern_mod_case(self, demo_fixture, data):
# 解析 linkcluster.ini 配置文件
link_parse = configparser.ConfigParser()
link_parse_dir = os.path.join(workdir, "config", "linkcluster.ini")
link_parse.read(link_parse_dir, encoding="utf-8")
link_list_dict = []
link_list = [2] # 1 代表 Link 其他源 cluster
for i in link_list:
tmp_dict = {}
link_index = "link_{}".format(i)
tmp_dict["link_dst_cluster"] = link_parse.get(link_index, "link_dst_cluster")
tmp_dict["link_dst_vsys"] = link_parse.get(link_index, "link_dst_vsys")
tmp_dict["url"] = link_parse.get(link_index, "url")
tmp_dict["username"] = link_parse.get(link_index, "username")
tmp_dict["passwd"] = link_parse.get(link_index, "passwd")
link_list_dict.append(copy.deepcopy(tmp_dict))
print(link_list_dict)
""" 传参查考
link_list_dict = [
{
"link_dst_cluster": "42.49-User4Link",
"link_dst_vsys": "Vsys2test",
"url": "http://192.168.42.49/#/login",
"username": "admin",
"passwd": "admin"
},
]
"""
sf = ServiceFunctions(demo_fixture)
sf.chk_lnk_mod_case(data, link_list_dict=link_list_dict)
@pytest.mark.parametrize(
"data", [
{
"ids": "创建service_function_layer2switch_数据再修改数据",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "VXLAN-G:random->VXLAN-G:random",
"health_check": "BFD:600:6->BFD:500:5",
"enable": "on->off"
}
],
ids=["创建service_function_layer2switch_数据再修改数据"]
)
@pytest.mark.linktest
def test_lnk_intern_mod_case(self, demo_fixture, data):
# 解析 linkcluster.ini 配置文件
link_parse = configparser.ConfigParser()
link_parse_dir = os.path.join(workdir, "config", "linkcluster.ini")
link_parse.read(link_parse_dir, encoding="utf-8")
link_list_dict = []
link_list = [4] # 4 代表 Link 本源 cluster
for i in link_list:
tmp_dict = {}
link_index = "link_{}".format(i)
tmp_dict["link_dst_cluster"] = link_parse.get(link_index, "link_dst_cluster")
tmp_dict["link_dst_vsys"] = link_parse.get(link_index, "link_dst_vsys")
tmp_dict["url"] = link_parse.get(link_index, "url")
tmp_dict["username"] = link_parse.get(link_index, "username")
tmp_dict["passwd"] = link_parse.get(link_index, "passwd")
link_list_dict.append(copy.deepcopy(tmp_dict))
print(link_list_dict)
""" 传参查考
link_list_dict = [
{
"link_dst_cluster": "42.49-User4Link",
"link_dst_vsys": "Vsys2test",
"url": "http://192.168.42.49/#/login",
"username": "admin",
"passwd": "admin"
},
]
"""
sf = ServiceFunctions(demo_fixture)
sf.chk_lnk_mod_case(data, link_list_dict=link_list_dict)
@pytest.mark.parametrize(
"data", [
{
"ID": "!?#@",
"Name": "????????????!!!!!!!!!!!!@@@@@@@@@@@@@@@@#############################$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&******************************************???"
}
],
ids=["查找特殊字符?@#!类型数据"]
)
@pytest.mark.special
def test_query_spec_chr(self, demo_fixture, data):
sf = ServiceFunctions(demo_fixture)
sf.chk_query_spec_chr(data)
@pytest.mark.parametrize(
"data", [
{
"ids": "test_audit_log_all_operation",
"model": "modify",
"device_group": "Device_Group:GROUP 香山->Data_Center:Center 香山",
"connectivity": "VXLAN-G:random->Layer_2_Switch:random:random",
"health_check": "BFD:600:6->None",
"enable": "on->off"
}
],
)
# @pytest.mark.skip(reason='未写完')
def test_audit_log_all_operation(self, demo_fixture, data):
sf = ServiceFunctions(demo_fixture)
sf._audit_log_all_operation(data)
@pytest.mark.parametrize(
"data", [
{
"ids": "test_all_search_fields",
"model": "create",
"device_group": "Device_Group:GROUP 香山->",
"connectivity": "Layer_2_Switch:random:random->",
"health_check": "None->",
"enable": "on->"
}
],
)
def test_all_search_fields(self, demo_fixture, data):
sf = ServiceFunctions(demo_fixture)
sf._all_search_fields(data)
if __name__ == '__main__':
a = time.time()
print(111111111111)
pytest.main(['-sv', 'test_service_functions.py', '--check-max-tb=60000'])
b = time.time()
c = b - a
print("用时:::", c)
print(3333333333333)
"""
# 在测试文件的当前路径执行如下命令执行测试用例:
pytest –cache-clear -v pytest_json.py --alluredir ./allure
# 执行如下命令生成测试报告(自动打开浏览器):
allure serve allure
"""
|