From 4ff0fd0db663153bee3c2f499d152c29cc3c3bd3 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 13 May 2020 16:09:24 +0200 Subject: Moving old migration tests to new directory --- migration-test/tests/ApiTest.py | 114 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 migration-test/tests/ApiTest.py (limited to 'migration-test/tests/ApiTest.py') diff --git a/migration-test/tests/ApiTest.py b/migration-test/tests/ApiTest.py new file mode 100644 index 0000000..0af8626 --- /dev/null +++ b/migration-test/tests/ApiTest.py @@ -0,0 +1,114 @@ +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)) -- cgit v1.2.3 From 761510c4675dd5817c432d1f71c4698dd42ec77e Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 13 May 2020 18:18:44 +0200 Subject: Using migration tests to generate random unit test cases --- migration-test/apitest/api.py | 3 ++- migration-test/tests/ApiTest.py | 54 ++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 23 deletions(-) (limited to 'migration-test/tests/ApiTest.py') diff --git a/migration-test/apitest/api.py b/migration-test/apitest/api.py index 5fa2e4b..cd34844 100644 --- a/migration-test/apitest/api.py +++ b/migration-test/apitest/api.py @@ -5,6 +5,7 @@ from .apitest import ApiTest class ApiCalculator(ApiTest): ranks = { + 'kmp': 101, 'o++++': 7, 'o+++': 6, 'o++': 5, @@ -23,7 +24,7 @@ class ApiCalculator(ApiTest): cont_count, cont_rank, override=None): params = {} - params['version'] = '1' + #params['version'] = '1' params['type'] = self.tourtypes[tour_type] params['over39_boards'] = tour_boards params['tournament_rank'] = self.ranks[tour_rank] diff --git a/migration-test/tests/ApiTest.py b/migration-test/tests/ApiTest.py index 0af8626..72ecf7f 100644 --- a/migration-test/tests/ApiTest.py +++ b/migration-test/tests/ApiTest.py @@ -1,4 +1,5 @@ import csv +import json import requests import random import os @@ -8,11 +9,15 @@ from apitest.pzbs import PzbsCalculator from apitest.api import ApiCalculator def runTest(tester, params): - return tester.get_response( + request=tester.get_request(*params) + response=tester.get_response( requests.post( tester.get_url(), - data=tester.get_request(*params) + data=request ).text) + print json.dumps(request) + print json.dumps(response) + return response class ApiTestCase(unittest.TestCase): def __setupParams(self): @@ -54,10 +59,11 @@ class ApiTestCase(unittest.TestCase): 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)) + 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']: @@ -69,30 +75,33 @@ class ApiTestCase(unittest.TestCase): } p = (type, rank, boards, 35, 400, manualParams) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) + 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) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) + 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) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) + 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': [ @@ -108,7 +117,8 @@ class ApiTestCase(unittest.TestCase): random.randint(20, 25), random.randint(300, 400) / 2.0, manualParams) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) + runTest(self.api, p) + #self.assertEqual( + # runTest(self.pzbs, p), + # runTest(self.api, p), + # msg=str(p)) -- cgit v1.2.3