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 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_add_to_inventory(): db._reset_db() db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') x = make_rpc_call('add_to_inventory', ('Uncle Herman\'s', 'moonshine', '5 liter')) x = make_rpc_call('get_liquor_inventory', []) assert x == [[u"Uncle Herman's", u'moonshine']]
def test_json_add_recipe(): db._reset_db() db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch') db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter') make_rpc_call('add_recipe', (('whiskey bath', [('blended scotch', '2 liter')]))) x = make_rpc_call('get_recipe_names', []) assert 'whiskey bath' in x
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 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 liquor_types_add(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] typ = results['typ'][0] db.add_bottle_type(mfg, liquor, typ) db.save_db("database.db") headers = list(html_headers) headers.append(('Location', '/liquor_types')) start_response('302 Found', headers) return ["Redirect to /liquor_types..."]
def liquor_types_Rev(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liq = results['liquor'][0] typ = results['typ'][0] db.add_bottle_type(mfg,liq,typ) #print db._bottle_types_db data = "Added liquor type to database" data += "<p><a href = '/'>Index</a></p>" start_response('200 OK', list(html_headers)) return [data]
def lt_recv(self, environ, start_response): formdata = environ["QUERY_STRING"] results = urlparse.parse_qs(formdata) mfg = results["mfg"][0] liquor = results["liquor"][0] typ = results["typ"][0] print mfg print liquor print typ db.add_bottle_type(mfg, liquor, typ) 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 += "Mfg: " + mfg data += "Liquor: " + liquor data += "Type: " + typ data += """ Visit: <a href='index'>Index</a> </body> """ start_response("200 OK", list(html_headers)) return [data]
def rpc_add_bottle_type(self, mfg, liquor, typ): db.add_bottle_type(mfg, liquor, typ)
#! /usr/bin/env python import os from drinkz import db, recipes try: os.mkdir('html') except OSError: # already exists 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)
def rpc_lt(self, mfg, liquor, typ): db.add_bottle_type(mfg, liquor, typ) print db._check_bottle_type_exists("Johnnie Walker", "Black Label") return mfg + " " + liquor + " " + typ
# already exists pass try: os.mkdir("html/subdir") except OSError: # already exists pass ######################################################################## # Add items to the inventory # Copied the drinks from drinkz/test_recipes.py ######################################################################## db._reset_db() # Reset 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 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") # Add recipes 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")])
import drinkz.db from drinkz import recipes try: os.mkdir('html') except OSError: # already exists pass #################################################### #Create Data #################################################### db._reset_db() db.add_bottle_type('Jack Daniels', 'black label', 'bourbon') db.add_to_inventory('Jack Daniels', 'black label', '750 ml') db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch') db.add_bottle_type('Johnnie Walker', 'black label', '1 liter') db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka') db.add_to_inventory('Gray Goose', 'vodka', '1 pint') db.add_bottle_type('Captain Morgan', 'rum', 'spiced rum') db.add_to_inventory('Captain Morgan', 'rum', '24 oz') db.add_bottle_type('Guinness', 'stout', 'dry stout') db.add_to_inventory('Guinness', 'stout', '144 oz') db.add_bottle_type('Baileys', 'whiskey', 'Irish cream')