def test_layering(): mk(('first.conf', """ random:choice random:sample random:randint """), ('second.conf', """ random:random random:gauss random:choice random:shuffle """) ) expected = [ [] , [random.choice, random.sample, random.random, random.gauss] , [random.randint, random.choice, random.shuffle] , [] , [] , [] ] actual = load('first.conf', 'second.conf') assert actual == expected, actual
def test_tornado_loader_shim_resolves_path_from_absolute_nested_parent_path(): mk(("base.html", "Resolved."), "www") make_renderer = tornado_factory_factory(["--project_root", FSFIX]) path = os.path.abspath(os.path.join(FSFIX, convert_path("www/index.html"))) render = make_renderer(path, "{% extends base.html %}") actual = render({}) assert actual == "Resolved.", actual
def test_can_override_default_renderer_entirely(): mk(('.aspen/configure-aspen.py', OVERRIDE_SIMPLATE), ('index.spt', NEGOTIATED_RESOURCE)) request = StubRequest.from_fs('index.spt') request.headers['Accept'] = 'text/plain' actual = get_response(request, Response()).body assert actual == "glubber", actual
def test_aspen_favicon_doesnt_get_clobbered_by_virtual_path(): mk('%value.spt') request = StubRequest.from_fs('/favicon.ico') dispatcher.dispatch(request) expected = {} actual = request.line.uri.path assert actual == expected, actual
def test_tornado_caches_by_default(): mk(("base.html", "{% block foo %}{% end %} Blam.")) make_renderer = tornado_factory_factory(["--project_root", FSFIX]) render = make_renderer("<string>", "{% extends base.html %}" "{% block foo %}Some bytes!{% end %}") open(fix("base.html"), "w+").write("{% block foo %}{% end %} Blar.") actual = render({}) assert actual == "Some bytes! Blam.", actual
def test_get_response_doesnt_reset_content_type_when_not_negotiating(): mk(('index', NEGOTIATED_RESOURCE)) request = StubRequest.from_fs('index') response = Response() response.headers['Content-Type'] = 'never/mind' actual = get_response(request, response).headers['Content-Type'] assert actual == "never/mind", actual
def test_trailing_slash_redirects_trailing_slash_to_the_right_place(): mk("foo") response = assert_raises(Response, check_trailing_slash, "/foo") expected = "/foo/" actual = response.headers["Location"] assert actual == expected, actual
def test_alternate_index_is_found(): mk( ('.aspen/aspen.conf', '[aspen]\ndefault_filenames = default.html') , ('default.html', "Greetings, program!") ) expected = fix('default.html') actual = check_index('/').fs assert actual == expected, actual
def test_trailing_slash_redirects_trailing_slash_to_the_right_place(): mk('foo') response = assert_raises(Response, check_trailing_slash, '/foo') expected = '/foo/' actual = response.headers['Location'] assert actual == expected, actual
def test_aspen_favicon_doesnt_get_clobbered_by_virtual_path(): mk('%value') request = StubRequest.from_fs('/favicon.ico') gauntlet.run_through(request, gauntlet.not_found) expected = {} actual = request.line.uri.path assert actual == expected, actual
def test_file_matches_other_extension(): mk( ('%value.json', '{"Greetings,": "program!"}') , ('%value.txt', "Greetings, program!") ) expected = "%value.txt" actual = os.path.basename(check_virtual_paths('/baz.txt').fs) assert actual == expected, actual
def test_file_matches_in_face_of_dir(): mk( ('%page/index.html', 'Nothing to see here.') , ('%value.txt', "Greetings, program!") ) expected = {'value': [u'baz']} actual = check_virtual_paths('/baz.txt').line.uri.path assert actual == expected, actual
def test_alternate_index_is_found(): mk( ('.aspen/configure-aspen.py', 'website.indices += ["default.html"]') , ('default.html', "Greetings, program!") ) expected = fix('default.html') actual = check_index('/').fs assert actual == expected, actual
def test_file_with_no_extension_matches(): mk( ('%value', '{"Greetings,": "program!"}') , ('value', '{"Greetings,": "program!"}') ) expected = {'value': [u'baz']} actual = check_virtual_paths('/baz').line.uri.path assert actual == expected, actual
def test_configure_aspen_py_setting_override_works_too(): mk( ('.aspen/configure-aspen.py', 'website.indices = ["default.html"]') , ('index.html', "Greetings, program!") ) expected = fix('') actual = check_index('/').fs assert actual == expected, actual
def test_virtual_path__and_indirect_neg_file_not_dir(): mk( ('%foo/bar.html', "Greetings from bar!") , ('%baz.spt', "Greetings from baz!") ) expected = fix('%baz.spt') actual = check('/bal.html').fs assert actual == expected, actual
def test_trailing_slash_redirects_trailing_slash(): mk('foo') response = assert_raises(Response, check_trailing_slash, '/foo') expected = 301 actual = response.code assert actual == expected, actual
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_matches_the_first(): mk( ('%first/foo.html', "Greetings, program!") , ('%second/foo.html', "WWAAAAAAAAAAAA!!!!!!!!") ) expected = fix('%first/foo.html') actual = check_virtual_paths('/1999/foo.html').fs assert actual == expected, actual
def test_virtual_path_file_not_dir(): mk( ('%foo/bar.html', "Greetings from bar!") , ('%baz.html', "Greetings from baz!") ) actual = check_virtual_paths('/bal.html').fs expected = fix('%baz.html') assert actual == expected, actual
def test_indirect_negotiation_really_prefers_rendered(): mk( ('foo.html', "Greetings, program!") , ('foo.', "blah blah blah") ) expected = fix('foo.html') actual = check_indirect_negotiation('foo.html').fs assert actual == expected, actual
def test_index_conf_setting_overrides_and_doesnt_extend(): mk( ('.aspen/aspen.conf', '[aspen]\ndefault_filenames = default.html') , ('index.html', "Greetings, program!") ) expected = fix('') actual = check_index('/').fs assert actual == expected, actual
def test_get_response_406_gives_list_of_acceptable_types(): mk(('index', NEGOTIATED_RESOURCE)) request = StubRequest.from_fs('index') request.headers['Accept'] = 'cheese/head' actual = assert_raises(Response, get_response, request, Response()).body expected ="The following media types are available: text/plain, text/html." assert actual == expected, actual
def test_tornado_obeys_changes_reload_for_meta(): mk(("base.html", "{% block foo %}{% end %} Blam.")) make_renderer = tornado_factory_factory(["--project_root", FSFIX, "--changes_reload=yes"]) open(fix("base.html"), "w+").write("{% block foo %}{% end %} Blar.") render = make_renderer("<string>", "{% extends base.html %}" "{% block foo %}Some bytes!{% end %}") actual = render({}) assert actual == "Some bytes! Blar.", actual
def test_all_six(): mk(('foo.conf', """ random:choice random:sample random:randint random:random random:gauss random:choice random:shuffle Ignored! """) ) expected = [ [random.choice, random.sample] , [random.randint] , [random.random, random.gauss] , [random.choice, random.shuffle] , [] , [] ] actual = load('foo.conf') assert actual == expected, actual
def test_configure_aspen_py_setting_strips_commas(): mk( ( '.aspen/configure-aspen.py' , 'website.indices = ["index.html", "default.html"]') , ('default.html', "Greetings, program!") ) expected = fix('default.html') actual = check_index('/').fs 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_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_configure_aspen_py_setting_takes_second_if_first_is_missing(): mk( ( '.aspen/configure-aspen.py' , 'website.indices = ["index.html", "default.html"]') , ('default.html', "Greetings, program!") ) expected = fix('default.html') actual = check_index('/').fs assert actual == expected, actual
def test_virtual_path_raises_404_on_direct_access(): mk() response = assert_raises(Response, check_virtual_paths, '/%name/foo.html') expected = 404 actual = response.code assert actual == expected, actual
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_configure_aspen_py_setting_works_with_only_comma(): mk(('default.html', "Greetings, program!")) expected = fix('default.html') actual = check_index('/', '--indices', 'index.html, ,default.html').fs assert actual == expected, actual
def test_virtual_path_can_passthrough(): mk(('foo.html', "Greetings, program!")) expected = fix('foo.html') actual = check_virtual_paths('foo.html').fs assert actual == expected, actual
def test_virtual_path_is_virtual(): mk(('%bar/foo.html', "Greetings, program!")) expected = fix('%bar/foo.html') actual = check_virtual_paths('/blah/foo.html').fs assert actual == expected, actual
def test_virtual_path_typecasts_to_int(): mk(('%year.int/foo.html', "Greetings, program!")) expected = {'year': [1999]} actual = check_virtual_paths('/1999/foo.html').line.uri.path assert actual == expected, actual
def test_virtual_path_file_key_val_not_cast(): mk(('foo/%bar.html', "Greetings, program!")) expected = {'bar': [u'537']} actual = check_virtual_paths('/foo/537.html').line.uri.path assert actual == expected, actual
def test_virtual_path_file_key_val_cast(): mk(('foo/%bar.int.html', "Greetings, program!")) expected = {'bar': [537]} actual = check_virtual_paths('/foo/537.html').line.uri.path assert actual == expected, repr(actual) + " isn't " + repr(expected)
def test_virtual_path__and_indirect_neg_file_not_dir(): mk(('%foo/bar.html', "Greetings from bar!"), ('%baz', "Greetings from baz!")) actual = check_virtual_paths('/bal.html').fs expected = fix('%baz') assert actual == expected, actual
def test_virtual_path_and_indirect_neg_ext(): mk(('%foo/bar', "Greetings program!")) actual = check_virtual_paths('/greet/bar.html').fs expected = fix('%foo/bar') assert actual == expected, actual
def test_trailing_slash_passes_files_through(): mk(('foo/index.html', "Greetings, program!")) expected = fix('/foo/537.html') actual = check_trailing_slash('/foo/537.html').fs assert actual == expected, actual
def test_trailing_slash_passes_dirs_with_slash_through(): mk('foo') expected = fix('/foo/') actual = check_trailing_slash('/foo/').fs assert actual == expected, actual
def test_indirect_negotiation_modifies_one_dot(): mk(('foo', "Greetings, program!")) expected = fix('foo') actual = check_indirect_negotiation('foo.html').fs assert actual == expected, actual
def test_virtual_path_raises_on_direct_access(): mk() assert_raises(Response, check_virtual_paths, '/%name/foo.html')
def test_virtual_path_raises_on_bad_typecast(): mk(('%year.int/foo.html', "Greetings, program!")) assert_raises(Response, check_virtual_paths, '/I am not a year./foo.html')
def test_virtual_path_file_only_last_part____no_really(): mk(('foo/%bar.html', "Greetings, program!")) expected = fix('foo/blah.html/') actual = check_virtual_paths('/foo/blah.html/').fs assert actual == expected, actual
def test_virtual_path_sets_request_path(): mk(('%bar/foo.html', "Greetings, program!")) expected = {'bar': [u'blah']} actual = check_virtual_paths('/blah/foo.html').line.uri.path assert actual == expected, actual
def test_virtual_path_file(): mk(('foo/%bar.html', "Greetings, program!")) expected = fix('foo/%bar.html') actual = check_virtual_paths('/foo/blah.html').fs assert actual == expected, actual
def test_unfound_virtual_path_passes_through(): mk(('%bar/foo.html', "Greetings, program!")) request = check_virtual_paths('/blah/flah.html') expected = fix('/blah/flah.html') actual = request.fs assert actual == expected, actual
def test_virtual_path_directory(): mk(('%first/index.html', "Greetings, program!")) expected = fix('%first') + os.sep actual = check_virtual_paths('/foo/').fs assert actual == expected, actual + " != " + expected
def test_index_is_found(): mk(('index.html', "Greetings, program!")) expected = fix('index.html') actual = check_index('/').fs assert actual == expected, actual
def test_indirect_negotiation_really_prefers_rendered(): mk(('foo.html', "Greetings, program!"), ('foo.', "blah blah blah")) expected = fix('foo.html') actual = check_indirect_negotiation('foo.html').fs assert actual == expected, actual
def test_indirect_negotation_doesnt_do_dirs(): mk(('foo/bar.html', "Greetings, program!")) actual = check_indirect_negotiation('foo.html').fs expected = fix('foo.html') assert actual == expected, actual
def test_alternate_index_is_found(): mk(('.aspen/configure-aspen.py', 'website.indices += ["default.html"]'), ('default.html', "Greetings, program!")) expected = fix('default.html') actual = check_index('/').fs assert actual == expected, actual
def test_indirect_negotiation_skips_two_dots(): mk(('foo.bar', "Greetings, program!")) expected = fix('foo.bar.html') actual = check_indirect_negotiation('foo.bar.html').fs assert actual == expected, actual + " isn't " + expected
def test_virtual_path_matches_the_first(): mk(('%first/foo.html', "Greetings, program!"), ('%second/foo.html', "WWAAAAAAAAAAAA!!!!!!!!")) expected = fix('%first/foo.html') actual = check_virtual_paths('/1999/foo.html').fs assert actual == expected, actual
def test_indirect_negotiation_can_passthrough_negotiated(): mk(('foo', "Greetings, program!")) expected = fix('foo') actual = check_indirect_negotiation('foo').fs assert actual == expected, actual
def test_alternate_index_is_not_found(): mk(('default.html', "Greetings, program!")) expected = fix('') actual = check_index('/').fs assert actual == expected, actual