import httplib
import ConfigParser
import multiprocessing
def rest_test_connection_200(self):
"""this method is used for test http connection to REST Service
"""
params = {}
ns_url = TEST_DATA.get("Notification Server", "REST_TestConnection")
response = self.execute_request('GET', ns_url, params, 0, 0)
print response
return response
def rest_removeprofile_401(self):
"""
this method is used for simulating air-watch call to remove device profile to REST Service
"""
params = {
"RequestID": "123456789abcdef",
"User": {
"Email": "xwang@websense.com"
},
"Device": {
"Udid": "4B6D5E40DFB22BD57EC4AF54DA1F297A3221388B"
}
}
ns_url = TEST_DATA.get("Notification Server", "REST_RemoveProfile")
response = self.execute_request('POST', ns_url, params, 0, 1)
print response
return response
if contentflag == 0:
headers = {"Content-Type": "application/json", "Accept": "application/json"}
else:
headers = {"Content-Type": "application/xml", "Accept": "application/json"}
status = 200
try:
conn = httplib.HTTPSConnection(self.host, self.port)
if passwdflag == 0:
if acct_index == 0:
auth = base64.b64encode(self.username + ':' + self.password)
elif acct_index == 1:
auth = base64.b64encode(self.username2 + ':' + self.password)
elif acct_index == 2:
auth = base64.b64encode(self.username3 + ':' + self.password)
elif acct_index == 3:
auth = base64.b64encode(self.username4 + ':' + self.password)
else:
auth = base64.b64encode(self.username + ':' + self.wrongpassword)
headers["Authorization"] = "Basic "+auth
conn.request(requestMethod, requestURI, json.dumps(params), headers)
tmslog.log("NotificationSimu_REST_Stab.py send out REST request - Request ID : %s on %s" %(params['RequestID'],datetime.now()))
starttime = time.time()
response = conn.getresponse()
tmslog.log("NotificationSimu_REST_Stab.py get response from REST request - Request ID : %s with response %s" %(params['RequestID'], response.status))
endtime = time.time()
sec_cost = endtime - starttime
output = "time cost for REST request ID : %s and response is : %s seconds." %(params['RequestID'], str(sec_cost))
tmslog.log(output)
#tmslog.log('-'*20)
status = response.status
#return response.read().strip()
except Exception, e:
print repr(e)
finally:
if conn:
conn.close()
return status