Repository: trafficserver-qa Updated Branches: refs/heads/master 1e7b648b3 -> 3ed1bcd90
Cleanup of DynamicHTTPEndpoint This makes the tracking data a private variable, in addition this moves the "url" method down into the endpoint-- instead of in the test case class Project: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/commit/0e320555 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/tree/0e320555 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/diff/0e320555 Branch: refs/heads/master Commit: 0e32055538545bfe58ab83b7c0f57cba46ac9ed3 Parents: 1e7b648 Author: Thomas Jackson <[email protected]> Authored: Fri Apr 10 14:53:08 2015 -0700 Committer: Thomas Jackson <[email protected]> Committed: Fri Apr 10 14:53:08 2015 -0700 ---------------------------------------------------------------------- tsqa/endpoint.py | 36 ++++++++++++++++++++++-------------- tsqa/test_cases.py | 8 +------- 2 files changed, 23 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/0e320555/tsqa/endpoint.py ---------------------------------------------------------------------- diff --git a/tsqa/endpoint.py b/tsqa/endpoint.py index 99888bb..b5de009 100644 --- a/tsqa/endpoint.py +++ b/tsqa/endpoint.py @@ -117,7 +117,7 @@ class DynamicHTTPEndpoint(threading.Thread): def __init__(self, port=0): threading.Thread.__init__(self) # dict to store request data in - self.tracked_requests = {} + self._tracked_requests = {} self.daemon = True self.port = port @@ -136,7 +136,7 @@ class DynamicHTTPEndpoint(threading.Thread): If the tracking header is set, save the request ''' if flask.request.headers.get(self.TRACKING_HEADER): - self.tracked_requests[flask.request.headers[self.TRACKING_HEADER]] = {'request': request.copy()} + self._tracked_requests[flask.request.headers[self.TRACKING_HEADER]] = {'request': request.copy()} @self.app.after_request @@ -145,7 +145,7 @@ class DynamicHTTPEndpoint(threading.Thread): If the tracking header is set, save the response ''' if flask.request.headers.get(self.TRACKING_HEADER): - self.tracked_requests[flask.request.headers[self.TRACKING_HEADER]]['response'] = response + self._tracked_requests[flask.request.headers[self.TRACKING_HEADER]]['response'] = response return response @@ -168,17 +168,17 @@ class DynamicHTTPEndpoint(threading.Thread): ''' Return a new key for tracking a request by key ''' - key = str(len(self.tracked_requests)) - self.tracked_requests[key] = {} + key = str(len(self._tracked_requests)) + self._tracked_requests[key] = {} return key def get_tracking_by_key(self, key): ''' Return tracking data by key ''' - if key not in self.tracked_requests: + if key not in self._tracked_requests: raise Exception() - return self.tracked_requests[key] + return self._tracked_requests[key] def normalize_path(self, path): ''' @@ -206,6 +206,14 @@ class DynamicHTTPEndpoint(threading.Thread): raise Exception() del self.handlers[path] + def url(self, path=''): + ''' + Get the url for the given path in this endpoint + ''' + if path and not path.startswith('/'): + path = '/' + path + return 'http://127.0.0.1:{0}{1}'.format(self.address[1], path) + def run(self): self.server = make_server('', self.port, @@ -240,7 +248,7 @@ class TrackingWSGIServer(threading.Thread): def __init__(self, app, port=0): threading.Thread.__init__(self) # dict to store request data in - self.tracked_requests = {} + self._tracked_requests = {} self.daemon = True self.port = port @@ -255,7 +263,7 @@ class TrackingWSGIServer(threading.Thread): If the tracking header is set, save the request ''' if flask.request.headers.get(self.TRACKING_HEADER): - self.tracked_requests[flask.request.headers[self.TRACKING_HEADER]] = {'request': request.copy()} + self._tracked_requests[flask.request.headers[self.TRACKING_HEADER]] = {'request': request.copy()} @self.app.after_request @@ -264,7 +272,7 @@ class TrackingWSGIServer(threading.Thread): If the tracking header is set, save the response ''' if flask.request.headers.get(self.TRACKING_HEADER): - self.tracked_requests[flask.request.headers[self.TRACKING_HEADER]]['response'] = response + self._tracked_requests[flask.request.headers[self.TRACKING_HEADER]]['response'] = response return response @@ -272,17 +280,17 @@ class TrackingWSGIServer(threading.Thread): ''' Return a new key for tracking a request by key ''' - key = str(len(self.tracked_requests)) - self.tracked_requests[key] = {} + key = str(len(self._tracked_requests)) + self._tracked_requests[key] = {} return key def get_tracking_by_key(self, key): ''' Return tracking data by key ''' - if key not in self.tracked_requests: + if key not in self._tracked_requests: raise Exception() - return self.tracked_requests[key] + return self._tracked_requests[key] def run(self): self.server = make_server('', http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/0e320555/tsqa/test_cases.py ---------------------------------------------------------------------- diff --git a/tsqa/test_cases.py b/tsqa/test_cases.py index b314c5f..a621016 100644 --- a/tsqa/test_cases.py +++ b/tsqa/test_cases.py @@ -144,9 +144,6 @@ class DynamicHTTPEndpointCase(unittest.TestCase): cls.http_endpoint.ready.wait() - # create local requester object - cls.track_requests = tsqa.endpoint.TrackingRequests(cls.http_endpoint) - # Do this last, so we can get our stuff registered # call parent constructor super(DynamicHTTPEndpointCase, cls).setUpClass() @@ -155,10 +152,7 @@ class DynamicHTTPEndpointCase(unittest.TestCase): ''' Get the url for the local dynamic endpoint given a path ''' - if path and not path.startswith('/'): - path = '/' + path - return 'http://127.0.0.1:{0}{1}'.format(self.http_endpoint.address[1], - path) + return self.http_endpoint.url(path) class HTTPBinCase(unittest.TestCase):
