@@ -20,33 +20,49 @@ class TestNoggin(TestCase):
20
20
def setUp (self ):
21
21
self .app = noggin .Noggin ()
22
22
23
- def test_create_app (self , mock_recv , mock_send ):
24
- assert self .app
25
-
26
23
def test_route_simple (self , mock_recv , mock_send ):
24
+
25
+ '''Does a simple route work as expected?'''
26
+
27
27
self .app .route ('/path1' )(MagicMock ())
28
28
handler , match = self .app .match ('/path1' )
29
29
assert handler
30
30
31
31
def test_route_params_1 (self , mock_recv , mock_send ):
32
+
33
+ '''Do routes with match groups work as expected?'''
34
+
32
35
self .app .route ('/path2/([^/]+)' )(MagicMock ())
33
36
handler , match = self .app .match ('/path2/foo' )
34
37
assert handler
35
38
assert match .group (1 ) == 'foo'
36
39
37
40
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
+
38
46
self .app .route ('/path2/([^/]+)' )(MagicMock ())
39
47
handler , match = self .app .match ('/path2/foo/bar' )
40
48
assert handler is None
41
49
42
50
def test_send_response (self , mock_recv , mock_send ):
51
+
52
+ '''Does calling send_response generate the expected
53
+ content?'''
54
+
43
55
sock = MagicMock ()
44
56
self .app .send_response (sock , 200 , 'Okay' , 'This is a test' )
45
57
assert sock .write .called
46
58
assert sock .write .call_args_list [0 ][0 ][0 ] == b'HTTP/1.1 200 Okay\r \n '
47
59
assert sock .write .call_args_list [- 1 ][0 ][0 ] == b'This is a test'
48
60
49
61
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
+
50
66
mock_recv .side_effect = (bytes ([b ]) for b in
51
67
b'GET /\r \n \r \n ' )
52
68
client = noggin .compat .socket .mpsocket ()
@@ -57,6 +73,10 @@ def test_request_404(self, mock_recv, mock_send):
57
73
b'HTTP/1.1 404 Not Found\r \n ' )
58
74
59
75
def test_request_200 (self , mock_recv , mock_send ):
76
+
77
+ '''Can we successfully handle a request for an existing
78
+ route?'''
79
+
60
80
@self .app .route ('/' )
61
81
def handler (req ):
62
82
return 'This is a test'
@@ -91,6 +111,9 @@ def handler(req):
91
111
b'Content-type: text/html\r \n ' )
92
112
93
113
def test_read_simple (self , mock_recv , mock_send ):
114
+
115
+ '''Can we correctly read the body of a request?'''
116
+
94
117
@self .app .route ('/' , methods = ['PUT' ])
95
118
def handler (req ):
96
119
return req .content
@@ -111,6 +134,10 @@ def handler(req):
111
134
b'This is a test' )
112
135
113
136
def test_read_chunked (self , mock_recv , mock_send ):
137
+
138
+ '''Can we correctly read a request using
139
+ Transfer-encoding: chunked?'''
140
+
114
141
@self .app .route ('/' , methods = ['PUT' ])
115
142
def handler (req ):
116
143
return req .content
0 commit comments