예제 #1
0
파일: test_small.py 프로젝트: naskoro/naya
def test_jinja_shared():
    app['jinja:path_deny'] = []
    c.get('/t/text.txt', code=200)
    c.get('/t/', code=200)

    app['jinja:path_deny'] = ['.*']
    c.get('/t/text.txt', code=404)
    c.get('/t/', code=404)

    app['jinja:theme_redirect'] = True
    c.get('/t/text.txt', code=301)
    c.get(c.path, code=200, follow_redirects=True)
    aye('==', '/static/text.txt', c.path)

    app['theme:url_prefix'] = '/t/'
    app.reload()
    c.get('/t/text.txt', code=200)

    app['jinja:path_allow'] = ['\.txt$']
    app['jinja:path_deny'] = []
    c.get('/t/text.txt', code=200)
    c.get('/t/', code=404)

    app['jinja:path_allow'] = ['.*']
    app['jinja:path_deny'] = ['\.html$']
    c.get('/t/text.txt', code=200)
    c.get('/t/', code=200)

    app['jinja:shared'] = False
    c.get('/t/', code=404)
예제 #2
0
파일: test_simple.py 프로젝트: naskoro/naya
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'))
예제 #3
0
파일: test_script.py 프로젝트: naskoro/naya
def test_shell():
    def check(cmd):
        cmd = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        stdout, stderr = cmd.communicate('print(42)\nquit()')
        aye('==', 0, cmd.returncode)
        aye('==', '42\n', stdout)

    check('./manage.py shell')
    check('./manage.py shell --no-bpython')

    cmd = Popen('./manage.py shell', shell=True,
        stdin=PIPE, stdout=PIPE, stderr=STDOUT
    )
    aye('is', None, cmd.terminate())
예제 #4
0
파일: test_small.py 프로젝트: naskoro/naya
def test_session():
    c.get('session/check/', code=200)
    aye('==', 'no answer', c.data)

    c.get('session/add/', code=200)
    aye('==', 'ok', c.data)

    c.get('session/check/', code=200)
    aye('==', 'answer is 42', c.data)
예제 #5
0
 def check(sep=':'):
     app.conf['jinja:prefix_separator'] = sep
     c.get('/admin%sbase.html' % sep, code=200)
     aye('in', 'admin', c.data)
     aye('in', '/s/admin/base.html', c.data)
예제 #6
0
def test_app():
    aye('==', 'examples.modular', app.import_name)
    aye('!=', False, app.jinja)

    aye('==', 3, call(len, app.modules))

    front = app.modules['front']
    blog = app.modules['blog']
    admin = app.modules['admin']

    aye('==', ('front', ''), (front['name'], front['prefix']))
    aye('==', ('blog', ''), (blog['name'], blog['prefix']))
    aye('==', ('admin', 'admin'), (admin['name'], admin['prefix']))

    aye('==', 'examples.modular.front', front.import_name)
    aye('==', 'examples.modular.blog', blog.import_name)
    aye('==', 'examples.modular.admin', admin.import_name)
예제 #7
0
def test_urls():
    c.get('/', code=200)
    aye('in', 'from front', c.data)

    c.get('/admin/', code=200)
    aye('in', 'text/html', c.content_type)
    aye('in', 'from admin', c.data)

    c.get('/admin/base.html', code=200)
    aye('in', 'front', c.data)

    c.get('/admin/base', code=301)
    c.get('/admin/base/', code=200)
    aye('in', 'text/html', c.content_type)
    aye('in', 'admin', c.data)

    c.get('/admin/test.html', code=200)
    aye('in', 'from front', c.data)

    c.get('/s/admin/base.html', code=200)
    aye('not in', 'admin', c.data)

    c.get('/s/admin/test.html', code=200)
    aye('not in', 'admin', c.data)

    c.get('/s/admin/index.html', code=200)
    aye('in', 'admin', c.data)

    c.get('/repos/', code=200)
    aye('in', 'modular.front.repos.list', c.data)

    c.get('/dashboard/', code=200)
    aye('in', 'modular.front.dashboard', c.data)

    c.get('/admin/dashboard', code=301)
    c.get(c.path, code=200, follow_redirects=True)
    aye('==', '/admin/dashboard/', c.path)
    aye('in', 'modular.admin.dashboard', c.data)

    c.get('/text.txt', code=404)
    c.get('/main.css', code=404)
    c.get('/admin/not_found', code=404)
    c.get('/admin/base/index', code=404)
예제 #8
0
def test_url_for():
    aye('==', '/', app.url_for(':tpl', path=''))
    aye('==', '/', app.url_for(':tpl', path='/'))
    aye('==', '/index.html', app.url_for(':tpl', path='index.html'))
    aye('==', '/admin/', app.url_for(':tpl', path='admin/'))
    aye('==', '/admin/index.html',
        app.url_for(':tpl', path='admin/index.html')
    )
    aye('==', '/admin/base.html',
        app.url_for(':tpl', path='admin/base.html')
    )
    aye('==', '/s/index.html', app.url_for(':theme', path='index.html'))
    aye('==', '/s/admin/index.html',
        app.url_for(':theme', path='admin/index.html')
    )

    aye('==', '/repos/', app.url_for('front:repos.list'))
    aye('==', '/dashboard/', app.url_for('front:dashboard'))
    aye('==', '/admin/dashboard/', app.url_for('admin:dashboard'))
예제 #9
0
파일: test_small.py 프로젝트: naskoro/naya
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)
예제 #10
0
파일: test_small.py 프로젝트: naskoro/naya
def test_url_for():
    aye('==', '/', app.url_for(':hello'))
    aye('==', '/bob', app.url_for(':hello', name='bob'))
    aye('==', '/t/', app.url_for(':jinja', path=''))
    aye('==', '/t/index.html', app.url_for(':jinja', path='index.html'))
    aye('==', '/static/index.html', app.url_for(':static', path='index.html'))

    aye('==', '/blog/', app.url_for(':blog.index'))
    aye('==', '/blog/', app.url_for('blog:index'))
    aye('==', '/blog/', app.url_for('examples.small.blog.index'))
예제 #11
0
파일: test_small.py 프로젝트: naskoro/naya
def test_app_init():
    aye(True, app['testing'])
    aye(False, App()['testing'])

    App.import_name = None
    raises(AttributeError, lambda: App())
예제 #12
0
파일: test_small.py 프로젝트: naskoro/naya
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'))
예제 #13
0
파일: test_small.py 프로젝트: naskoro/naya
def test_app():
    aye('==', 'examples.small', app.import_name)
    aye('!=', False, app.jinja)

    aye('==', 5, call(len, marker.defaults.of(app)))
    aye('==', 5, call(len, marker.init.of(app)))
    aye('==', 2, call(len, app.modules))
    aye('==', 1, call(len, marker.pre_request.of(app)))
    aye('==', 1, call(len, marker.post_request.of(app)))
    aye('==', 1, call(len, marker.wrap_handler.of(app)))
    aye('==', 1, call(len, marker.middleware.of(app)))

    mod = app.modules['']
    aye('==', ('', ''), (mod['name'], mod['prefix']))
    aye('==', 'examples.small.views', mod.import_name)
예제 #14
0
파일: test_script.py 프로젝트: naskoro/naya
 def check(cmd):
     cmd = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
     stdout, stderr = cmd.communicate('print(42)\nquit()')
     aye('==', 0, cmd.returncode)
     aye('==', '42\n', stdout)
예제 #15
0
파일: test_simple.py 프로젝트: naskoro/naya
def test_app():
    aye('==', 'examples.simple', app.import_name)
    aye('==', ('', ''), (app['name'], app['prefix']))

    aye(False, call(hasattr, app, 'jinja'))

    aye('==', 3, call(len, marker.defaults.of(app)))
    aye('==', 3, call(len, marker.init.of(app)))
    aye('==', 1, call(len, marker.pre_request.of(app)))
    aye('==', 1, call(len, marker.post_request.of(app)))
    aye('==', 0, call(len, marker.wrap_handler.of(app)))
    aye('==', 0, call(len, marker.middleware.of(app)))

    aye('==', 0, call(len, app.modules))

    url_rules = list(app.url_rules)
    aye('==', 1, call(len, url_rules))
    aye('==', 'examples.simple.index', url_rules[0].endpoint)
    aye('==', '/', url_rules[0].rule)
예제 #16
0
파일: test_simple.py 프로젝트: naskoro/naya
def test_client():
    result = c.get('/', code=200, as_tuple=True)
    aye('in', 'PATH_INFO', result[0])
    aye(True, call(isinstance, result[1], app.response_class))