diff options
author | emkael <emkael@tlen.pl> | 2019-01-18 01:15:37 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-18 01:15:37 +0100 |
commit | 033cd8f39d3e88283e4eb626f35f0e97c16e9e0e (patch) | |
tree | 49894d0624e8f25c0e2201954f413020c98cafdf /test/apitest/api.py | |
parent | 8c92dbcc1fa093c3f28df21ecc13b42b4e701be3 (diff) |
Test suite for API <-> pzbs.pl comparison
Diffstat (limited to 'test/apitest/api.py')
-rw-r--r-- | test/apitest/api.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/apitest/api.py b/test/apitest/api.py new file mode 100644 index 0000000..4a52296 --- /dev/null +++ b/test/apitest/api.py @@ -0,0 +1,48 @@ +import json +import urlparse + +from .apitest import ApiTest + +class ApiCalculator(ApiTest): + ranks = { + 'o++++': 7, + 'o+++': 6, + 'o++': 5, + 'o+': 4, + 'o-': 3, + 'r': 2, + 'o': 1, + 'k': 0 + } + def get_url(self): + return 'http://localhost/pkl/api.php' + def get_method(self): + return 'post' + def get_request(self, + tour_type, tour_rank, tour_boards, + cont_count, cont_rank, + override=None): + params = {} + params['type'] = self.tourtypes[tour_type] + params['over39_boards'] = tour_boards + params['tournament_rank'] = self.ranks[tour_rank] + params['contestants'] = cont_count + params['title_sum'] = cont_rank + if override: + params['manual'] = {} + if 'points' in override: + params['manual[min_points]'] = override['points'] + if 'weight' in override: + params['manual[tournament_weight]'] = override['weight'] + if 'players' in override: + params['manual[players_coefficient]'] = override['players'] + if 'cutoff' in override: + i = 0 + for c in override['cutoff']: + params['manual[points_cutoffs][' + str(i) + '][0]'] = c[0] + params['manual[points_cutoffs][' + str(i) + '][1]'] = c[1] + i += 1 + return params + + def get_response(self, text): + return json.loads(text) |