-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
47 lines (40 loc) · 1.5 KB
/
test.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
from integrate import TestCase, test
#import ses
import urllib2
import ConfigParser
import json
import base64
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
PARSER = ConfigParser.ConfigParser()
PARSER.read('config.ini')
IPADRESS = PARSER.get('options', 'ipaddress')
USERNAME = PARSER.get('options', 'username')
PASSWORD = PARSER.get('options', 'password')
PORT = PARSER.get('options', 'port')
LIST = PARSER.get('options', 'LIST')
GROUP1 = PARSER.get('options', 'group1')
GROUP2 = PARSER.get('options', 'group2')
# Mgmt URL
SERVER = "https://" + IPADRESS + ":" + PORT
HEADERS = {'Content-Type': 'application/json'}
API_PATH = "/api/cli" # param
URL = SERVER + API_PATH
class Test(TestCase):
"ASA API availability test case"
@test()
def asa_con_test(self, check):
"""test request to ASA API"""
post_data = {"commands":
["show vpn-sessiondb anyconnect | include Username|Assigned IP|Group Policy"]}
req = urllib2.Request(URL, json.dumps(post_data), HEADERS)
base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD)).replace('\n', '')
req.add_header("Authorization", "Basic %s" % base64string)
self.con = urllib2.urlopen(req)
status_code = self.con.getcode()
check.equal(str(status_code), '200')
@test(skip_if_failed=["asa_con_test"])
def asa_api_test1(self, check):
"""test1 request to ASA API"""
resp = self.con.read()
check.is_not_none(resp, message=None)