def test_virtual_path_docs_6(): mk(('%year.int/index.html', "Tonight we're going to party like it's {{ request.path['year'] }}!")) response = handle('/1999/') expected = "Tonight we're going to party like it's 1999!" actual = response.body assert actual == expected, actual
def test_virtual_path_docs_4(): mk( ('%name/index.html', "Greetings, {{ request.path['name'] }}!") , ('%name/%cheese.txt', "{{ request.path['name'].title() }} likes {{ request.path['cheese'] }} cheese.") ) response = handle('/chad/cheddar.txt/') expected = 404 actual = response.code assert actual == expected, actual
def test_virtual_path_docs_3(): mk( ('%name/index.html', "^L\nGreetings, {{ request.path['name'] }}!") , ('%name/%cheese.txt', "^L\r\n{{ request.path['name'].title() }} likes {{ request.path['cheese'] }} cheese.") ) response = handle('/chad/cheddar.txt') expected = "Chad likes cheddar cheese." actual = response.body assert actual == expected, actual
def test_simplates_can_import_from_dot_aspen(): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html', "import fooGreetings, {{ foo.bar }}!") ) expected = "Greetings, baz!" actual = handle().body assert actual == expected, actual
def test_virtual_path_docs_6(): mk( ( '%year.int/index.html' , "Tonight we're going to party like it's {{ request.path['year'] }}!" ) ) response = handle('/1999/') expected = "Tonight we're going to party like it's 1999!" actual = response.body assert actual == expected, actual
def test_virtual_path_docs_4(): mk(('%name/index.html', "Greetings, {{ request.path['name'] }}!"), ('%name/%cheese.txt', "{{ request.path['name'].title() }} likes {{ request.path['cheese'] }} cheese." )) response = handle('/chad/cheddar.txt/') expected = 404 actual = response.code assert actual == expected, actual
def test_normal_response_is_returned(): mk(('index.html', "Greetings, program!")) expected = '\r\n'.join("""\ HTTP/1.1 Content-Type: text/html Greetings, program! """.splitlines()) actual = handle()._to_http('1.1') assert actual == expected, actual
def test_virtual_path_docs_5(): mk( ('%name/index.html', "Greetings, {{ request.path['name'] }}!") , ('%name/%cheese.txt', "{{ request.path['name'].title() }} likes {{ request.path['cheese'] }} cheese.") , ( '%year.int/index.html' , "Tonight we're going to party like it's {{ request.path['year'] }}!" ) ) response = handle('/1999/') expected = "Greetings, 1999!" actual = response.body assert actual == expected, actual
def test_virtual_path_docs_5(): mk(('%name/index.html', "Greetings, {{ request.path['name'] }}!"), ('%name/%cheese.txt', "{{ request.path['name'].title() }} likes {{ request.path['cheese'] }} cheese." ), ('%year.int/index.html', "Tonight we're going to party like it's {{ request.path['year'] }}!")) response = handle('/1999/') expected = "Greetings, 1999!" actual = response.body assert actual == expected, actual
def test_virtual_path_docs_2(): mk(('%name/index.html', "Greetings, {{ request.path['name'] }}!")) response = handle('/python/') expected = "Greetings, python!" actual = response.body assert actual == expected, actual
def test_autoindex_response_is_returned(): mk(('.aspen/aspen.conf', '[aspen]\nlist_directories: 1') , ('README', "Greetings, program!")) expected = True actual = 'README' in handle().body assert actual == expected, actual
def test_autoindex_response_is_404_by_default(): mk(('README', "Greetings, program!")) expected = 404 actual = handle().code assert actual == expected, actual
def test_normal_response_is_returned(): mk(('index.html', "Greetings, program!")) expected = '\r\n'.join("""\ HTTP/1.1 Content-Length: 19 Content-Type: text/html; charset=UTF-8 Greetings, program! """.splitlines()) actual = handle()._to_http('1.1') assert actual == expected, actual def test_fatal_error_response_is_returned(): mk(('index.html', "raise heck")) expected = 500 actual = handle().code assert actual == expected, actual def test_nice_error_response_is_returned(): mk(('index.html', "from aspen import Responseraise Response(500)")) expected = 500 actual = handle().code assert actual == expected, actual def test_nice_error_response_is_returned_for_404(): mk(('index.html', "from aspen import Responseraise Response(404)")) expected = 404 actual = handle().code assert actual == expected, actual def test_autoindex_response_is_404_by_default():