コード例 #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
コード例 #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
コード例 #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
コード例 #4
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
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
コード例 #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
コード例 #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)
コード例 #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
コード例 #8
0
ファイル: test_gauntlet.py プロジェクト: buchuki/aspen
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
コード例 #9
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
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
コード例 #10
0
ファイル: test_gauntlet.py プロジェクト: jarpineh/aspen
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
コード例 #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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
ファイル: test_website.py プロジェクト: jarpineh/aspen
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
コード例 #15
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
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
コード例 #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
コード例 #17
0
ファイル: test_gauntlet.py プロジェクト: jarpineh/aspen
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
コード例 #18
0
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
コード例 #19
0
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
コード例 #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
コード例 #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
コード例 #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
コード例 #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
コード例 #24
0
ファイル: test_website.py プロジェクト: jarpineh/aspen
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
コード例 #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
コード例 #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
コード例 #27
0
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
コード例 #28
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
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():
コード例 #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
コード例 #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
コード例 #31
0
def test_autoindex_response_is_404_by_default(mk):
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected
コード例 #32
0
ファイル: test_website.py プロジェクト: jarpineh/aspen
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():
コード例 #33
0
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
コード例 #34
0
ファイル: test_website.py プロジェクト: jarpineh/aspen
def test_autoindex_response_is_404_by_default():
    mk(('README', "Greetings, program!"))
    expected = 404
    actual = handle().code
    assert actual == expected, actual
コード例 #35
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
def test_fatal_error_response_is_returned():
    mk(('index.html', "raise heck"))
    expected = 500
    actual = handle().code
    assert actual == expected, actual
コード例 #36
0
ファイル: test_website.py プロジェクト: sanyaade-webdev/aspen
def test_autoindex_response_is_returned():
    mk(('README', "Greetings, program!"))
    expected = True
    actual = 'README' in handle('/', '--list_directories=TrUe').body
    assert actual == expected, actual
コード例 #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
コード例 #38
0
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
コード例 #39
0
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
コード例 #40
0
ファイル: test_website.py プロジェクト: buchuki/aspen
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
コード例 #41
0
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)
コード例 #42
0
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
コード例 #43
0
def test_autoindex_response_is_returned(mk):
    mk(('README', "Greetings, program!"))
    body = handle('/', '--list_directories=TrUe').body
    assert 'README' in body
コード例 #44
0
ファイル: test_website.py プロジェクト: jarpineh/aspen
def test_autoindex_response_is_returned():
    mk(('README', "Greetings, program!"))
    expected = True
    actual = 'README' in handle('/', '--list_directories=TrUe').body
    assert actual == expected, actual
コード例 #45
0
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
コード例 #46
0
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
コード例 #47
0
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
コード例 #48
0
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)
コード例 #49
0
def test_autoindex_response_is_returned():
    mk(('README', "Greetings, program!"))
    body = handle('/', '--list_directories=TrUe').body
    assert 'README' in body, body
コード例 #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
コード例 #51
0
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
コード例 #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
コード例 #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
コード例 #54
0
ファイル: test_gauntlet.py プロジェクト: jarpineh/aspen
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
コード例 #55
0
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
コード例 #56
0
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
コード例 #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