-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[middleware] enable subclassing of other middleware implementations, …
…remove POST in django A mixed bag here: - extend the capability of new `get_context_*` functions in Flask, Bottle, and Werkzeug middlewares - Drop `request.POST.dict()` from default instrumentation in django by default - Adds initial test structure for middleware. At best, this tests that the middleware code executes and doesn't crash due to trivial runtime errors, but there's a long way to go here.
- Loading branch information
Showing
10 changed files
with
198 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
from mock import Mock, patch, call, ANY | ||
|
||
from beeline.middleware.bottle import HoneyWSGIMiddleware | ||
|
||
class SimpleWSGITest(unittest.TestCase): | ||
def setUp(self): | ||
self.addCleanup(patch.stopall) | ||
self.m_gbl = patch('beeline.middleware.bottle.beeline').start() | ||
|
||
def test_call_middleware(self): | ||
''' Just call the middleware and ensure that the code runs ''' | ||
mock_app = Mock() | ||
mock_resp = Mock() | ||
mock_trace = Mock() | ||
mock_environ = {} | ||
self.m_gbl.start_trace.return_value = mock_trace | ||
|
||
mw = HoneyWSGIMiddleware(mock_app) | ||
mw({}, mock_resp) | ||
self.m_gbl.start_trace.assert_called_once() | ||
|
||
mock_app.assert_called_once_with(mock_environ, ANY) | ||
|
||
# get the response function passed to the app | ||
resp_func = mock_app.mock_calls[0][1][1] | ||
# call it to make sure it does what we want | ||
# the values here don't really matter | ||
resp_func(1, 2) | ||
|
||
mock_resp.assert_called_once_with(1, 2) | ||
self.m_gbl.finish_trace.assert_called_once_with(mock_trace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
from mock import Mock, patch, call, ANY | ||
|
||
from beeline.middleware.django import HoneyMiddlewareBase | ||
|
||
class SimpleWSGITest(unittest.TestCase): | ||
def setUp(self): | ||
self.addCleanup(patch.stopall) | ||
self.m_gbl = patch('beeline.middleware.django.beeline').start() | ||
|
||
def test_call_middleware(self): | ||
''' Just call the middleware and ensure that the code runs ''' | ||
mock_req = Mock() | ||
mock_resp = Mock() | ||
mock_trace = Mock() | ||
self.m_gbl.start_trace.return_value = mock_trace | ||
|
||
mw = HoneyMiddlewareBase(mock_resp) | ||
resp = mw(mock_req) | ||
self.m_gbl.start_trace.assert_called_once() | ||
|
||
mock_resp.assert_called_once_with(mock_req) | ||
|
||
self.m_gbl.finish_trace.assert_called_once_with(mock_trace) | ||
self.assertEqual(resp, mock_resp.return_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
from mock import Mock, patch, call, ANY | ||
|
||
from beeline.middleware.flask import HoneyWSGIMiddleware | ||
|
||
class SimpleWSGITest(unittest.TestCase): | ||
def setUp(self): | ||
self.addCleanup(patch.stopall) | ||
self.m_gbl = patch('beeline.middleware.flask.beeline').start() | ||
|
||
def test_call_middleware(self): | ||
''' Just call the middleware and ensure that the code runs ''' | ||
mock_app = Mock() | ||
mock_resp = Mock() | ||
mock_trace = Mock() | ||
mock_environ = {} | ||
self.m_gbl.start_trace.return_value = mock_trace | ||
|
||
mw = HoneyWSGIMiddleware(mock_app) | ||
mw({}, mock_resp) | ||
self.m_gbl.start_trace.assert_called_once() | ||
|
||
mock_app.assert_called_once_with(mock_environ, ANY) | ||
|
||
# get the response function passed to the app | ||
resp_func = mock_app.mock_calls[0][1][1] | ||
# call it to make sure it does what we want | ||
# the values here don't really matter | ||
resp_func("200", 2) | ||
|
||
mock_resp.assert_called_once_with("200", 2) | ||
self.m_gbl.finish_trace.assert_called_once_with(mock_trace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
from mock import Mock, patch, call, ANY | ||
|
||
from beeline.middleware.werkzeug import HoneyWSGIMiddleware | ||
|
||
class SimpleWSGITest(unittest.TestCase): | ||
def setUp(self): | ||
self.addCleanup(patch.stopall) | ||
self.m_gbl = patch('beeline.middleware.werkzeug.beeline').start() | ||
|
||
def test_call_middleware(self): | ||
''' Just call the middleware and ensure that the code runs ''' | ||
mock_app = Mock() | ||
mock_resp = Mock() | ||
mock_trace = Mock() | ||
mock_environ = {} | ||
self.m_gbl.start_trace.return_value = mock_trace | ||
|
||
mw = HoneyWSGIMiddleware(mock_app) | ||
mw({}, mock_resp) | ||
self.m_gbl.start_trace.assert_called_once() | ||
|
||
mock_app.assert_called_once_with(mock_environ, ANY) | ||
|
||
# get the response function passed to the app | ||
resp_func = mock_app.mock_calls[0][1][1] | ||
# call it to make sure it does what we want | ||
# the values here don't really matter | ||
resp_func(1, 2) | ||
|
||
mock_resp.assert_called_once_with(1, 2) | ||
self.m_gbl.finish_trace.assert_called_once_with(mock_trace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VERSION = '2.7.0' | ||
VERSION = '2.8.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters