|
7 | 7 | from pytest import raises
|
8 | 8 |
|
9 | 9 | import aspen
|
10 |
| -from aspen import Response |
| 10 | +from aspen import dispatcher, Response |
11 | 11 |
|
12 | 12 |
|
13 | 13 | # Helpers
|
@@ -43,6 +43,29 @@ def assert_body(harness, uripath, expected_body):
|
43 | 43 | [-----] text/html
|
44 | 44 | <h1>Greetings, Program!</h1>"""
|
45 | 45 |
|
| 46 | + |
| 47 | +# dispatcher.dispatch |
| 48 | +# =================== |
| 49 | + |
| 50 | +def test_dispatcher_returns_a_result(harness): |
| 51 | + request = harness.make_request('Greetings, program!', 'index.html') |
| 52 | + result = dispatcher.dispatch(harness.client.website, request) |
| 53 | + assert result.status == dispatcher.DispatchStatus.okay |
| 54 | + assert result.match == os.path.join(harness.fs.www.root, 'index.html') |
| 55 | + assert result.wildcards == {} |
| 56 | + assert result.detail == 'Found.' |
| 57 | + |
| 58 | +def test_dispatcher_returns_a_result_for_autoindex(harness): |
| 59 | + request = harness.make_request('Greetings, program!', 'index.html') |
| 60 | + os.remove(request.fs) |
| 61 | + harness.client.website.list_directories = True |
| 62 | + result = dispatcher.dispatch(harness.client.website, request) |
| 63 | + assert result.status == dispatcher.DispatchStatus.okay |
| 64 | + assert result.match == os.path.join(harness.fs.www.root, '') |
| 65 | + assert result.wildcards == {} |
| 66 | + assert result.detail == 'Found.' |
| 67 | + |
| 68 | + |
46 | 69 | # Indices
|
47 | 70 | # =======
|
48 | 71 |
|
@@ -462,4 +485,3 @@ def test_dont_serve_hidden_files(harness):
|
462 | 485 | def test_dont_serve_spt_file_source(harness):
|
463 | 486 | harness.fs.www.mk(('foo.html.spt', "Greetings, program!"),)
|
464 | 487 | assert_raises_404(harness, '/foo.html.spt')
|
465 |
| - |
|
0 commit comments