Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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)

Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
def test_index():
    with get(weby.wsgify(hello.app), '/') as r:
        assert u'200' in r.status
        assert u'Hello, world!' in r.body