Exemplo n.º 1
0
def test_add_liquor_type():
    simple_app = SimpleApp()
    simple_app.load_database('bin/database_file')
    
    environ = {'PATH_INFO': '/recv_add_liquor_type', 'QUERY_STRING': 'mfg=Lucid&liq=Green+Fairy&typ=absinthe'}
    d = {}
    def my_start_response(s, h, return_in=d):
        d['status'] = s
        d['headers'] = h
    
    text = _init_app(environ, my_start_response)
    status, headers = d['status'], d['headers']
    
    assert text.find('Lucid, Green Fairy, absinthe') != -1, text
Exemplo n.º 2
0
def test_add_recipe():
    simple_app = SimpleApp()
    simple_app.load_database('bin/database_file')
    
    d = {}
    def my_start_response(s, h, return_in=d):
        d['status'] = s
        d['headers'] = h
    
    environ = {'PATH_INFO': '/recv_add_recipe', 'QUERY_STRING': 'name=New+Recipe&in0=good+alcohol&amt0=6+gallons&in1=&amt1=&in2=&amt2=&in3=&amt3=&in4=&amt4='}
    
    results = _init_app(environ, my_start_response)
    status, headers = d['status'], d['headers']
    
    assert results.find('New Recipe:</strong> <em>Needs more ingredients') != -1, results
Exemplo n.º 3
0
def test_recipes():
    simple_app = SimpleApp()
    simple_app.load_database('bin/database_file')
    
    environ = {'PATH_INFO': '/recipes.html'}
    d = {}
    def my_start_response(s, h, return_in=d):
        d['status'] = s
        d['headers'] = h
    
    text = _init_app(environ, my_start_response)
    status, headers = d['status'], d['headers']
    
    assert text.find('scotch on the rocks') != -1, text
    assert text.find('black label on the rocks') != -1, text
Exemplo n.º 4
0
def test_add_inventory_item():
    simple_app = SimpleApp()
    simple_app.load_database('bin/database_file')
    
    d = {}
    def my_start_response(s, h, return_in=d):
        d['status'] = s
        d['headers'] = h
    
    # add the lucid green fairy bottle type
    simple_app.fake_init_page_builder('templates')
    environ = {'PATH_INFO': '/recv_add_liquor_type', 'QUERY_STRING': 'mfg=Lucid&liq=Green+Fairy&typ=absinthe'}
    simple_app(environ, my_start_response)
    
    environ = {'PATH_INFO': '/recv_add_inventory_item', 'QUERY_STRING': 'mfg=Lucid&liq=Green+Fairy&amt=8oz'}
    
    results = "".join(simple_app(environ, my_start_response))
    status, headers = d['status'], d['headers']
    
    assert results.find('Lucid, Green Fairy:') != -1, results
Exemplo n.º 5
0
def test_init():
    app = SimpleApp()
    app.load_database('bin/database_file')
Exemplo n.º 6
0
#!/usr/bin/env python

import random
import socket
import time
from drinkz.app import SimpleApp

the_app = SimpleApp()
the_app.fake_init_page_builder("templates")

s = socket.socket() # create socket object
host = socket.gethostname() # get local machine name
port = 8181;
s.bind((host,port)) # bind to the port

print "Starting server on", host, port

s.listen(5) # wait for client connection

while True:
    c, addr = s.accept() # establish connection with client
    print "Got connection from", addr
    
    buffer = c.recv(1024)
    
    while "\r\n\r\n" not in buffer:
        data = c.recv(1024)
        if not data:
            break
        buffer += data
        print (buffer,)
Exemplo n.º 7
0
def _init_app(environ, start_response):
    app_obj = SimpleApp()
    app_obj.fake_init_page_builder('templates')
    results = app_obj(environ, start_response)
    return "".join(results)