diff options
author | emkael <emkael@tlen.pl> | 2020-05-13 16:09:24 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-05-13 16:09:24 +0200 |
commit | 4ff0fd0db663153bee3c2f499d152c29cc3c3bd3 (patch) | |
tree | a391093811a534292a4ae88adafa307d7f7e421e /test | |
parent | 61fe073ccb506972f85e128eb7751dcb501c1fe7 (diff) |
Moving old migration tests to new directory
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 2 | ||||
-rw-r--r-- | test/apitest/__init__.py | 0 | ||||
-rw-r--r-- | test/apitest/api.py | 48 | ||||
-rw-r--r-- | test/apitest/apitest.py | 14 | ||||
-rw-r--r-- | test/apitest/pzbs.py | 69 | ||||
-rw-r--r-- | test/csv/.emptydir | 0 | ||||
-rw-r--r-- | test/test.py | 12 | ||||
-rw-r--r-- | test/tests/ApiTest.py | 114 | ||||
-rw-r--r-- | test/tests/__init__.py | 0 |
9 files changed, 0 insertions, 259 deletions
diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index b26a5b8..0000000 --- a/test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.pyc -*.csv diff --git a/test/apitest/__init__.py b/test/apitest/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/test/apitest/__init__.py +++ /dev/null diff --git a/test/apitest/api.py b/test/apitest/api.py deleted file mode 100644 index 5fa2e4b..0000000 --- a/test/apitest/api.py +++ /dev/null @@ -1,48 +0,0 @@ -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://pzbs.pl/sedziowie/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['version'] = '1' - 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: - 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) diff --git a/test/apitest/apitest.py b/test/apitest/apitest.py deleted file mode 100644 index e75890d..0000000 --- a/test/apitest/apitest.py +++ /dev/null @@ -1,14 +0,0 @@ -class ApiTest(object): - ranks = {} - tourtypes = {'i': 1, 'p': 2, 't': 4} - def get_url(self): - pass - def get_method(self): - pass - def get_request(self, - tour_rank, tour_type, tour_boards, - cont_count, cont_rank, - override=None): - pass - def parse_response(self, response_body): - pass diff --git a/test/apitest/pzbs.py b/test/apitest/pzbs.py deleted file mode 100644 index 9f5cfa5..0000000 --- a/test/apitest/pzbs.py +++ /dev/null @@ -1,69 +0,0 @@ -import urlparse - -from bs4 import BeautifulSoup as bs - -from .apitest import ApiTest - -class PzbsCalculator(ApiTest): - ranks = { - 'o++++': 1, - 'o+++': 2, - 'o++': 3, - 'o+': 4, - 'o-': 5, - 'r': 6, - 'o': 7, - 'k': 8 - } - def get_url(self): - return 'http://pzbs.pl/sedziowie/pkl/pkle2018-old.php' - def get_method(self): - return 'post' - def get_request(self, - tour_type, tour_rank, tour_boards, - cont_count, cont_rank, - override=None): - params = { - 'rgg': 25, 'rgp': 15, 'rot': 10, 'rok1': 7, 'rok': 5, 'rtp': 4, 'rto': 2, 'rtk': 1, - 'min1': 200, 'min2': 150, 'min3': 75, 'min4': 50, 'min5': 0, 'min6': 0, 'min7': 0, 'min8': 0, - 'rgg_': 40, 'rgp_': 25, 'rot_': 15, 'rok1_': 10, 'rok_': 7, 'rtp_': 5, 'rto_': 3, 'rtk_': 2, - 'min1_': 300, 'min2_': 200, 'min3_': 100, 'min4_': 70, 'min5_': 0, 'min6_': 0, 'min7_': 0, 'min8_': 0, - 'zaw': 0.05, 'prp1': 90, 'prp2': 20, 'pru1': 2, 'pru2': 20, 'pru3': 50, - 'typ': 0, - 'rozdan': 0, - 'rng': 0, - 'iuc': 0, - 'izw': 0, - 'swk': 0, - 'srd': 0 - } - params['typ'] = self.tourtypes[tour_type] - params['rozdan'] = tour_boards - params['rng'] = self.ranks[tour_rank] - params['iuc'] = cont_count - params['izw'] = cont_count * self.tourtypes[tour_type] - params['swk'] = cont_rank - params['srd'] = max(0.15, cont_rank / (cont_count * self.tourtypes[tour_type])) - if override: - if 'points' in override: - params['min' + str(params['rng']) + '_'*params['rozdan']] = override['points'] - if 'weight' in override: - params['r' + ['', 'gg', 'gp', 'ot', 'ok1', 'ok', 'tp', 'to', 'tk'][params['rng']] + '_'*params['rozdan']] = override['weight'] - if 'players' in override: - params['zaw'] = override['players'] - if 'cutoff' in override: - for i in range(0, 3): - params['pru' + str(i+1)] = override['cutoff'][i][0] * 100 - params['prp' + str(i+1)] = override['cutoff'][i][1] * 100 - return params - - def get_response(self, text): - results = {u'points': {}} - content = bs(text, 'lxml') - for row in content.select('table')[-1].select('tr'): - cells = row.select('td') - if cells[0].text.isdigit(): - results[u'points'][cells[0].text] = int(cells[1].text) - elif cells[0].text == 'SUMA PKL': - results[u'sum'] = int(cells[1].text) - return results diff --git a/test/csv/.emptydir b/test/csv/.emptydir deleted file mode 100644 index e69de29..0000000 --- a/test/csv/.emptydir +++ /dev/null diff --git a/test/test.py b/test/test.py deleted file mode 100644 index d11e1cb..0000000 --- a/test/test.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys -import unittest - -import tests.ApiTest - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromModule(tests.ApiTest) \ - if len(sys.argv) < 2 \ - else unittest.TestLoader().loadTestsFromNames( - ['tests.ApiTest.ApiTestCase.test_%sCases' % (s) - for s in sys.argv[1:]]) - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/tests/ApiTest.py b/test/tests/ApiTest.py deleted file mode 100644 index 0af8626..0000000 --- a/test/tests/ApiTest.py +++ /dev/null @@ -1,114 +0,0 @@ -import csv -import requests -import random -import os -import unittest - -from apitest.pzbs import PzbsCalculator -from apitest.api import ApiCalculator - -def runTest(tester, params): - return tester.get_response( - requests.post( - tester.get_url(), - data=tester.get_request(*params) - ).text) - -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) - 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) - 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) - 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) - 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) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) diff --git a/test/tests/__init__.py b/test/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/test/tests/__init__.py +++ /dev/null |