Merge pull request #371 from coreos-inc/fmt
Fix tests in response to breakage in #351
This commit is contained in:
commit
3f6f5162e8
4 changed files with 14 additions and 7 deletions
|
@ -2,13 +2,15 @@ import unittest
|
||||||
|
|
||||||
from endpoints.v1 import v1_bp
|
from endpoints.v1 import v1_bp
|
||||||
from endpoints.verbs import verbs
|
from endpoints.verbs import verbs
|
||||||
|
from app import app
|
||||||
|
|
||||||
class TestAnonymousAccessChecked(unittest.TestCase):
|
class TestAnonymousAccessChecked(unittest.TestCase):
|
||||||
def verifyBlueprint(self, blueprint):
|
def verifyBlueprint(self, blueprint):
|
||||||
class Checker(object):
|
class Checker(object):
|
||||||
def __init__(self, test_case):
|
def __init__(self, test_case):
|
||||||
self.test_case = 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):
|
def add_url_rule(self, rule, endpoint, view_function, methods=None):
|
||||||
if (not '__anon_protected' in dir(view_function) and
|
if (not '__anon_protected' in dir(view_function) and
|
||||||
|
|
|
@ -51,3 +51,5 @@ class TestConfig(DefaultConfig):
|
||||||
LICENSE_EXPIRATION_WARNING = datetime.now() + timedelta(weeks=520)
|
LICENSE_EXPIRATION_WARNING = datetime.now() + timedelta(weeks=520)
|
||||||
|
|
||||||
FEATURE_GITHUB_BUILD = True
|
FEATURE_GITHUB_BUILD = True
|
||||||
|
|
||||||
|
CLOUDWATCH_NAMESPACE = None
|
||||||
|
|
|
@ -18,11 +18,11 @@ def start_cloudwatch_sender(metrics, app):
|
||||||
"""
|
"""
|
||||||
Starts sending from metrics to a new CloudWatchSender.
|
Starts sending from metrics to a new CloudWatchSender.
|
||||||
"""
|
"""
|
||||||
try:
|
access_key = app.config.get('CLOUDWATCH_AWS_ACCESS_KEY')
|
||||||
access_key = app.config['CLOUDWATCH_AWS_ACCESS_KEY']
|
secret_key = app.config.get('CLOUDWATCH_AWS_SECRET_KEY')
|
||||||
secret_key = app.config['CLOUDWATCH_AWS_SECRET_KEY']
|
namespace = app.config.get('CLOUDWATCH_NAMESPACE')
|
||||||
namespace = app.config['CLOUDWATCH_NAMESPACE']
|
|
||||||
except KeyError:
|
if not namespace:
|
||||||
logger.debug('CloudWatch not configured')
|
logger.debug('CloudWatch not configured')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class MetricQueue(object):
|
||||||
|
|
||||||
def put(self, name, value, **kwargs):
|
def put(self, name, value, **kwargs):
|
||||||
if self._queue is None:
|
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
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -47,12 +47,15 @@ def time_after_request(name, metric_queue):
|
||||||
start = getattr(g, '_request_start_time', None)
|
start = getattr(g, '_request_start_time', None)
|
||||||
if start is None:
|
if start is None:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
dur = time.time() - start
|
dur = time.time() - start
|
||||||
dims = {'endpoint': request.endpoint}
|
dims = {'endpoint': request.endpoint}
|
||||||
|
|
||||||
metric_queue.put('ResponseTime', dur, dimensions=dims, unit='Seconds')
|
metric_queue.put('ResponseTime', dur, dimensions=dims, unit='Seconds')
|
||||||
metric_queue.put('ResponseCode', r.status_code, dimensions=dims)
|
metric_queue.put('ResponseCode', r.status_code, dimensions=dims)
|
||||||
if r.status_code < 200 or r.status_code >= 300:
|
if r.status_code < 200 or r.status_code >= 300:
|
||||||
metric_queue.put('Non200Response', 1, dimensions={'name': name})
|
metric_queue.put('Non200Response', 1, dimensions={'name': name})
|
||||||
|
|
||||||
return r
|
return r
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
Reference in a new issue