From 1e7f93543a7b1ed89bf68839d62e6f94b852c913 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 7 Dec 2016 13:49:32 +0300 Subject: [PATCH] Added endpoints for partners_api_tests. --- tools/python/ResponseProvider.py | 65 +++++++---- tools/python/jsons.py | 185 ++++++++++++++++++++++++++++++ tools/python/run_desktop_tests.py | 2 +- 3 files changed, 228 insertions(+), 24 deletions(-) create mode 100644 tools/python/jsons.py diff --git a/tools/python/ResponseProvider.py b/tools/python/ResponseProvider.py index 2a3b26e43e..cb0ab42e95 100644 --- a/tools/python/ResponseProvider.py +++ b/tools/python/ResponseProvider.py @@ -1,13 +1,15 @@ from __future__ import print_function +import jsons import logging +import os BIG_FILE_SIZE = 47684 class Payload: - def __init__(self, message, response_code=200, headers=dict()): + def __init__(self, message, response_code=200, headers={}): self.__response_code = response_code self.__message = message self.__headers = headers @@ -96,10 +98,7 @@ active users and/or stop the server. raise NotImplementedError() - - class ResponseProvider: - def __init__(self, delegate): self.headers = list() self.delegate = delegate @@ -111,32 +110,42 @@ class ResponseProvider: def pong(self): self.delegate.got_pinged() return Payload("pong") - + + def my_id(self): return Payload(str(os.getpid())) - - + + def strip_query(self, url): + query_start = url.find("?") + if (query_start > 0): + return url[:query_start] + return url + + def response_for_url_and_headers(self, url, headers): self.headers = headers self.chunk_requested() + url = self.strip_query(url) try: return { - - "/unit_tests/1.txt" : self.test1, - "/unit_tests/notexisting_unittest": self.test_404, - "/unit_tests/permanent" : self.test_301, - "/unit_tests/47kb.file" : self.test_47_kb, - # Following two URIs are used to test downloading failures on different platforms. - "/unit_tests/mac/1234/Uruguay.mwm" : self.test_404, - "/unit_tests/linux/1234/Uruguay.mwm" : self.test_404, - "/ping" : self.pong, - "/kill" : self.kill, - "/id" :self.my_id, + "/unit_tests/1.txt": self.test1, + "/unit_tests/notexisting_unittest": self.test_404, + "/unit_tests/permanent": self.test_301, + "/unit_tests/47kb.file": self.test_47_kb, + # Following two URIs are used to test downloading failures on different platforms. + "/unit_tests/mac/1234/Uruguay.mwm": self.test_404, + "/unit_tests/linux/1234/Uruguay.mwm": self.test_404, + "/ping": self.pong, + "/kill": self.kill, + "/id": self.my_id, + "/partners/time": self.partners_time, + "/partners/price": self.partners_price, }[url]() except: return self.test_404() - + + def chunk_requested(self): if "range" in self.headers: self.is_chunked = True @@ -175,9 +184,10 @@ class ResponseProvider: self.byterange = (0, size) def chunked_response_header(self, size): - return {"Content-Range" : "bytes {start}-{end}/{out_of}".format(start=self.byterange[0], - end=self.byterange[1], - out_of=size)} + return { + "Content-Range" : "bytes {start}-{end}/{out_of}".format(start=self.byterange[0], + end=self.byterange[1], out_of=size) + } def test_47_kb(self): @@ -196,7 +206,16 @@ class ResponseProvider: return "".join(message) - + + # Partners_api_tests + def partners_time(self): + return Payload(jsons.PARTNERS_TIME) + + + def partners_price(self): + return Payload(jsons.PARTNERS_PRICE) + + def kill(self): logging.debug("Kill called in ResponseProvider") self.delegate.kill() diff --git a/tools/python/jsons.py b/tools/python/jsons.py new file mode 100644 index 0000000000..8cc7b50bfd --- /dev/null +++ b/tools/python/jsons.py @@ -0,0 +1,185 @@ +PARTNERS_PRICE = """ +{ + "prices": [ + { + "currency_code": "USD", + "display_name": "POOL", + "distance": 10.93, + "duration": 1320, + "estimate": "$13-17", + "high_estimate": 18, + "localized_display_name": "POOL", + "low_estimate": 13, + "minimum": null, + "product_id": "bc300c14-c30d-4d3f-afcb-19b240c16a13", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "uberX", + "distance": 10.93, + "duration": 1320, + "estimate": "$15-21", + "high_estimate": 21, + "localized_display_name": "uberX", + "low_estimate": 15, + "minimum": 6, + "product_id": "dee8691c-8b48-4637-b048-300eee72d58d", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "uberX + Car Seat", + "distance": 10.93, + "duration": 1320, + "estimate": "$26-31", + "high_estimate": 31, + "localized_display_name": "uberX + Car Seat", + "low_estimate": 26, + "minimum": 15, + "product_id": "bc98a16f-ad72-41a3-8624-809ce654ac57", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "uberXL", + "distance": 10.93, + "duration": 1320, + "estimate": "$27-36", + "high_estimate": 36, + "localized_display_name": "uberXL", + "low_estimate": 27, + "minimum": 7, + "product_id": "9ffa937e-7d2e-4bcf-bc2b-ffec4ef24380", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "UberBLACK", + "distance": 10.93, + "duration": 1320, + "estimate": "$48-63", + "high_estimate": 63, + "localized_display_name": "UberBLACK", + "low_estimate": 48, + "minimum": 15, + "product_id": "a52a9012-d73e-4127-8440-f273cddfd307", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "BLACK CAR + Car Seat", + "distance": 10.93, + "duration": 1320, + "estimate": "$58-73", + "high_estimate": 73, + "localized_display_name": "BLACK CAR + Car Seat", + "low_estimate": 58, + "minimum": 25, + "product_id": "2a299c73-098d-47cd-b32c-825cb155f82a", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "UberSUV", + "distance": 10.93, + "duration": 1320, + "estimate": "$59-75", + "high_estimate": 75, + "localized_display_name": "UberSUV", + "low_estimate": 59, + "minimum": 25, + "product_id": "4e6fd14c-3866-40f1-b173-f12aeb8fbbd0", + "surge_multiplier": 1.0 + }, + { + "currency_code": "USD", + "display_name": "SUV + Car Seat", + "distance": 10.93, + "duration": 1320, + "estimate": "$65-80", + "high_estimate": 80, + "localized_display_name": "SUV + Car Seat", + "low_estimate": 65, + "minimum": 35, + "product_id": "74766497-b951-4eae-98c9-a67d87e2c0c4", + "surge_multiplier": 1.0 + }, + { + "currency_code": null, + "display_name": "Wheelchair", + "distance": 10.93, + "duration": 1320, + "estimate": "Metered", + "high_estimate": null, + "localized_display_name": "Wheelchair", + "low_estimate": null, + "minimum": null, + "product_id": "89f38d7a-d184-4054-9f2e-6b57c94143d6", + "surge_multiplier": 1.0 + }, + { + "currency_code": null, + "display_name": "uberTAXI", + "distance": 10.93, + "duration": 1320, + "estimate": "Metered", + "high_estimate": null, + "localized_display_name": "uberTAXI", + "low_estimate": null, + "minimum": null, + "product_id": "f67c83fb-4668-42eb-9aa1-ab32e710c8bf", + "surge_multiplier": 1.0 + } + ] +} +""" + +PARTNERS_TIME = """ +{ + "times": [ + { + "display_name": "POOL", + "estimate": 360, + "localized_display_name": "POOL", + "product_id": "bc300c14-c30d-4d3f-afcb-19b240c16a13" + }, + { + "display_name": "uberX", + "estimate": 300, + "localized_display_name": "uberX", + "product_id": "dee8691c-8b48-4637-b048-300eee72d58d" + }, + { + "display_name": "uberXL", + "estimate": 360, + "localized_display_name": "uberXL", + "product_id": "9ffa937e-7d2e-4bcf-bc2b-ffec4ef24380" + }, + { + "display_name": "UberBLACK", + "estimate": 300, + "localized_display_name": "UberBLACK", + "product_id": "a52a9012-d73e-4127-8440-f273cddfd307" + }, + { + "display_name": "BLACK CAR + Car Seat", + "estimate": 300, + "localized_display_name": "BLACK CAR + Car Seat", + "product_id": "2a299c73-098d-47cd-b32c-825cb155f82a" + }, + { + "display_name": "UberSUV", + "estimate": 300, + "localized_display_name": "UberSUV", + "product_id": "4e6fd14c-3866-40f1-b173-f12aeb8fbbd0" + }, + { + "display_name": "SUV + Car Seat", + "estimate": 300, + "localized_display_name": "SUV + Car Seat", + "product_id": "74766497-b951-4eae-98c9-a67d87e2c0c4" + } + ] +} +""" diff --git a/tools/python/run_desktop_tests.py b/tools/python/run_desktop_tests.py index 4c0a1e7326..6acf81e6ca 100755 --- a/tools/python/run_desktop_tests.py +++ b/tools/python/run_desktop_tests.py @@ -39,7 +39,7 @@ WITH_SERVER = "with_server" PORT = 34568 -TESTS_REQUIRING_SERVER = ["downloader_tests", "storage_tests"] +TESTS_REQUIRING_SERVER = ["downloader_tests", "storage_tests", "partners_api_tests"] class TestRunner: