-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
65 lines (49 loc) · 1.85 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import flask
import mock
import unittest
import flask_statsd
class FlaskStatsdTestCase(unittest.TestCase):
def setUp(self):
app = flask.Flask("myapp")
statsd = flask_statsd.Statsd(app)
self.test_client = app.test_client()
@app.route('/')
def index():
statsd.incr("test_incr")
with statsd.timer("test_timer"):
pass
return "Test", 200
@app.route('/fail')
def fail():
return "FAIL", 500
def test_successful_response(self):
with mock.patch('flask_statsd.Statsd._client') as mock_client:
self.test_client.get("/")
mock_client.incr.call_args_list == [
mock.call(count=1, stat='myapp.test_incr', rate=1),
mock.call(count=1, stat='myapp.request_handlers.index.200', rate=1)
]
mock_client.timing.assert_any_call(
stat = 'myapp.request_handlers.index.200',
delta = mock.ANY,
rate = mock.ANY)
mock_client.timer.assert_any_call(
stat = 'myapp.test_timer',
rate = mock.ANY)
mock_client.timing.assert_any_call(
stat = 'myapp.request_handlers.overall.200',
delta = mock.ANY,
rate = mock.ANY)
def test_failed_response(self):
with mock.patch('flask_statsd.Statsd._client') as mock_client:
self.test_client.get("/fail")
mock_client.incr.assert_any_call(
stat = 'myapp.request_handlers.fail.500',
count = 1,
rate = mock.ANY)
mock_client.timing.assert_any_call(
stat = 'myapp.request_handlers.fail.500',
delta = mock.ANY,
rate = mock.ANY)
if __name__ == '__main__':
unittest.main()