Beispiel #1
0
def test_testing():
    c.get('/', query_string={'answer': '42'})
    aye(True, hasattr(c, 'data'))
    aye(True, call(isinstance, c.data, unicode))

    aye(True, hasattr(c, 'content_type'))
    aye('==', 'text/html; charset=utf-8', c.content_type)

    aye(True, hasattr(c, 'status_code'))
    aye(True, 200, c.status_code)

    aye(True, hasattr(c, 'headers'))
    aye('in', ('Content-Length', '12'), c.headers.items())

    aye(True, hasattr(c, 'path'))
    aye('==', '/', c.path)

    aye(True, hasattr(c, 'url'))
    aye('==', 'http://localhost/?answer=42', c.url)

    aye(False, hasattr(c, 'answer'))

    raises(AssertionError, lambda: aye('in', u' ответ', 'answer 42'))

    aye('in', 'Hello world!', c.cssselect('p'))
Beispiel #2
0
def test_url_for():
    c.get('/', code=200)
    aye('==', 'Hello world!', c.data)

    aye('==', '/', app.url_for(':index'))
    raises(BuildError, lambda: app.url_for(':jinja', path='index.html'))
    raises(BuildError, lambda: app.url_for(':theme', path='index.html'))
Beispiel #3
0
def test_urls():
    c.get('/', code=200)
    aye('in', 'Hello world!', c.data)

    c.get('/t/index.html/', code=301)
    c.get('/t/index.html', code=301)
    c.get('/t/index', code=301)
    c.get('/t/index/', code=301)

    c.get('/t/index/', code=200, follow_redirects=True)
    aye('==', '/t/', c.path)
    aye('in', '/static/index.html', c.data)

    c.get('/static/main.css', code=200)
    aye('==', 'text/css', c.content_type)
    c.get('/static/main.js', code=200)
    aye('==', 'application/javascript', c.content_type)

    c.get('/static/index.html', code=200)
    aye('in', '{{ template }}', c.data)

    c.get('/blog/', code=200)
    aye('in', 'blog.index', c.data)

    c.get('/a/500', code=500)
    c.get('/a/403', code=403)
    c.get('/tuple/', code=201)

    c.get('/text/', code=200)
    c.get('/macro/', code=200)

    c.get('/r/', code=200, follow_redirects=True)
    aye('==', '/', c.path)

    c.get('/r/hello/', code=200, follow_redirects=True)
    aye('==', '/naspeh', c.path)

    e = raises(ValueError, c.get, '/wrong/', code=500)
    aye('==', e.args, ('View function did not return a response', ))

    c.get('/t/text.txt', code=404)
    c.get('/t/not_found', code=404)
Beispiel #4
0
def test_app_init():
    aye(True, app['testing'])
    aye(False, App()['testing'])

    App.import_name = None
    raises(AttributeError, lambda: App())