Exemplo n.º 1
0
def test_json_add_recipe():
    db._reset_db()
    
    call_remote(method='add_recipe', params=['scotch on the rocks', 
                                             'blended scotch', '4 oz'], id=1)

    assert db.get_recipe('scotch on the rocks').name == 'scotch on the rocks'
Exemplo n.º 2
0
    def te_tab_down(self, e):
        """autocompletes the selected ingredient, and fills in the unit option in the unit field"""

        index = self.lb.curselection(
        )  # it's a tuple of indexes always of length 1, so get the first
        if index:
            name = self.lb.get(
                0, END)[index[0]]  # get all items, then look up by index
        else:
            # index is an empty tuple if no selection i.e. the list has been filtered so there is nothing
            # displayed and the user wants something from the recipe list
            name = self.recipe_box.get(
                0, END)[0]  # just get the first thing from the recipe list

        e.widget.delete(0, END)
        e.widget.insert(0, name)
        row = db.get_ingredient(name)  # to get the unit
        if row:
            self.unit = row["unit"]
            self.vessel = row["container_name"]
        else:
            row = db.get_recipe(name)
            self.unit = "meal"
            self.vessel = None

        if not row:
            raise KeyError("ingredient or recipe not in db")

        self.unit_entry.delete(
            0, END)  # clear it in case there's something in there
        self.unit_entry.insert(0, self.unit)
Exemplo n.º 3
0
def test_rpc_add_to_inventory():
    db.load_db('Database')

    #making an empty environ dictionary
    environ = {}
    environ['PATH_INFO'] = '/rpc'
    d = dict(method= 'add_recipe',params=['THE DUDE',[("Marco Botros","3 oz"),('vodka','1 liter')]], id=1)
    encoded = simplejson.dumps(d)
    environ['wsgi.input'] = StringIO(encoded) 
    environ['CONTENT_LENGTH'] = len(encoded) 
    environ['REQUEST_METHOD'] = 'POST' 
   
    #making a start_response function 
    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 db.get_recipe('THE DUDE'),db._recipes_db
    assert ('Content-Type', 'application/json') in headers
    assert status == '200 OK'
Exemplo n.º 4
0
def test_get_recipe():
    db._reset_db()
    r = recipes.Recipe('vodka martini', [('vodka', '6 oz'), ('vermouth', '1 oz')])
    db.add_recipe(r)
    x = db.get_recipe('vodka martini')
    
    assert r == x
    if(x):
        print x.name, x.ingredients
Exemplo n.º 5
0
    def add_a_new_recipe_recv(self, environ, start_response):
        print "in add_a_new_recipe_recv"
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)

        name = results['name'][0]
        ings = results['ings'][0]
        indv_ings = ings.split(',')
        ind_list =[]
        for item in indv_ings:
            myTup = tuple(item.split(':'))
            ind_list.append(myTup)
        
        recipe = recipes.Recipe(name,ind_list)
        db.add_recipe(recipe)
        db.save_db('bin/sample_database')
        taste_of_success = db.get_recipe(name)
        if taste_of_success == recipe:
            data = generate_html.generate_recipes_html()
        else:
            content_type = 'text/html'
            data = """  <html>
    <head>
    <title>Failure to add recipe!</title>
        <style type ="text/css">
        h1{color:red;}
    </style>
    </head>
    <body>"""
            data += """Failed to add Recipe, please try again!"""
            data += generate_html.generate_menu()
            data += """
</body>
</html>
"""     
        start_response('200 OK', list(html_headers))
        return [data]
Exemplo n.º 6
0
def test_rpc_AddRecipe():
	
	db._reset_db()
	call_remote(method='AddRecipe', params=['rum and coke', 'rum,2 oz,coke,4 oz'], id=1)
	assert db.get_recipe('rum and coke')