Skip to content

Commit a29f4ea

Browse files
committed
docstrings for tests
1 parent 45b7995 commit a29f4ea

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/test_noggin.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,49 @@ class TestNoggin(TestCase):
2020
def setUp(self):
2121
self.app = noggin.Noggin()
2222

23-
def test_create_app(self, mock_recv, mock_send):
24-
assert self.app
25-
2623
def test_route_simple(self, mock_recv, mock_send):
24+
25+
'''Does a simple route work as expected?'''
26+
2727
self.app.route('/path1')(MagicMock())
2828
handler, match = self.app.match('/path1')
2929
assert handler
3030

3131
def test_route_params_1(self, mock_recv, mock_send):
32+
33+
'''Do routes with match groups work as expected?'''
34+
3235
self.app.route('/path2/([^/]+)')(MagicMock())
3336
handler, match = self.app.match('/path2/foo')
3437
assert handler
3538
assert match.group(1) == 'foo'
3639

3740
def test_route_params_2(self, mock_recv, mock_send):
41+
42+
'''Are routes correctly anchored so that we don't get
43+
erroneous matches when the initial partial of our request uri
44+
matches an existing route?'''
45+
3846
self.app.route('/path2/([^/]+)')(MagicMock())
3947
handler, match = self.app.match('/path2/foo/bar')
4048
assert handler is None
4149

4250
def test_send_response(self, mock_recv, mock_send):
51+
52+
'''Does calling send_response generate the expected
53+
content?'''
54+
4355
sock = MagicMock()
4456
self.app.send_response(sock, 200, 'Okay', 'This is a test')
4557
assert sock.write.called
4658
assert sock.write.call_args_list[0][0][0] == b'HTTP/1.1 200 Okay\r\n'
4759
assert sock.write.call_args_list[-1][0][0] == b'This is a test'
4860

4961
def test_request_404(self, mock_recv, mock_send):
62+
63+
'''If we make a request for a route that doesn't exist, do we
64+
get a 404 error as expected?'''
65+
5066
mock_recv.side_effect = (bytes([b]) for b in
5167
b'GET /\r\n\r\n')
5268
client = noggin.compat.socket.mpsocket()
@@ -57,6 +73,10 @@ def test_request_404(self, mock_recv, mock_send):
5773
b'HTTP/1.1 404 Not Found\r\n')
5874

5975
def test_request_200(self, mock_recv, mock_send):
76+
77+
'''Can we successfully handle a request for an existing
78+
route?'''
79+
6080
@self.app.route('/')
6181
def handler(req):
6282
return 'This is a test'
@@ -91,6 +111,9 @@ def handler(req):
91111
b'Content-type: text/html\r\n')
92112

93113
def test_read_simple(self, mock_recv, mock_send):
114+
115+
'''Can we correctly read the body of a request?'''
116+
94117
@self.app.route('/', methods=['PUT'])
95118
def handler(req):
96119
return req.content
@@ -111,6 +134,10 @@ def handler(req):
111134
b'This is a test')
112135

113136
def test_read_chunked(self, mock_recv, mock_send):
137+
138+
'''Can we correctly read a request using
139+
Transfer-encoding: chunked?'''
140+
114141
@self.app.route('/', methods=['PUT'])
115142
def handler(req):
116143
return req.content

0 commit comments

Comments
 (0)