def test_inventory(): #load from file dynamic_web.load_database('bin/sample_database') environ = {} environ['PATH_INFO'] = '/inventory.html' 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'] #Check for manufacturer: "Gray Goose" assert text.find('Gray Goose') != -1, text #Check for manufacturer: "Johnnie Walker" assert text.find('Johnnie Walker') != -1, text #Check for manufacturer: "Rossi" assert text.find('Rossi') != -1, text #Check for manufacturer: "Uncle Herman's" assert text.find('Uncle Herman\'s') != -1, text #Make sure that the test did not produce an error assert status == '200 OK'
def test_liquor_types(): #load from file dynamic_web.load_database('bin/sample_database') environ = {} environ['PATH_INFO'] = '/liquor_types.html' 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'] #Check for liquor type: "blended scotch" assert text.find('blended scotch') != -1, text #Check for liquor type: "unflavored vodka" assert text.find('unflavored vodka') != -1, text #Check for liquor type: "vermouth" assert text.find('vermouth') != -1, text #Make sure that the test did not produce an error assert status == '200 OK'
def test_recipes(): #load from file dynamic_web.load_database('bin/sample_database') environ = {} environ['PATH_INFO'] = '/recipes.html' 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'] #Check for recipe: "scotch on the rocks" assert text.find('scotch on the rocks') != -1, text #Check for recipe: "vomit inducing martini" assert text.find('vomit inducing martini') != -1, text #Check for recipe: "whiskey bath" assert text.find('whiskey bath') != -1, text #Check for recipe: "vodka martini" assert text.find('vodka martini') != -1, text #Make sure that the test did not produce an error assert status == '200 OK'
def __call__(self, environ, start_response): #load from file dynamic_web.load_database('/../bin/drinkz_database') path = environ['PATH_INFO'] fn_name = dispatch.get(path, 'error') # retrieve 'self.fn_name' where 'fn_name' is the # value in the 'dispatch' dictionary corresponding to # the 'path'. fn = getattr(self, fn_name, None) if fn is None: start_response("404 Not Found", html_headers) return ["No path %s found" % path] return fn(environ, start_response)
def test_get_liquor_inventory(): # load from file dynamic_web.load_database("/../bin/drinkz_database") s, h, result = call_remote("get_liquor_inventory", []) # Check for valid status assert s == "200 OK" # Check for correct content assert ("Content-Type", "application/json") in h, h # Check for Gray Goose assert "Gray Goose" in result["result"], result["result"] # Check for Johnnie Walker assert "Johnnie Walker" in result["result"], result["result"] # Check for Rossi assert "Rossi" in result["result"], result["result"] # Uncle Herman's assert "Uncle Herman's" in result["result"], result["result"]
def test_get_recipe_names(): # load from file dynamic_web.load_database("/../bin/drinkz_database") s, h, result = call_remote("get_recipe_names", []) # Check for valid status assert s == "200 OK" # Check for correct content assert ("Content-Type", "application/json") in h, h # Check for whiskey bath assert "whiskey bath" in result["result"], result["result"] # Check for vomit inducing martini assert "vomit inducing martini" in result["result"], result["result"] # Check for scotch on the rocks assert "scotch on the rocks" in result["result"], result["result"] # Check for vodka martini assert "vodka martini" in result["result"], result["result"]
#HW5_1d JSON-RPC add liquor to inventory def rpc_add_to_inventory(self, mfg,liquor,amt ): return db.add_to_inventory(mfg,liquor,amt) #HW5_1d JSON-RPC add liquor type def rpc_add_bottle_type(self, mfg, liquor,typ): return db.add_bottle_type(mfg,liquor,typ) #HW5_1d JSON-RPC return the recipes that we can make def rpc_check_if_can_make_recipes(self, recipe_list): return list(db.check_if_can_make_recipes(recipe_list)) #H5_2 JSON-RPC to search price of a drink type def rpc_search_drink_price(self, type): return db.cost_search_drink_type(type) if __name__ == '__main__': import random, socket port = random.randint(8000, 9999) #load from file dynamic_web.load_database('/../bin/drinkz_database') #dynamic_web.save_database('/../bin/drinkz_database') app = SimpleApp() httpd = make_server('', port, app) print "Serving on port %d..." % port print "Try using a Web browser to go to http://%s:%d/" % \ (socket.getfqdn(), port) httpd.serve_forever()