示例#1
0
文件: test_weby.py 项目: jperla/weby
def test_remaining_url_arg_parser():
    with get(weby.wsgify(simplest.app), u'/joe?times=10') as r:
        assert u'200' in r.status
        assert u'joe' in r.body
        assert u'Hello, joe!' in r.body
        assert len(re.findall(u'joe', r.body)) == 10
        assert u'Hello, joe!' in r.body
示例#2
0
文件: test_weby.py 项目: jperla/weby
def test_simplest():
    with get(weby.wsgify(simplest.app), u'/world?times=3') as r:
        assert u'200' in r.status
        body = r.body
        assert u'world' in body
        assert u'Hello, world!' in body
        assert len(re.findall('world', body)) == 3
示例#3
0
文件: test_weby.py 项目: jperla/weby
def test_simplest_hello():
    with get(weby.wsgify(simplest.app), '/') as r:
        assert u'200' in r.status
        assert u'world' in r.body
        assert u'Hello, world!' in r.body
        assert u'<br />' in r.body
        assert u'500' not in r.status
        assert u'Error' not in r.status
        assert u'Error' not in r.body
示例#4
0
文件: __init__.py 项目: jperla/weby
def index(req, page):
    page(u'Hello, world!')

@app.subapp('hello')
@weby.urlable_page()
def hello(req, page):
    page(u'<form method="POST">')
    name = req.params.get('name', None)
    if name is None:
        page(u'Hello, world! <br />')
    else:
        page(u'Hello, %(name)s! <br />' % {'name': name})
    page(u'Your name: <input type="text" name="name">')
    page(u'<input type="submit">')
    page(u'</form>')

@app.subapp('hello_old')
@weby.urlable_page()
def hello_old(req, p):
    weby.http.status.redirect(hello.url())

# Middleware
from weby.middleware import EvalException
wrapped_app = weby.wsgify(app, EvalException)

# Server
from weby.http import server
if __name__ == '__main__':
    server.serve(wrapped_app, host='127.0.0.1', port=8080)

示例#5
0
文件: __init__.py 项目: jperla/weby
import weby

app = weby.defaults.App()

@app.default_subapp()
@weby.urlable_page()
def send(req, page):
    email = req.params.get(u'email', u'*****@*****.**')
    mail_server = req.settings[u'mail_server']
    message = weby.email.create_text_message(u'*****@*****.**',
                                                [email],
                                                u'Hello, World!',
                                                u'I am sending you a text message')
    mail_server.send_message(message)
    page(u'Sent email.')

mail_server = weby.email.TestMailServer()
settings = {'mail_server': mail_server}
app = weby.apps.SettingsMiddleApp(settings, app)

if __name__ == '__main__':
    weby.run(weby.wsgify(app))
    
# Try Loading http://127.0.0.1:8080/hello/world?times=1000000
示例#6
0
文件: test_weby.py 项目: jperla/weby
def test_static_app():
    content = u'div {\n    color: blue;\n}\n'
    with get(weby.wsgify(standard.app), u'/static/style.css') as r:
        assert content == r.body
示例#7
0
文件: test_weby.py 项目: jperla/weby
def test_send_email():
    with difference(lambda:len(send_email.mail_server.sent_email)):
        with get(weby.wsgify(send_email.app), '/static/style.css') as r:
            assert u'200' in r.status
示例#8
0
文件: test_weby.py 项目: jperla/weby
def test_layout():
    with get(weby.wsgify(layouts.app), '/hello?name=joe') as r:
        assert u'200' in r.status
        assert u'joe' in r.body
        assert u'Hello, joe!' in r.body
        assert u'<title>' in r.body
示例#9
0
文件: test_weby.py 项目: jperla/weby
def test_template():
    with get(weby.wsgify(first_template.app), u'/hello?name=joe') as r:
        assert u'200' in r.status
        assert u'joe' in r.body
        assert u'Hello, joe!' in r.body
示例#10
0
文件: test_weby.py 项目: jperla/weby
def test_redirect():
    with get(weby.wsgify(hello.app), '/hello_old/') as r:
        assert u'302' in r.status
        assert u'/hello/' in r.body
示例#11
0
文件: test_weby.py 项目: jperla/weby
def test_unicode():
    with get(weby.wsgify(simplest.app), u'/wểrld?times=3') as r:
        assert u'200' in r.status
        assert u'wểrld' in r.body.decode('utf8')
        assert u'Hello, wểrld!' in r.body.decode('utf8')
        assert len(re.findall(u'wểrld', r.body.decode('utf8'))) == 3
示例#12
0
文件: test_weby.py 项目: jperla/weby
def test_index():
    with get(weby.wsgify(hello.app), '/') as r:
        assert u'200' in r.status
        assert u'Hello, world!' in r.body