-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sdwan_wrong.py
84 lines (64 loc) · 2.91 KB
/
test_sdwan_wrong.py
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
import sdwan,pytest
# Disable requests security warnings for SSL certificate
# requests.session creates an object that has all the features of a traditional "requests" object but retain information
# about the TCP connection and HTTP parameters (like authentication and COOKIES)
GOOD = 0
USERNAME = 1
BASE = 2
DEVICE = 3
@pytest.fixture(scope = 'module')
def correctdata():
# Disable requests security warnings for SSL certificate
sdwan.requests.packages.urllib3.disable_warnings()
data = {"baseurl":"https://sandbox-sdwan-1.cisco.com",
"securitycheckurl" : "/j_security_check",
"tokenurl" : "/dataservice/client/token",
"devicelisturl" : "/dataservice/device",
"username" : "devnetuser",
"password" : "RG!_Yw919_83"}
return sdwan.requests.session(),data
@pytest.fixture(scope = 'module')
def wrongdatauser():
# Disable requests security warnings for SSL certificate
sdwan.requests.packages.urllib3.disable_warnings()
data = {"baseurl":"https://sandbox-sdwan-1.cisco.com",
"securitycheckurl" : "/j_security_check",
"tokenurl" : "/dataservice/client/token",
"devicelisturl" : "/dataservice/device",
"username" : "devnetuse",
"password" : "RG!_Yw919_83"}
return sdwan.requests.session(),data
def test_sdwanlogin_OK(correctdata):
assert sdwan.sdwanlogin(*correctdata) == ""
print(correctdata[0].cookies.get_dict())
def test_sdwanlogin_KO(wrongdatauser):
assert sdwan.sdwanlogin(*wrongdatauser) != ""
def test_sdwantoken_OK(correctdata):
print(correctdata[0].cookies.get_dict())
assert sdwan.sdwantoken(*correctdata).split("\n")[0] != "<html>"
def test_sdwantoken_KO(wrongdatauser):
assert sdwan.sdwantoken(*wrongdatauser).split("\n")[0] != "<html>"
def test_sdwanlistdevices_OK(correctdata):
assert sdwan.sdwanlistdevices(*correctdata).split("\n")[0] != "<html>"
def test_sdwanlistdevices_KO(wrongdatauser):
assert sdwan.sdwanlistdevices(*wrongdatauser).split("\n")[0] != "<html>"
"""
def sdwanlistdevices(session,inputdata):
# Step 3 --- Execute requests (retrieve device list from vManage)
response = session.get(f"{inputdata['baseurl']}{inputdata['devicelisturl']}",verify=False)
# Retrieve device list and print certain data for each device
devicelist = response.json()["data"]
for device in devicelist:
print(f"hostname: {device['host-name']:15} system IP: {device['system-ip']}")
if __name__ == "__main__":
data = {"baseurl":"https://sandbox-sdwan-1.cisco.com",
"securitycheckurl" : "/j_security_check",
"tokenurl" : "/dataservice/client/token",
"devicelisturl" : "/dataservice/device",
"username" : "devnetuser",
"password" : "RG!_Yw919_83"}
mysession = requests.session()
sdwanlogin(mysession,data)
sdwantoken(mysession,data)
sdwanlistdevices(mysession,data)
"""