-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·85 lines (64 loc) · 1.8 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
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
import httplib2
from json import load
from StringIO import StringIO
import sys
class Test:
_error = None
_reason = None
args = None
inform = None
headers = None
content = None
_requests = []
_errors = []
def __init__(self, args):
self.args = args
self.h = httplib2.Http()
self.headers = None
self.content = None
def _test(self):
pass
def runTest(self):
try:
self._requests = []
self._errors = []
self._setup()
self._test()
if len(self._requests) == 0:
self._requests.append({"headers": self.headers, "content": self.content, "func": "_request_ok"})
for request in self._requests:
request["content"] = request["content"].rstrip()
# Legacy tests
self._status = request["headers"].status
if request["headers"].status >= 500:
self._reason = "Error Code "+str(request["headers"].status)
self.error = "Internal Server Error"
self._tearUp()
return False
else:
ret = getattr(self, request["func"])(load(StringIO(request["content"])))
self._tearUp()
return ret
except:
self._error = "Except occurred in processing"
import traceback
traceback.print_exc(file=sys.stdout)
self._reason = sys.exc_info()[:2]
self._tearUp()
return False
def _getApiToken(self):
(self.headers, self.content) = self.h.request(self.args.server + "apitokens" + "/", "POST", 'data={"email":"'+self.args.user+'", "password":"'+self.args.password+'" }', headers={'content-type':'application/x-www-form-urlencoded'})
content = load(StringIO(self.content))
self.apitoken = content["apitoken"]
return self.apitoken
def _setup(self):
pass
def _tearUp(self):
pass
def getError(self):
return self._error
def getReason(self):
return self._reason
# Checks is succeeded
def succeeded(self):
return self._error is None