Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def test_unavailable_knob_works():
    mk( '.aspen'
      , ('.aspen/foo.py', 'bar = "baz"')
      , ('index.html', "import fooGreetings, {{ foo.bar }}!")
       )
    actual = handle('/', '--unavailable=1').code
    assert actual == 503, actual
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def test_resources_can_import_from_dot_aspen():
    mk( '.aspen'
      , ('.aspen/foo.py', 'bar = "baz"')
      , ('index.html', "import fooGreetings, {{ foo.bar }}!")
       )
    expected = "Greetings, baz!"
    actual = handle('/', '--project_root=.aspen').body
    assert actual == expected, actual
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
Exemplo n.º 14
0
def test_resources_can_import_from_dot_aspen():
    mk( '.aspen'
      , ('.aspen/foo.py', 'bar = "baz"')
      , ('index.html', "import fooGreetings, {{ foo.bar }}!")
       )
    expected = "Greetings, baz!"
    actual = handle('/', '--project_root=.aspen').body
    assert actual == expected, actual
Exemplo n.º 15
0
def test_unavailable_knob_sets_retry_after_on_website():
    mk( '.aspen'
      , ('.aspen/foo.py', 'bar = "baz"')
      , ('index.html', "import fooGreetings, {{ 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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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
Exemplo n.º 22
0
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
Exemplo n.º 23
0
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
Exemplo n.º 24
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
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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
Exemplo n.º 28
0
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():
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected, actual

def test_autoindex_response_is_returned():
Exemplo n.º 29
0
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
Exemplo n.º 30
0
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
Exemplo n.º 31
0
def test_autoindex_response_is_404_by_default(mk):
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected
Exemplo n.º 32
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

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():
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
Exemplo n.º 34
0
def test_autoindex_response_is_404_by_default():
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected, actual
Exemplo n.º 35
0
def test_fatal_error_response_is_returned():
    mk(('index.html', "raise heck"))
    expected = 500
    actual = handle().code
    assert actual == expected, actual
Exemplo n.º 36
0
def test_autoindex_response_is_returned():
    mk(('README', "Greetings, program!"))
    expected = True
    actual = 'README' in handle('/', '--list_directories=TrUe').body
    assert actual == expected, actual
Exemplo n.º 37
0
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
Exemplo n.º 40
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
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
Exemplo n.º 43
0
def test_autoindex_response_is_returned(mk):
    mk(('README', "Greetings, program!"))
    body = handle('/', '--list_directories=TrUe').body
    assert 'README' in body
Exemplo n.º 44
0
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_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)
Exemplo n.º 49
0
def test_autoindex_response_is_returned():
    mk(('README', "Greetings, program!"))
    body = handle('/', '--list_directories=TrUe').body
    assert 'README' in body, body
Exemplo n.º 50
0
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
Exemplo n.º 52
0
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
Exemplo n.º 53
0
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
Exemplo n.º 54
0
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
Exemplo n.º 57
0
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