def make_test_db(): db._reset_db() db.add_bottle_type('Kraken', 'dark spiced rum', 'dark spiced rum') db.add_to_inventory('Kraken', 'dark spiced rum', '750 ml') db.add_bottle_type('Bols', 'blue curacao', 'citrus liqeur') db.add_to_inventory('Bols', 'blue curacao', '500 ml') db.add_bottle_type('Hypnotiq', 'original', 'berry liqeur') db.add_to_inventory('Hypnotiq', 'original', '750 ml') db.add_bottle_type('Uncle John\'s', 'original cider', 'apple cider') db.add_to_inventory('Uncle John\'s', 'original cider', '1 g') kraken_destroyer = Recipe('kraken destroyer', [('dark spiced rum', '4.5 oz'), ('citrus liqeur', '1 oz'), ('berry liqeur', '1 oz'), ('apple cider', '8 oz')]) db.add_recipe(kraken_destroyer) kraken_and_cola = Recipe('kraken and cola', [('dark spiced rum', '6 oz'), ('cola', '8 oz')]) db.add_recipe(kraken_and_cola)
def populate_database(): db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch') db.add_to_inventory('Johnnie Walker', 'black label', '500 ml') db.add_bottle_type('Uncle Hermans', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Hermans', 'moonshine', '5 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 liter') db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth') db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz') derp = dict() r = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'), ('vermouth', '1.5 oz')]) db.add_recipe(r) derp[r.name] = r r = recipes.Recipe('Gin and Tonic', [('gin', '2 oz'), ('tonic water', '5 oz')]) db.add_recipe(r) derp[r.name] = r herp = dict() herp[('Johnnie Walker', 'black label')] = 1000 herp[('Gray Goose', 'vodka')] = 500 party1 = Party("Befall", "Get Drunk Party", "05-03-13", "11:00pm", "123 Balls St.", derp, herp) db.add_party(party1) db.save_db('bin\drinkz.txt')
def test_recipes(): db._reset_db() db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') r = recipes.Recipe('whiskey bath', [('blended scotch', '2 liter')]) db.add_recipe(r) environ = {} environ['PATH_INFO'] = '/recipes' d = {} def my_start_response(s, h, return_in=d): d['status'] = s d['headers'] = h app_obj = app.SimpleApp() results = app_obj(environ, my_start_response) text = "".join(results) status, headers = d['status'], d['headers'] assert text.find('Recipes') != -1, text assert text.find('whiskey bath') != -1, text assert ('Content-type', 'text/html') in headers assert status == '200 OK'
def test_json_inventory(): db._reset_db() db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') r = recipes.Recipe('whiskey bath', [('blended scotch', '2 liter')]) db.add_recipe(r) x = make_rpc_call('get_liquor_inventory', []) assert x == [[u"Uncle Herman's", u'moonshine']]
def test_json_recipes(): db._reset_db() db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') r = recipes.Recipe('whiskey bath', [('blended scotch', '2 liter')]) db.add_recipe(r) x = make_rpc_call('get_recipe_names', []) assert 'whiskey bath' in x
def recipe_recv(self, environ, start_response): formdata = environ["QUERY_STRING"] results = urlparse.parse_qs(formdata) name = results["name"][0] ingredients = results["ingredients"][0] ingredients = ingredients.split() ing = [] counter = 0 for i in ingredients: # first if counter % 2 == 0 and counter + 1 < len(ingredients): i = (ingredients[counter], ingredients[counter + 1]) ing.append(i) counter += 1 r = recipes.create(name, ing) db.add_recipe(r) content_type = "text/html" data = """\ <head><title>Form Results</title> <style type="text/css"> h1 {color:red;} </style> </head> <body> <h1>Form Results</h1>""" data += "Name: " + name data += "Ingredients: " for i in ing: for parts in i: data += parts + "\n" data += """ Visit: <a href='index'>Index</a> """ start_response("200 OK", list(html_headers)) return [data]
def recipe_Rev(self, environ, start_response): formdata = environ["QUERY_STRING"] results = urlparse.parse_qs(formdata) recipeName = results['recipeName'][0] ingredients = results['ingredients'][0].split(',') Ingredients = [] i=0 while i < len(ingredients): Ingredients.append((ingredients[i], ingredients[i+1])) i += 2 db.add_recipe(recipes.Recipe(recipeName, Ingredients)) data = "Added recipe to database" data += "<p><a href = '/'>Index</a></p>" start_response('200 OK', list(html_headers)) return [data]
def recipes_add(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) name = results['name'][0] ingredients = results['ingredients'][0] ingredients = ingredients.splitlines() ingredients = [ x.strip() for x in ingredients ] # clean whitespace ingredients = [ x for x in ingredients if x ] # remove empty ingredients = [ x.split(',') for x in ingredients ] r = recipes.Recipe(name, ingredients) db.add_recipe(r) db.save_db("database.db") headers = list(html_headers) headers.append(('Location', '/recipes')) start_response('302 Found', headers) return ["Redirect to /recipes..."]
def rpc_recipe(self, name, ingredients): ingredients = ingredients.split() ing = [] counter = 0 for i in ingredients: # first if counter % 2 == 0 and counter + 1 < len(ingredients): i = (ingredients[counter], ingredients[counter + 1]) ing.append(i) counter += 1 r = recipes.create(name, ing) db.add_recipe(r) data = name + " Ingredients: " for i in ing: for parts in i: data += parts + " " data += "\n" return data
def db_Init(): db._reset_db() db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch') db.add_to_inventory('Johnnie Walker', 'black label', '500 ml') db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 liter') db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth') db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz') db.add_bottle_type('Freedom Walker', 'blue label', 'unblended scotch') r = recipes.Recipe('scotch on the rocks', [('blended scotch','4 oz')]) db.add_recipe(r) r = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'),('vermouth', '1.5 oz')]) db.add_recipe(r) r = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')]) db.add_recipe(r)
def rpc_add_recipe(self, name, ingredients): r = recipes.Recipe(name, ingredients) db.add_recipe(r)
pass db._reset_db() db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch') db.add_to_inventory('Johnnie Walker', 'black label', '500 ml') db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 liter') db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth') db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz') r = recipes.Recipe('scotch on the rocks', [('blended scotch', '4 oz')]) db.add_recipe(r) r = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'), ('vermouth', '1.5 oz')]) db.add_recipe(r) r = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')]) db.add_recipe(r) ### fp = open('html/index.html', 'w') print >>fp, """ <p><a href='index.html'>this is a relative link to index!</a></p> <p><a href='recipes.html'>this is a relative link to recipes!</a></p> <p><a href='inventory.html'>this is a relative link to inventory!</a></p> <p><a href='liquor_types.html'>this is a relative link to liquor types!</a></p> <h1>Hello, world!(Index)</h1>
import os from drinkz import db, recipes #Input different data db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch') db.add_to_inventory('Johnnie Walker', 'black label', '500 ml') db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 liter') db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth') db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz') r1 = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')]) r2 = recipes.Recipe('scotch on the rocks', [('blended scotch', '4 oz')]) r3 = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'),('vermouth', '1.5 oz')]) db.add_recipe(r1) db.add_recipe(r2) db.add_recipe(r3) try: os.mkdir('html/') except OSError: # already exists pass addr = """ <p><a href="index.html">Index</a> <p><a href='inventory.html'>Inventory</a></p> <p><a href='recipes.html'>Recipes</a></p> <p><a href='liquor_types.html'>Liquor Types</a></p>
def rpc_add_recipe(self, name, ing): db.add_recipe(recipes.Recipe(name, ing))
db.add_to_inventory('Johnnie Walker', 'black label', '500 ml') db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 liter') db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth') db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz') r = recipes.Recipe('scotch on the rocks', [('blended scotch','4 oz')]) s = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'),('vermouth', '1.5 oz')]) t = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')]) db.add_recipe(r) db.add_recipe(s) db.add_recipe(t) RCPs = db.get_all_recipes() fp = open('html/index.html', 'w') print >>fp, """<p><a href='inventory.html'>Inventory</a></p> <p><a href='recipes.html'>Recipes</a></p> <p><a href='liquor_types.html'>Liquor Types</a></p> """ fp.close() ###