def test_virtual_path_docs_3(mk): mk(('%name/index.html.spt', GREETINGS_NAME_SPT), ('%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT)) response = handle('/chad/cheddar.txt') expected = "Chad likes cheddar cheese." actual = response.body assert actual == expected
def test_redirect_has_only_location(mk): mk(('index.html.spt', "from aspen import Response\n[---]\nrequest.redirect('http://elsewhere', code=304)\n[---]\n")) actual = handle() assert actual.code == 304 headers = actual.headers assert len(headers) == 1 assert headers.get('Location') is not None
def test_virtual_path_docs_6(): mk(('%year.int/index.html', "^L\nTonight we're going to party like it's {{ 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_unavailable_knob_works(): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html', "import fooGreetings, {{ foo.bar }}!") ) actual = handle('/', '--unavailable=1').code assert actual == 503, actual
def test_virtual_path_docs_4(mk): mk(('%name/index.html.spt', GREETINGS_NAME_SPT), ('%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT)) response = handle('/chad/cheddar.txt/') expected = 404 actual = response.code assert actual == expected
def test_virtual_path_docs_1(): mk(('%name/index.html.spt', GREETINGS_NAME_SPT)) expected = "Greetings, aspen!" #import pdb; pdb.set_trace() response = handle('/aspen/') actual = response.body assert actual == expected, repr(actual) + " from " + repr(response)
def test_virtual_path_docs_5(mk): mk(('%name/index.html.spt', GREETINGS_NAME_SPT), ('%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT), ('%year.int/index.html.spt', PARTY_LIKE_YEAR_SPT)) response = handle('/1999/') expected = "Greetings, 1999!" actual = response.body assert actual == expected
def test_virtual_path_docs_3(): mk( ('%name/index.html', "^L\nGreetings, {{ request.path['name'] }}!") , ('%name/%cheese.txt', "^L\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_resources_can_import_from_dot_aspen(): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html', "import fooGreetings, {{ foo.bar }}!") ) expected = "Greetings, baz!" actual = handle('/', '--project_root=.aspen').body assert actual == expected, actual
def test_virtual_path_docs_4(): mk( ('%name/index.html', "^L\nGreetings, {{ path['name'] }}!") , ('%name/%cheese.txt', "{{ path['name'].title() }} likes {{ path['cheese'] }} cheese.") ) response = handle('/chad/cheddar.txt/') expected = 404 actual = response.code assert actual == expected, actual
def test_virtual_path_docs_4(): mk(('%name/index.html', "^L\nGreetings, {{ path['name'] }}!"), ('%name/%cheese.txt', "{{ path['name'].title() }} likes {{ 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.spt', GREETINGS_NAME_SPT), ( '%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT) ) response = handle('/chad/cheddar.txt') expected = "Chad likes cheddar cheese." actual = response.body assert actual == expected, actual
def test_virtual_path_docs_4(): mk( ( '%name/index.html.spt', GREETINGS_NAME_SPT), ( '%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT) ) response = handle('/chad/cheddar.txt/') expected = 404 actual = response.code assert actual == expected, actual
def test_unavailable_knob_sets_retry_after_on_website(): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html', "import fooGreetings, {{ foo.bar }}!") ) actual = handle('/', '--unavailable=10').headers['Retry-After'] expected = datetime.datetime.utcnow().strftime('%a, %d %b %Y') assert actual.startswith(expected), actual assert actual.endswith(' +0000'), actual
def test_path_part_params_are_available(mk): mk(('/foo/index.html.spt', """ if 'b' in path.parts[0].params: a = path.parts[0].params['a'] [---] %(a)s""")) expected = "3" actual = handle('/foo;a=1;b;a=3/').body assert actual == expected
def test_virtual_path_docs_6(): mk( ( '%year.int/index.html' , "^L\nTonight we're going to party like it's {{ 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_path_part_params_are_available(): mk(('/foo/index.html.spt', """ if 'b' in path.parts[0].params: a = path.parts[0].params['a'] [---] %(a)s""")) expected = "3" actual = handle('/foo;a=1;b;a=3/').body assert actual == expected, actual + " isn't " + expected
def test_virtual_path_docs_5(): mk( ( '%name/index.html.spt', GREETINGS_NAME_SPT), ( '%name/%cheese.txt.spt', NAME_LIKES_CHEESE_SPT), ( '%year.int/index.html.spt', PARTY_LIKE_YEAR_SPT) ) response = handle('/1999/') expected = "Greetings, 1999!" actual = response.body assert actual == expected, actual
def test_resources_can_import_from_dot_aspen(mk): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html.spt', "from foo import bar\n[---]\nGreetings, %(bar)s!") ) expected = "Greetings, baz!" project_root = os.path.join(FSFIX, '.aspen') actual = handle('/', '--project_root='+project_root).body assert actual == expected
def test_resources_can_import_from_dot_aspen(): mk( '.aspen' , ('.aspen/foo.py', 'bar = "baz"') , ('index.html.spt', "from foo import bar\n[---]\nGreetings, %(bar)s!") ) expected = "Greetings, baz!" project_root = os.path.join(FSFIX, '.aspen') actual = handle('/', '--project_root='+project_root).body assert actual == expected, actual
def test_virtual_path_docs_5(): mk( ("%name/index.html", "^L\nGreetings, {{ path['name'] }}!"), ("%name/%cheese.txt", "{{ path['name'].title() }} likes {{ path['cheese'] }} cheese."), ("%year.int/index.html", "^L\nTonight we're going to party like it's {{ path['year'] }}!"), ) response = handle("/1999/") expected = "Greetings, 1999!" actual = response.body assert actual == expected, actual
def test_normal_response_is_returned(mk): 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
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', "^L\nGreetings, {{ path['name'] }}!"), ('%name/%cheese.txt', "{{ path['name'].title() }} likes {{ path['cheese'] }} cheese."), ('%year.int/index.html', "^L\nTonight we're going to party like it's {{ path['year'] }}!")) response = handle('/1999/') expected = "Greetings, 1999!" actual = response.body assert actual == expected, actual
def test_fatal_error_response_is_returned(mk): mk(('index.html.spt', "raise heck\n[---]\n")) expected = 500 actual = handle().code assert actual == expected
def test_negotiated_inside_virtual_path(): mk(('/%foo/bar', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE )) response = handle('/program/bar.txt') expected = "Greetings, program!" actual = response.body assert actual == expected, actual
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(): mk(('README', "Greetings, program!")) expected = 404 actual = handle().code assert actual == expected, actual def test_autoindex_response_is_returned():
def test_virtual_path_docs_6(mk): mk(('%year.int/index.html.spt', PARTY_LIKE_YEAR_SPT)) response = handle('/1999/') expected = "Tonight we're going to party like it's 1999!" actual = response.body assert actual == expected
def test_indirect_negotiation_sets_media_type_to_secondary(): mk(('/foo', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.txt') expected = "Greetings, program!" actual = response.body assert actual == expected, actual
def test_autoindex_response_is_404_by_default(mk): mk(('README', "Greetings, program!")) expected = 404 actual = handle().code assert actual == expected
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_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():
def test_indirect_negotiation_with_unsupported_media_type_is_404(mk): mk(('/foo.spt', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.jpg') actual = response.code assert actual == 404
def test_autoindex_response_is_404_by_default(): mk(('README', "Greetings, program!")) expected = 404 actual = handle().code 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_autoindex_response_is_returned(): mk(('README', "Greetings, program!")) expected = True actual = 'README' in handle('/', '--list_directories=TrUe').body assert actual == expected, actual
def test_nice_error_response_is_returned_for_404(mk): mk(('index.html.spt', "from aspen import Response\n[---]\nraise Response(404)\n[---]\n")) expected = 404 actual = handle().code assert actual == expected
def test_virtual_path_docs_6(): mk( ( '%year.int/index.html.spt', PARTY_LIKE_YEAR_SPT)) response = handle('/1999/') expected = "Tonight we're going to party like it's 1999!" actual = response.body assert actual == expected, actual
def test_negotiated_inside_virtual_path_with_startypes_present(): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE )) response = handle('/program/bar.html') actual = response.body assert '<h1>' in 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_negotiated_inside_virtual_path_with_startype_fallback(): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE )) response = handle('/program/bar.jpg') expected = "Unknown request type, program!" actual = response.body.strip() assert actual == expected, "got " + repr(actual) + " instead of " + repr(expected)
def test_negotiated_inside_virtual_path_with_startypes_present(mk): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE)) response = handle('/program/bar.html') actual = response.body assert '<h1>' in actual
def test_autoindex_response_is_returned(mk): mk(('README', "Greetings, program!")) body = handle('/', '--list_directories=TrUe').body assert 'README' in body
def test_negotiated_inside_virtual_path_with_startype_partial_match(mk): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE)) response = handle('/program/bar.txt') expected = "Greetings, program!" actual = response.body assert actual == expected
def test_negotiated_inside_virtual_path(): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE )) response = handle('/program/bar.txt') expected = "Greetings, program!" actual = response.body assert actual == expected, actual
def test_negotiated_inside_virtual_path_with_startype_fallback(mk): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE)) response = handle('/program/bar.jpg') expected = "Unknown request type, program!" actual = response.body.strip() assert actual == expected
def test_negotiated_inside_virtual_path_with_startype_partial_match(): mk(('/%foo/bar.spt', INDIRECTLY_NEGOTIATED_VIRTUAL_RESOURCE_STARTYPE )) response = handle('/program/bar.txt') expected = "Greetings, program!" actual = response.body assert actual == expected, "got " + repr(actual) + " instead of " + repr(expected)
def test_autoindex_response_is_returned(): mk(('README', "Greetings, program!")) body = handle('/', '--list_directories=TrUe').body assert 'README' in body, body
def test_indirect_negotiation_sets_media_type(): mk(('/foo', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.html') expected = "<h1>Greetings, program!</h1>\n" actual = response.body assert actual == expected, actual
def test_virtual_path_docs_2(): mk(('%name/index.html.spt', GREETINGS_NAME_SPT)) expected = "Greetings, python!" response = handle('/python/') actual = response.body assert actual == expected, actual
def test_indirect_negotiation_with_unsupported_media_type_is_404(): mk(('/foo', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.jpg') actual = response.code assert actual == 404, actual
def test_virtual_path_docs_2(mk): mk(('%name/index.html.spt', GREETINGS_NAME_SPT)) expected = "Greetings, python!" response = handle('/python/') actual = response.body assert actual == expected
def test_virtual_path_docs_2(): mk(('%name/index.html', "^L\nGreetings, {{ path['name'] }}!")) response = handle('/python/') expected = "Greetings, python!" actual = response.body assert actual == expected, actual
def test_indirect_negotiation_sets_media_type(mk): mk(('/foo.spt', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.html') expected = "<h1>Greetings, program!</h1>\n" actual = response.body assert actual == expected
def test_indirect_negotiation_sets_media_type_to_secondary(mk): mk(('/foo.spt', INDIRECTLY_NEGOTIATED_RESOURCE)) response = handle('/foo.txt') expected = "Greetings, program!" actual = response.body assert actual == expected