Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_simplates_can_import_from_dot_aspen():
    mk( '.aspen'
      , ('.aspen/foo.py', 'bar = "baz"')
      , ('index.html', "import fooGreetings, {{ foo.bar }}!")
       )
    expected = "Greetings, baz!"
    actual = handle().body
    assert actual == expected, actual
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def test_autoindex_response_is_404_by_default():
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected, actual
Ejemplo n.º 13
0
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 Responseraise 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 Responseraise Response(404)"))
    expected = 404 
    actual = handle().code
    assert actual == expected, actual

def test_autoindex_response_is_404_by_default():
Ejemplo n.º 14
0
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