-
Notifications
You must be signed in to change notification settings - Fork 3
/
api-test.py
executable file
·75 lines (59 loc) · 1.78 KB
/
api-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
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
#!/bin/python
import pycurl
from StringIO import StringIO
import json
import os
import requests
import sys
IP=sys.argv[1]
URL_CHECK="http://"+IP+"/studentapi"
URL_LIST="http://"+IP+"/studentapi/student/list"
URL_POST="http://"+IP+"/studentapi/student"
### Check the API is responding or not
r = requests.get(URL_CHECK)
if r.status_code == 200:
print 'URL CHECK - SUCCESS'
else:
print 'URL CHECK - FAILURE'
os.system('exit 1')
### Check the LIST of Students with API
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, URL_LIST)
c.setopt(c.WRITEFUNCTION, buffer.write)
c.perform()
c.close()
body = buffer.getvalue()
data = json.loads(body)
httpstat=str(data['httpStatus'])
STAT=int(httpstat[:1])
if STAT == 2:
print 'STUDENT APP LIST CHECK - SUCCESS'
else:
print 'STUDENT APP LIST CHECK - FAILURE'
os.system('exit 1')
### INSERT DATA to Student app from API
headers = {
'Content-Type': 'application/json',
}
data = '{"studentName": "Meghan Mahadev","studentAddr": "Hyderabad","studentAge": "2","studentQulaification": "Nursary","studentPercent": "99%","studentYearPassword": "2017"}'
response = requests.post(URL_POST, headers=headers, data=data)
resp_string=str(response.status_code)
output=response.text
data = json.loads(output)
STUDENT_ID=data['data']['object']['student_id']
response=int(resp_string[:1])
if response == 2:
print 'STUDENT APP INSERT DATA - SUCCESS'
else:
print 'STUDENT APP INSERT DATA - FAILURE'
os.system('exit 1')
URL_DELETE="http://"+IP+"/studentapi/student/"+str(STUDENT_ID)
response = requests.delete(URL_DELETE, headers=headers)
resp_string =str(response.status_code)
response=int(resp_string[:1])
if response == 2:
print 'STUDENT APP DELETE DATA - SUCCESS'
else:
print 'STUDENT APP DELETE DATA - FAILURE'
os.system('exit 1')