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
Ejemplo n.º 2
0
def test_configure_aspen_py_setting_strips_commas(mk):
    mk(('.aspen/configure-aspen.py',
        'website.indices = ["index.html", "default.html"]'),
       ('default.html', "Greetings, program!"))
    expected = fix('default.html')
    actual = check('/').fs
    assert actual == expected
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
def test_configure_aspen_py_setting_takes_second_if_first_is_missing(mk):
    mk(('.aspen/configure-aspen.py',
        'website.indices = ["index.html", "default.html"]'),
       ('default.html', "Greetings, program!"))
    expected = fix('default.html')
    actual = check('/').fs
    assert actual == expected
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
def test_index_conf_setting_works_with_only_comma():
    mk( ( '.aspen/aspen.conf'
        , '[aspen]\ndefault_filenames: index.html,default.html')
      , ('default.html', "Greetings, program!")
       )
    expected = fix('default.html')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 14
0
def test_index_conf_setting_ignores_blanks():
    mk( ( '.aspen/aspen.conf'
        , '[aspen]\ndefault_filenames: index.html,, ,, ,,, default.html')
      , ('default.html', "Greetings, program!")
       )
    expected = fix('default.html')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 15
0
def test_index_conf_setting_takes_second_if_first_is_missing():
    mk( ( '.aspen/aspen.conf'
        , '[aspen]\ndefault_filenames = index.html default.html')
      , ('default.html', "Greetings, program!")
       )
    expected = fix('default.html')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
def test_configure_aspen_py_setting_takes_first():
    mk(
        (".aspen/configure-aspen.py", 'website.indices = ["index.html", "default.html"]'),
        ("index.html", "Greetings, program!"),
        ("default.html", "Greetings, program!"),
    )
    expected = fix("index.html")
    actual = check_index("/").fs
    assert actual == expected, actual
Ejemplo n.º 19
0
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
Ejemplo n.º 20
0
def test_negotiated_index_is_found(mk):
    mk(('index', """
[----------] text/html
<h1>Greetings, program!</h1>
[----------] text/plain
Greetings, program!
"""))
    expected = fix('index')
    actual = check('/').fs
    assert actual == expected
Ejemplo n.º 21
0
def test_negotiated_index_is_found():
    mk(( 'index'
       , """\
^L text/html
<h1>Greetings, program!</h1>
^L text/plain
Greetings, program!
"""))
    expected = fix('index')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 22
0
def test_dont_redirect_second_index_if_first(mk):
    mk(('.aspen/configure-aspen.py',
        'website.indices = ["index.html", "default.html"]'),
       ('default.html', "Greetings, program!"),
       ('index.html', "Greetings, program!"))
    # first index redirects
    assert_raises_302(check, '/index.html')
    # second shouldn't
    expected = fix('default.html')
    actual = check('/default.html').fs
    assert actual == expected
def test_dont_redirect_second_index_if_first():
    mk( ( '.aspen/configure-aspen.py'
        , 'website.indices = ["index.html", "default.html"]')
      , ('default.html', "Greetings, program!")
      , ('index.html', "Greetings, program!")
       )
    # first index redirects
    assert_raises_302(check, '/index.html')
    # second shouldn't
    expected = fix('default.html')
    actual = check('/default.html').fs
    assert actual == expected, actual
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
def test_configuration_script_can_set_renderer_default(mk):
    CONFIG = """
website.renderer_default="stdlib_format"
    """
    SIMPLATE = """
name="program"
[----]
Greetings, {name}!
    """
    mk(
       ('.aspen/configure-aspen.py', CONFIG),
       ('index.html.spt', SIMPLATE)
      )
    w = Website(['--www_root', FSFIX, '-p', fix('.aspen'), '--show_tracebacks=yes'])
    request = StubRequest(b'/')
    request.website = w
    response = w.handle_safely(request)
    actual = response.body.strip()
    expected = 'Greetings, program!'
    assert actual == expected
Ejemplo n.º 26
0
def test_configuration_script_can_set_renderer_default():
    CONFIG = """
website.renderer_default="stdlib_format"
    """
    SIMPLATE = """
name="program"
[----]
Greetings, {name}!
    """
    mk(
       ('.aspen/configure-aspen.py', CONFIG),
       ('index.html.spt', SIMPLATE)
      )
    w = Website(['--www_root', FSFIX, '-p', fix('.aspen'), '--show_tracebacks=yes'])
    request = StubRequest(b'/')
    request.website = w
    response = w.handle_safely(request)
    actual = response.body.strip()
    expected = 'Greetings, program!'
    assert actual == expected, actual
Ejemplo n.º 27
0
def test_virtual_path_is_virtual(mk):
    mk(('%bar/foo.html', "Greetings, program!"))
    expected = fix('%bar/foo.html')
    actual = check('/blah/foo.html').fs
    assert actual == expected
Ejemplo n.º 28
0
def test_indirect_negotiation_can_passthrough_negotiated(mk):
    mk(('foo', "Greetings, program!"))
    expected = fix('foo')
    actual = check('foo').fs
    assert actual == expected
Ejemplo n.º 29
0
def test_indirect_negotiation_really_prefers_rendered_2(mk):
    mk(('foo.html', "Greetings, program!"), ('foo', "blah blah blah"))
    expected = fix('foo.html')
    actual = check('foo.html').fs
    assert actual == expected
Ejemplo n.º 30
0
def test_virtual_path_file_only_last_part(mk):
    mk(('foo/%bar.html.spt', "Greetings, program!"))
    expected = fix('foo/%bar.html.spt')
    actual = check('/foo/blah/baz.html').fs
    assert actual == expected
Ejemplo n.º 31
0
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
Ejemplo n.º 32
0
def test_virtual_path_can_passthrough(mk):
    mk(('foo.html', "Greetings, program!"))
    expected = fix('foo.html')
    actual = check('foo.html').fs
    assert actual == expected
Ejemplo n.º 33
0
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
Ejemplo n.º 34
0
def test_configure_aspen_py_setting_ignores_blanks():
    mk(('default.html', "Greetings, program!"))
    expected = fix('default.html')
    actual = check_index('/', '--indices', 'index.html, ,default.html').fs
    assert actual == expected, actual
Ejemplo n.º 35
0
def test_virtual_path__and_indirect_neg_file_not_dir(mk):
    mk(('%foo/bar.html', "Greetings from bar!"),
       ('%baz.spt', "Greetings from baz!"))
    expected = fix('%baz.spt')
    actual = check('/bal.html').fs
    assert actual == expected
Ejemplo n.º 36
0
def test_virtual_path_matches_the_first(mk):
    mk(('%first/foo.html', "Greetings, program!"),
       ('%second/foo.html', "WWAAAAAAAAAAAA!!!!!!!!"))
    expected = fix('%first/foo.html')
    actual = check('/1999/foo.html').fs
    assert actual == expected
Ejemplo n.º 37
0
def test_trailing_on_virtual_paths(mk):
    mk(('%foo/%bar/%baz/index.html', "Greetings program!"))
    expected = fix('/%foo/%bar/%baz/index.html')
    actual = check('/foo/bar/baz/').fs
    assert actual == expected
Ejemplo n.º 38
0
def test_dispatcher_passes_through_virtual_dir_with_trailing_slash(mk):
    mk(('%foo/index.html', "Greetings, program!"))
    expected = fix('/%foo/index.html')
    actual = check('/foo/').fs
    assert actual == expected
Ejemplo n.º 39
0
def test_trailing_slash_passes_dirs_with_slash_through(mk):
    mk(('foo/index.html', "Greetings, program!"))
    expected = fix('/foo/index.html')
    actual = check('/foo/').fs
    assert actual == expected
Ejemplo n.º 40
0
def test_virtual_path_and_indirect_neg_ext(mk):
    mk(('%foo/bar', "Greetings program!"))
    actual = check('/greet/bar.html').fs
    expected = fix('%foo/bar')
    assert actual == expected
Ejemplo n.º 41
0
def make_request(filename='echo.sock'):
    request = Request(uri='/echo.sock')
    request.website = Website([])
    request.fs = fix(filename)
    return request
Ejemplo n.º 42
0
def test_path_part_params_static_file(mk):
    mk(('/foo/bar.html', "Greetings program!"))
    expected = fix('/foo/bar.html')
    actual = check('/foo/bar.html;a=1;b=;a=2;b=3').fs
    assert actual == expected
Ejemplo n.º 43
0
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
Ejemplo n.º 44
0
def test_path_part_params_negotiated_simplate(mk):
    mk(('/foo/bar.spt', "Greetings program!"))
    expected = fix('/foo/bar.spt')
    actual = check('/foo/bar.html;a=1;b=;a=2;b=3').fs
    assert actual == expected
Ejemplo n.º 45
0
def test_index_is_found():
    mk(('index.html', "Greetings, program!"))
    expected = fix('index.html')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 46
0
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
Ejemplo n.º 47
0
def test_virtual_path_directory():
    mk(('%first/index.html', "Greetings, program!"))
    expected = fix('%first')
    actual = check_virtual_paths('/foo/').fs
    assert actual == expected, actual
Ejemplo n.º 48
0
def test_trailing_slash_passes_dirs_with_slash_through():
    mk('foo')
    expected = fix('/foo/')
    actual = check_trailing_slash('/foo/').fs
    assert actual == expected, actual
Ejemplo n.º 49
0
def test_path_part_params_greedy_simplate(mk):
    mk(('/foo/%bar.spt', "Greetings program!"))
    expected = fix('/foo/%bar.spt')
    actual = check('/foo/baz/buz;a=1;b=;a=2;b=3/blam.html').fs
    assert actual == expected
Ejemplo n.º 50
0
def test_virtual_path_directory(mk):
    mk(('%first/index.html', "Greetings, program!"))
    expected = fix('%first/index.html')
    actual = check('/foo/').fs
    assert actual == expected
Ejemplo n.º 51
0
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
Ejemplo n.º 52
0
def test_alternate_index_is_found(mk):
    mk(('.aspen/configure-aspen.py', 'website.indices += ["default.html"]'),
       ('default.html', "Greetings, program!"))
    expected = fix('default.html')
    actual = check('/').fs
    assert actual == expected
Ejemplo n.º 53
0
def test_alternate_index_is_not_found():
    mk(('default.html', "Greetings, program!"))
    expected = fix('')
    actual = check_index('/').fs
    assert actual == expected, actual
Ejemplo n.º 54
0
def test_indirect_negotiation_modifies_one_dot(mk):
    mk(('foo', "Greetings, program!"))
    expected = fix('foo')
    actual = check('foo.html').fs
    assert actual == expected
Ejemplo n.º 55
0
def test_path_part_with_params_works(mk):
    mk(('foo/index.html', "Greetings program!"))
    expected = fix('/foo/index.html')
    actual = check('/foo;a=1/').fs
    assert actual == expected
Ejemplo n.º 56
0
def test_indirect_negotiation_skips_two_dots(mk):
    mk(('foo.bar', "Greetings, program!"))
    expected = fix('foo.bar')
    actual = check('foo.bar.html').fs
    assert actual == expected
Ejemplo n.º 57
0
def test_path_part_params_vpath(mk):
    mk(('%bar/index.html', "Greetings program!"))
    expected = fix('/%bar/index.html')
    actual = check('/foo;a=1;b=;a=2;b=3/').fs
    assert actual == expected
Ejemplo n.º 58
0
def test_index_is_found(mk):
    mk(('index.html', "Greetings, program!"))
    expected = fix('index.html')
    actual = check('/').fs
    assert actual == expected
Ejemplo n.º 59
0
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
Ejemplo n.º 60
0
def test_configure_aspen_py_setting_ignores_blanks():
    mk(('default.html', "Greetings, program!"))
    expected = fix('default.html')
    actual = check_index('/', '--indices', 'index.html, ,default.html').fs
    assert actual == expected, actual