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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
import csv
import json
import requests
import random
import os
import unittest
from apitest.pzbs import PzbsCalculator
from apitest.api import ApiCalculator
def runTest(tester, params):
request=tester.get_request(*params)
response=tester.get_response(
requests.post(
tester.get_url(),
data=request
).text)
print json.dumps(request)
print json.dumps(response)
return response
class ApiTestCase(unittest.TestCase):
def __setupParams(self):
csv_files = []
for root, dirs, files in os.walk('./csv'):
csv_files += [os.path.join(root, f) for f in files if f.lower().endswith('.csv')]
self.params = []
for csv_file in csv_files:
csv_content = csv.reader(open(csv_file), delimiter=";")
param_contents = [
row for idx, row in enumerate(csv_content) if idx == 2][0]
self.params.append((
param_contents[0][0].lower(),
None, 0,
int(param_contents[1]), float(param_contents[4])))
def setUp(self):
self.pzbs = PzbsCalculator()
self.api = ApiCalculator()
self.__setupParams()
self.longMessage=True
self.maxDiff = None
def test_csvCases(self):
for params in self.params:
for rank in ApiCalculator.ranks.keys():
for boards in [0, 1]:
p = (params[0], rank, boards, params[3], params[4])
self.assertEqual(
runTest(self.pzbs, p),
runTest(self.api, p),
msg=str(p))
def test_randomCases(self):
for i in range(0, 20):
for type in ['t', 'p', 'i']:
for rank in ApiCalculator.ranks.keys():
for boards in [0, 1]:
p = (type, rank, boards,
random.randint(6, 350),
random.randint(0, 4000) / 2.0)
runTest(self.api, p)
#self.assertEqual(
# runTest(self.pzbs, p),
# runTest(self.api, p),
# msg=str(p))
def test_customParamCases(self):
for type in ['t', 'p', 'i']:
for rank in ApiCalculator.ranks.keys():
for boards in [0, 1]:
for j in range(0, 20):
manualParams = {
'points': random.randint(20, 100)
}
p = (type, rank, boards,
35, 400, manualParams)
runTest(self.api, p)
#self.assertEqual(
# runTest(self.pzbs, p),
# runTest(self.api, p),
# msg=str(p))
for j in range(0, 20):
manualParams = {
'weight': random.randint(20, 100)
}
p = (type, rank, boards,
35, 400, manualParams)
runTest(self.api, p)
#self.assertEqual(
# runTest(self.pzbs, p),
# runTest(self.api, p),
# msg=str(p))
for j in range(0, 20):
manualParams = {
'players': random.randint(20, 100) * 0.001
}
p = (type, rank, boards,
35, 400, manualParams)
runTest(self.api, p)
#self.assertEqual(
# runTest(self.pzbs, p),
# runTest(self.api, p),
# msg=str(p))
for j in range(0, 20):
manualParams = {
'cutoff': [
[random.uniform(0.04, 0.06),
random.uniform(0.7, 0.9)],
[random.uniform(0.15, 0.35),
random.uniform(0.15, 0.35)],
[random.uniform(0.4, 0.6),
0.0]
]
}
p = (type, rank, boards,
random.randint(20, 25),
random.randint(300, 400) / 2.0,
manualParams)
runTest(self.api, p)
#self.assertEqual(
# runTest(self.pzbs, p),
# runTest(self.api, p),
# msg=str(p))
|