def rpc_add_inventory(self, mfg, liquor, amount): n = False; result = db.check_inventory(mfg, liquor) if result == False: db.add_to_inventory(mfg, liquor, amount) n = True return n
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_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 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 inventory_add(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] amount = results['amount'][0] db.add_to_inventory(mfg, liquor, amount) db.save_db("database.db") headers = list(html_headers) headers.append(('Location', '/inventory')) start_response('302 Found', headers) return ["Redirect to /inventory..."]
def li_recv(self, environ, start_response): formdata = environ["QUERY_STRING"] results = urlparse.parse_qs(formdata) mfg = results["mfg"][0] liquor = results["liquor"][0] amount = results["amount"][0] num_amount = db.convert_to_ml(amount) content_type = "text/html" if num_amount != -1: amount = "Amount in ML: %d" % (num_amount) else: amount = "Unknown Units" db.add_to_inventory(mfg, liquor, amount) 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 += amount data += """ Visit: <a href='index'>Index</a> """ start_response("200 OK", list(html_headers)) return [data]
def inventory_Rev(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liq = results['liquor'][0] amt = results['amount'][0] #print amt data = "" bottleTypExists = db._check_bottle_type_exists(mfg, liq) if bottleTypExists == True: db.add_to_inventory(mfg, liq, amt) data += "Added Liquor to Inventory" else: data = "Could not add bottle to inventory, Liquor bottle type could not be found" data += "<p><a href='/'>Index</a></p>" start_response('200 OK', list(html_headers)) return [data]
def rpc_add_to_inventory(self, mfg, liquor, amount): db.add_to_inventory(mfg, liquor, amount)
#! /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_li(self, mfg, liquor, amount): # new_amount = db.convert_to_ml(amount) db.add_to_inventory(mfg, liquor, amount) return mfg + " " + liquor + " " + amount
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")]) db.add_recipe(r)
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') db.add_to_inventory('Baileys', 'whiskey','750 ml')