Skip to content

Commit 01dfbb0

Browse files
committed
add more test cases
1 parent ebb7e1d commit 01dfbb0

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flask-zipkin
22

3-
a flask zipkin extesion based on py_zipkin.
3+
a flask zipkin extension based on py_zipkin.
44

55
## Installation
66

@@ -23,7 +23,7 @@ zipkin.init_app(app)
2323

2424
you could gen a header to pass it to other services, the downstream service will recieve this header.
2525

26-
```
26+
```python
2727
@bp.route('/')
2828
def hello():
2929
headers = {}

flask_zipkin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _before_request(self):
9898

9999
span = zipkin.zipkin_span(
100100
service_name=self.app.name,
101-
span_name='{0}.{1}'.format(request.endpoint, request.mehod),
101+
span_name='{0}.{1}'.format(request.endpoint, request.method),
102102
transport_handler=handler,
103103
sample_rate=self._sample_rate,
104104
zipkin_attrs=zipkin_attrs

test_flask_zipkin.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import unittest
55
import mock
66

7-
from flask import Flask
7+
import flask
88
from flask_zipkin import Zipkin
99

1010

@@ -15,27 +15,48 @@ def handle_transport(*kargs, **kwargs):
1515
class FlaskZipkinTestCase(unittest.TestCase):
1616

1717
def setUp(self):
18-
app = Flask(__name__)
18+
app = flask.Flask(__name__)
1919
app.testing = True
2020
app.config['ZIPKIN_DISABLE'] = False
2121
app.config['ZIPKIN_DSN'] = 'whatever'
2222

23+
bp = flask.Blueprint('bp', __name__, url_prefix='/bp')
24+
25+
@app.route('/foo')
26+
def foo():
27+
return 'bar'
28+
29+
@bp.route('/bar')
30+
def bar():
31+
return 'foo'
32+
2333
z = Zipkin()
24-
z.init_app(app)
2534
z._transport_handler = handle_transport
2635

2736
self.z = z
2837
self.app = app
29-
30-
@app.route('/foo')
31-
def foo():
32-
return 'bar'
38+
self.app.register_blueprint(bp)
39+
z.init_app(self.app)
3340

3441
@mock.patch('py_zipkin.zipkin.create_endpoint')
3542
def test_normal_get(self, create_endpoint_mock):
3643
rv = self.app.test_client().get('/foo')
3744
assert rv.status_code == 200
3845

46+
@mock.patch('py_zipkin.zipkin.create_endpoint')
47+
def test_flask_request_context_with_app(self, create_endpoint_mock):
48+
with self.app.test_request_context('/foo'):
49+
self.app.preprocess_request()
50+
assert flask.g._zipkin_span
51+
assert flask.g._zipkin_span.span_name == 'foo.GET'
52+
53+
@mock.patch('py_zipkin.zipkin.create_endpoint')
54+
def test_flask_request_context_with_bp(self, create_endpoint_mock):
55+
with self.app.test_request_context('/bp/bar'):
56+
self.app.preprocess_request()
57+
assert flask.g._zipkin_span
58+
assert flask.g._zipkin_span.span_name == 'bp.bar.GET'
59+
3960

4061
def suite():
4162
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)