Ejemplo 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'
Ejemplo n.º 2
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'
Ejemplo n.º 3
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
Ejemplo n.º 4
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]
Ejemplo n.º 5
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')