fix for tests so they should work on travis ci
This commit is contained in:
parent
d56ee33bad
commit
94d3fec47d
|
@ -10,11 +10,4 @@ Credits:
|
|||
of and put in here.
|
||||
- robhudson for django-debug-toolbar
|
||||
|
||||
Changes
|
||||
-------
|
||||
|
||||
0.3:
|
||||
|
||||
- added in logging handler for logging error counts to stats
|
||||
|
||||
For more see our docs at: http://readthedocs.org/docs/django-statsd/en/latest/
|
||||
|
|
|
@ -6,15 +6,22 @@ from django.conf import settings
|
|||
_statsd = None
|
||||
|
||||
|
||||
def get(name, default):
|
||||
try:
|
||||
return getattr(settings, name, default)
|
||||
except ImportError:
|
||||
return default
|
||||
|
||||
|
||||
def get_client():
|
||||
client = getattr(settings, 'STATSD_CLIENT', 'statsd.client')
|
||||
host = getattr(settings, 'STATSD_HOST', 'localhost')
|
||||
client = get('STATSD_CLIENT', 'statsd.client')
|
||||
host = get('STATSD_HOST', 'localhost')
|
||||
# This is causing problems with statsd
|
||||
# gaierror ([Errno -9] Address family for hostname not supported)
|
||||
# TODO: figure out what to do here.
|
||||
# host = socket.gethostbyaddr(host)[2][0]
|
||||
port = getattr(settings, 'STATSD_PORT', 8125)
|
||||
prefix = getattr(settings, 'STATSD_PREFIX', None)
|
||||
port = get('STATSD_PORT', 8125)
|
||||
prefix = get('STATSD_PREFIX', None)
|
||||
return import_module(client).StatsClient(host, port, prefix)
|
||||
|
||||
if not _statsd:
|
||||
|
|
|
@ -21,4 +21,3 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **kw):
|
||||
statsd.timing(kw.get('key'), time.time())
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ from django_statsd.clients import statsd
|
|||
import inspect
|
||||
import time
|
||||
|
||||
|
||||
class GraphiteMiddleware(object):
|
||||
|
||||
def process_response(self, request, response):
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from django.conf import settings
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
# Workaround for tests.
|
||||
try:
|
||||
patches = getattr(settings, 'STATSD_PATCHES', [])
|
||||
except ImportError:
|
||||
patches = []
|
||||
|
||||
patches = getattr(settings, 'STATSD_PATCHES', [])
|
||||
for patch in patches:
|
||||
import_module(patch).patch()
|
||||
|
||||
|
|
|
@ -9,4 +9,3 @@ def wrapped(method, key, *args, **kw):
|
|||
|
||||
def wrap(method, key, *args, **kw):
|
||||
return partial(wrapped, method, key, *args, **kw)
|
||||
|
||||
|
|
|
@ -1,12 +1,27 @@
|
|||
import dictconfig
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
minimal = {
|
||||
'DATABASES': {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'mydatabase'
|
||||
}
|
||||
},
|
||||
'ROOT_URLCONF':'',
|
||||
'STATSD_CLIENT': 'django_statsd.clients.null'
|
||||
}
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(**minimal)
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, HttpResponseForbidden
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.utils import dictconfig
|
||||
from django.utils import unittest
|
||||
|
||||
import mock
|
||||
|
@ -30,6 +45,7 @@ cfg = {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@mock.patch.object(middleware.statsd, 'incr')
|
||||
class TestIncr(TestCase):
|
||||
|
||||
|
@ -131,7 +147,7 @@ class TestRecord(TestCase):
|
|||
self.url = reverse('django_statsd.record')
|
||||
settings.STATSD_RECORD_GUARD = None
|
||||
self.good = {'client': 'boomerang', 'nt_nav_st': 1,
|
||||
'nt_domcomp': 3}
|
||||
'nt_domcomp': 3}
|
||||
self.stick = {'client': 'stick',
|
||||
'window.performance.timing.domComplete': 123,
|
||||
'window.performance.timing.domInteractive': 456,
|
||||
|
|
|
@ -60,7 +60,7 @@ def process_key(start, key, value):
|
|||
@require_http_methods(['GET', 'HEAD'])
|
||||
def _process_boomerang(request):
|
||||
if 'nt_nav_st' not in request.GET:
|
||||
raise ValueError, ('nt_nav_st not in request.GET, make sure boomerang'
|
||||
raise ValueError('nt_nav_st not in request.GET, make sure boomerang'
|
||||
' is made with navigation API timings as per the following'
|
||||
' http://yahoo.github.com/boomerang/doc/howtos/howto-9.html')
|
||||
|
||||
|
@ -115,7 +115,7 @@ def record(request):
|
|||
guard = getattr(settings, 'STATSD_RECORD_GUARD', None)
|
||||
if guard:
|
||||
if not callable(guard):
|
||||
raise ValueError, 'STATSD_RECORD_GUARD must be callable'
|
||||
raise ValueError('STATSD_RECORD_GUARD must be callable')
|
||||
result = guard(request)
|
||||
if result:
|
||||
return result
|
||||
|
|
|
@ -16,6 +16,11 @@ Credits:
|
|||
Changes
|
||||
-------
|
||||
|
||||
0.3.5:
|
||||
|
||||
- fix tests to work standalone
|
||||
- add in waterfall view of timings
|
||||
|
||||
0.3.3:
|
||||
|
||||
- fix setup.py to include loggers etc
|
||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ from setuptools import setup
|
|||
setup(
|
||||
# Because django-statsd was taken, I called this django-statsd-mozilla.
|
||||
name='django-statsd-mozilla',
|
||||
version='0.3.4',
|
||||
version='0.3.5',
|
||||
description='Django interface with statsd',
|
||||
long_description=open('README.rst').read(),
|
||||
author='Andy McKay',
|
||||
|
|
Loading…
Reference in New Issue