Merge pull request #8 from ibnpaul/tornado-6

Add support for Tornado 6, increase test coverage
This commit is contained in:
Andrew Rabert 2019-03-19 21:07:58 -04:00 committed by GitHub
commit 67b4df6e71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 118 additions and 16 deletions

View file

@ -6,7 +6,7 @@ python:
- 3.7 - 3.7
install: install:
- pip install -e . - pip install -e .
- pip install -r test-requirements.txt - pip install -r requires/testing.txt
- pip install tornado - pip install tornado
script: nosetests script: nosetests
after_success: after_success:

View file

@ -1,6 +1,12 @@
Version History Version History
--------------- ---------------
`2.0.1`_ (18-Mar-2019)
~~~~~~~~~~~~~~~~~~~~~~
- Add support for Tornado 6
- Move requirements files to requires/
- Increase test coverage
`2.0.0`_ (26-Nov-2018) `2.0.0`_ (26-Nov-2018)
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
- Drop support for Python 2.7, 3.3, 3.4 - Drop support for Python 2.7, 3.3, 3.4
@ -15,6 +21,7 @@ Version History
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
- Adds ``sprockets.mixins.correlation.HandlerMixin`` - Adds ``sprockets.mixins.correlation.HandlerMixin``
.. _`2.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/2.0.0...2.0.1
.. _`2.0.0`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.2...2.0.0 .. _`2.0.0`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.2...2.0.0
.. _`1.0.2`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.1...1.0.2 .. _`1.0.2`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.1...1.0.2
.. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1 .. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1

View file

@ -1,4 +1,4 @@
Copyright (c) 2015-2018 AWeber Communications Copyright (c) 2015-2019 AWeber Communications
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,

View file

@ -1,5 +0,0 @@
-r requirements.txt
-r test-requirements.txt
flake8
sphinx>=1.2,<2
sphinx-rtd-theme>=0.1,<1.0

View file

@ -1 +0,0 @@
tornado>=4.0,<5.2

7
requires/development.txt Normal file
View file

@ -0,0 +1,7 @@
-r requires/installation.txt
-r requires/testing.txt
-e .
flake8
sphinx>=1.2,<2
sphinx-rtd-theme>=0.1,<1.0

View file

@ -0,0 +1 @@
tornado>=4.3,<7

View file

@ -51,8 +51,8 @@ setuptools.setup(
], ],
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
namespace_packages=['sprockets'], namespace_packages=['sprockets'],
install_requires=read_requirements('requirements.txt'), install_requires=read_requirements('installation.txt'),
tests_require=read_requirements('test-requirements.txt'), tests_require=read_requirements('testing.txt'),
test_suite='nose.collector', test_suite='nose.collector',
zip_safe=True, zip_safe=True,
) )

View file

@ -7,5 +7,5 @@ except ImportError:
raise ImportError raise ImportError
version_info = (2, 0, 0) version_info = (2, 0, 1)
__version__ = '.'.join(str(v) for v in version_info[:3]) __version__ = '.'.join(str(v) for v in version_info[:3])

View file

@ -1,20 +1,28 @@
import uuid import uuid
import unittest import unittest
import unittest.mock
from tornado import testing, web from tornado import testing, web
from sprockets.mixins import correlation from sprockets.mixins import correlation
from sprockets.mixins.correlation.mixins import correlation_id_logger
class CorrelatedRequestHandler(correlation.HandlerMixin, web.RequestHandler): class RequestHandler(web.RequestHandler):
def get(self, status_code): def get(self, status_code):
status_code = int(status_code) status_code = int(status_code)
self.set_status(status_code)
if status_code >= 300: if status_code >= 300:
raise web.HTTPError(status_code) raise web.HTTPError(status_code)
self.write('status {0}'.format(status_code)) self.write('status {0}'.format(status_code))
class CorrelatedRequestHandler(correlation.HandlerMixin, RequestHandler):
pass
class CorrelationMixinTests(testing.AsyncHTTPTestCase): class CorrelationMixinTests(testing.AsyncHTTPTestCase):
def get_app(self): def get_app(self):
@ -35,3 +43,83 @@ class CorrelationMixinTests(testing.AsyncHTTPTestCase):
response = self.fetch('/status/500', response = self.fetch('/status/500',
headers={'Correlation-Id': correlation_id}) headers={'Correlation-Id': correlation_id})
self.assertEqual(response.headers['correlation-id'], correlation_id) self.assertEqual(response.headers['correlation-id'], correlation_id)
class CorrelationIDLoggerTests(testing.AsyncHTTPTestCase):
def get_app(self):
return web.Application([
(r'/status/(?P<status_code>\d+)', CorrelatedRequestHandler),
(r'/status/no-correlation/(?P<status_code>\d+)', RequestHandler),
], log_function=correlation_id_logger)
def setUp(self):
self.patcher = unittest.mock.patch(
'sprockets.mixins.correlation.mixins.log.access_log')
self.access_logger = self.patcher.start()
super().setUp()
def tearDown(self):
self.patcher.stop()
super().tearDown()
def test_lt_400_logs_info(self):
for status in (200, 202):
response = self.fetch('/status/{}'.format(status))
self.access_logger.info.assert_any_call(
"%d %s %.2fms {CID %s}",
status,
unittest.mock.ANY,
unittest.mock.ANY,
response.headers['correlation-id']
)
def test_gte_400_lt_500_logs_warning(self):
for status in (400, 429):
response = self.fetch('/status/{}'.format(status))
self.access_logger.warning.assert_any_call(
"%d %s %.2fms {CID %s}",
status,
unittest.mock.ANY,
unittest.mock.ANY,
response.headers['correlation-id']
)
def test_gte_500_logs_error(self):
for status in (500, 504):
response = self.fetch('/status/{}'.format(status))
self.access_logger.error.assert_any_call(
"%d %s %.2fms {CID %s}",
status,
unittest.mock.ANY,
unittest.mock.ANY,
response.headers['correlation-id']
)
def test_uses_correlation_id_from_header_if_missing_from_handler(self):
correlation_id = uuid.uuid4().hex
self.fetch('/status/no-correlation/200',
headers={'Correlation-Id': correlation_id})
self.access_logger.info.assert_any_call(
"%d %s %.2fms {CID %s}",
200,
unittest.mock.ANY,
unittest.mock.ANY,
correlation_id
)
def test_correlation_id_is_none_if_missing_from_handler_and_header(self):
self.fetch('/status/no-correlation/200')
self.access_logger.info.assert_any_call(
"%d %s %.2fms {CID %s}",
200,
unittest.mock.ANY,
unittest.mock.ANY,
None
)

13
tox.ini
View file

@ -1,20 +1,25 @@
[tox] [tox]
envlist = py35,py36,py37,tornado43,torando51 envlist = py35,py36,py37,tornado43,tornado51,tornado6
toxworkdir = {toxinidir}/build/tox toxworkdir = {toxinidir}/build/tox
skip_missing_intepreters = true skip_missing_intepreters = true
[testenv] [testenv]
deps = deps =
-rtest-requirements.txt -r requires/testing.txt
tornado tornado
commands = {envbindir}/nosetests commands = {envbindir}/nosetests
[testenv:tornado43] [testenv:tornado43]
deps = deps =
-rtest-requirements.txt -r requires/testing.txt
tornado>=4.3,<4.4 tornado>=4.3,<4.4
[testenv:tornado51] [testenv:tornado51]
deps = deps =
-rtest-requirements.txt -r requires/testing.txt
tornado>=5.1,<5.2 tornado>=5.1,<5.2
[testenv:tornado6]
deps =
-r requires/testing.txt
tornado>=6,<7