From 4625ecf2730a04f3f6e3672da094e2e07bcf03a6 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 17 Aug 2015 16:26:20 -0400 Subject: [PATCH] Fix tests in response to breakage in #351 --- test/test_anon_checked.py | 4 +++- test/testconfig.py | 2 ++ util/saas/cloudwatch.py | 10 +++++----- util/saas/metricqueue.py | 5 ++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/test_anon_checked.py b/test/test_anon_checked.py index 05a6651d8..db8f36d52 100644 --- a/test/test_anon_checked.py +++ b/test/test_anon_checked.py @@ -2,13 +2,15 @@ import unittest from endpoints.v1 import v1_bp from endpoints.verbs import verbs - +from app import app class TestAnonymousAccessChecked(unittest.TestCase): def verifyBlueprint(self, blueprint): class Checker(object): def __init__(self, test_case): self.test_case = test_case + self.first_registration = True + self.app = app def add_url_rule(self, rule, endpoint, view_function, methods=None): if (not '__anon_protected' in dir(view_function) and diff --git a/test/testconfig.py b/test/testconfig.py index 0b947fd64..75c1c3f9c 100644 --- a/test/testconfig.py +++ b/test/testconfig.py @@ -51,3 +51,5 @@ class TestConfig(DefaultConfig): LICENSE_EXPIRATION_WARNING = datetime.now() + timedelta(weeks=520) FEATURE_GITHUB_BUILD = True + + CLOUDWATCH_NAMESPACE = None diff --git a/util/saas/cloudwatch.py b/util/saas/cloudwatch.py index c25bf7e09..eb1955b53 100644 --- a/util/saas/cloudwatch.py +++ b/util/saas/cloudwatch.py @@ -18,11 +18,11 @@ def start_cloudwatch_sender(metrics, app): """ Starts sending from metrics to a new CloudWatchSender. """ - try: - access_key = app.config['CLOUDWATCH_AWS_ACCESS_KEY'] - secret_key = app.config['CLOUDWATCH_AWS_SECRET_KEY'] - namespace = app.config['CLOUDWATCH_NAMESPACE'] - except KeyError: + access_key = app.config.get('CLOUDWATCH_AWS_ACCESS_KEY') + secret_key = app.config.get('CLOUDWATCH_AWS_SECRET_KEY') + namespace = app.config.get('CLOUDWATCH_NAMESPACE') + + if not namespace: logger.debug('CloudWatch not configured') return diff --git a/util/saas/metricqueue.py b/util/saas/metricqueue.py index b99ec922f..52b51a16e 100644 --- a/util/saas/metricqueue.py +++ b/util/saas/metricqueue.py @@ -19,7 +19,7 @@ class MetricQueue(object): def put(self, name, value, **kwargs): if self._queue is None: - logging.debug('No metric queue: %s %s %s', name, value, kwargs) + logger.debug('No metric queue %s %s %s', name, value, kwargs) return try: @@ -47,12 +47,15 @@ def time_after_request(name, metric_queue): start = getattr(g, '_request_start_time', None) if start is None: return r + dur = time.time() - start dims = {'endpoint': request.endpoint} + metric_queue.put('ResponseTime', dur, dimensions=dims, unit='Seconds') metric_queue.put('ResponseCode', r.status_code, dimensions=dims) if r.status_code < 200 or r.status_code >= 300: metric_queue.put('Non200Response', 1, dimensions={'name': name}) + return r return f