Esempio n. 1
0
def test_rpc_AddToInventory():

	db._reset_db()
	call_remote(method='AddLiquorType', params=['Jack Daniels', 'Old No. 7', 'whiskey'], id=1)
	call_remote(method='AddToInventory', params=['Jack Daniels', 'Old No. 7', '1000 ml'], id=1)

	assert db.check_inventory('Jack Daniels', 'Old No. 7')
Esempio n. 2
0
def test_rpc_add_to_inventory():
    db._reset_db()
    db.add_bottle_type("Marco Botros","vodka","like the moon")
    #db.load_db('Database')

    #making an empty environ dictionary
    environ = {}
    environ['PATH_INFO'] = '/rpc'
    d = dict(method= 'add_to_inventory',params=[("Marco Botros","vodka","3 oz")], 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.check_inventory('Marco Botros', 'vodka'),db._inventory_db
    assert ('Content-Type', 'application/json') in headers
    assert status == '200 OK'
Esempio n. 3
0
    def need_ingredients(self):

        missing_list = []

        bottle_type_list = []
        
	for i in self.ingredients:
	    for item in db._bottle_types_db:
		if  i[0] == item[2]:
		    bottle_type_list.append(item)


        amounts_list = []

	for i in bottle_type_list:
	    if db.check_inventory(i[0], i[1]):
		amount = (i[0], i[2], db.get_liquor_amount(i[0], i[1]))
		amounts_list.append(amount)        
                
        for i in self.ingredients:
            amount = 0.0
            for item in amounts_list: 
                if i[0]==item[1]:
                    if amount < float(item[2]): 
                        amount = float(item[2])
            ing_amount = convert.convert_ml(i[1])            
            if float(amount) < float(ing_amount):
                needed = float(ing_amount)-float(amount)
                needed_tup = (i[0], needed)
                missing_list.append(needed_tup)


	return missing_list
Esempio n. 4
0
def test_rpc_add_to_inventory():
    db._reset_db()
    db.add_bottle_type("Abe Lincoln","Freedom","punch")

    environ = {}
    environ['PATH_INFO'] = '/rpc'
    d = dict(method= 'add_to_inventory',params=[("Abe Lincoln","Freedom","3 oz")], 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.check_inventory('Abe Lincoln', 'Freedom'),db._inventory_db
    assert ('Content-Type', 'application/json') in headers
    assert status == '200 OK'
Esempio n. 5
0
def test_bulk_load_inventory_3():
    db._reset_db()

    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    data = "Johnnie Walker,Black Label,1000 ml\na,b\n"
    fp = StringIO(data)                 # make this look like a file handle
    n = load_bulk_data.load_inventory(fp)
    
    assert db.check_inventory('Johnnie Walker', 'Black Label')
    assert n == 1, n
Esempio n. 6
0
    def need_ingredients(self):

        missing_list = []

        # PUT ALL THE LIQUOR TYPES NEEDED IN A LIST(see if they exist) ===========

        bottle_type_list = []
        
	for i in self.ingredients:
	    for item in db._bottle_types_db:
		if  i[0] == item[2]:
		    bottle_type_list.append(item)

        #print bottle_type_list, "bottle_type_list"

        #=========================================================================


        # CHECK INVENTORY FOR THOSE LIQUORS(put them in a list of tuples)=========

        amounts_list = []

	for i in bottle_type_list:
	    if db.check_inventory(i[0], i[1]):
		amount = (i[0], i[2], db.get_liquor_amount(i[0], i[1]))
		amounts_list.append(amount)


        #print amounts_list, "amounts_list"
            
        
        #=========================================================================

        # CREATE THE MISSING LIST=================================================

        
                
        for i in self.ingredients:
            amount = 0.0
            for item in amounts_list: #replace smaller amount with larger
                if i[0]==item[1]:
                    if amount < float(item[2]): 
                        amount = float(item[2])
            ing_amount = convert.convert_ml(i[1])#convert the ingredient to ml
            
            if float(amount) < float(ing_amount):#compare the amount with ing
                needed = float(ing_amount)-float(amount)
                needed_tup = (i[0], needed)
                missing_list.append(needed_tup)#add to missing list


	return missing_list
Esempio n. 7
0
def test_rpc_addinventory_2():
	db._reset_db()
	db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
	text = call_remote(jsonrpc='1.0', method='addinventory', params = ["Johnnie Walker", "black label", "25 gallon"], id='1')
	
	

	rpc_request = simplejson.loads(text)
	#print rpc_request
        result = rpc_request['result']
	print result
	check = db.check_inventory("Johnnie Walker", "black label")
	assert "Succesfully added." in result
	assert check 
Esempio n. 8
0
    def add_to_inventory_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]
        myBool = db.check_inventory(mfg,liquor)
        if myBool == True:
            intial_amt = db.get_liquor_amount(mfg,liquor)
        else:
            intial_amt = 0
        db.add_to_inventory(mfg, liquor, amount)
        db.save_db('bin/sample_database')
        taste_of_success = db.check_inventory(mfg, liquor)
        amt_success = db.get_liquor_amount(mfg,liquor)
        if taste_of_success == True and amt_success > intial_amt:
            data = generate_html.generate_liquor_types_html()

        else:
            content_type = 'text/html'
            data = """  <html>
    <head>
    <title>Failure to Add Liquor!</title>
        <style type ="text/css">
        h1{color:red;}
    </style>
    </head>
    <body>"""
            data += """Failed to add Liquor type, please try again!"""
            data += generate_html.generate_menu()
            data += """
</body>
</html>
"""     
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 9
0
    def need_ingredients(self):

        # the list we're hoping to return
        missing = []

        found = False

        # go through the ingredients
        for ing in self.ingredients:
            found = False
            # make a tuple to be added eventually
            need = (ing[0], db.convert_to_ml(ing[1]))

            original_needed_amount = need[1]  # ignore this for a while, it will come in handy soon

            # now compare the ingredient type to the types we hve
            for type in db.get_bottle_types():

                # if we know such type exists and that type is in our inventory (by a mfg and a liquor)
                if (type[2] == need[0]) and db.check_inventory(type[0], type[1]):
                    # print "checking "+type[2]+" with mfg= "+type[0]+ " with liquor "+type[1]
                    # see how much liquor is available by that particular mfg and liquor
                    available_amount = db.get_liquor_amount(type[0], type[1])

                    # if we have more than or equal amount of that liquor from that particular mfg and liquor
                    if available_amount >= original_needed_amount:
                        # print "found it :)"
                        # then we're done here, let's move on to the next ingredient (break out of the current/types loop)
                        found = True
                        break

                    else:  # if the amount is not enough

                        # how much is missing? (difference between what we need and what we have)
                        difference_amount = original_needed_amount - available_amount

                        # we will try to find the mfg and liquor with the minimum missing amount. Otherwise, just leave it alone.
                        # I know I could've used min() but this will make thigns look simpler
                        if difference_amount < need[1]:
                            # print "we will replace the current "+str(need[1])+" with the new differnece: "+str(difference_amount)
                            need = (need[0], difference_amount)
                        # else:
                        # print "we will not replace "+str(need[1])+" with the new difference "+str(difference_amount)

            if not found:
                missing.append(need)
        return missing
Esempio n. 10
0
def comment_test():
	db._reset_db()																										#1
	
	mfg = 'Johnnie Walker'																								#2
	name = 'Black Label'
	typ = 'Blended Scotch'
	amt = '1000ml'

	st_typ = "#this comment is not suitable for children\n" + mfg + "," + name + "," + typ + "\n#nor is this one."		#3
	st_amt = "#this comment is not suitable for children\n" + mfg + "," + name + "\n#nor is this one."

	fp_typ = StringIO(st_typ)																							#4
	fp_amt = StringIO(st_amt)

	load_bulk_data.load_bottle_types(fp_typ)																			#5
	assert db._check_bottle_type_exists(mfg, name) == True

	load_bulk_data.load_inventory(fp_amt)																				#6
	assert db.check_inventory(mfg, name) == False
Esempio n. 11
0
def wspace_test():
	db._reset_db()														#1

	mfg = 'Johnnie Walker'												#2
	name = 'Black Label'
	typ = 'Blended Scotch'
	amt = '1000ml'

	st_typ = "\n \n \n" + mfg + "," + name + "," + typ + "\n\n\n"		#3
	st_amt = "\n \n \n" + mfg + "," + name + "\n\n\n"

	fp_typ = StringIO(st_typ)											#4
	fp_amt = StringIO(st_amt)
	
	load_bulk_data.load_bottle_types(fp_typ)							#5
	assert db._check_bottle_type_exists(mfg, name) == True

	load_bulk_data.load_inventory(fp_amt)								#6
	assert db.check_inventory(mfg, name) == False
Esempio n. 12
0
def test_rpc_add_to_inventory():
    db._reset_db()
    
    #Add bottle type first
    db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
    
    mfg = 'Johnnie Walker'
    liquor =  'black label'
    amt =  '500 ml'

    #originalAmt = db.get_liquor_amount(mfg,liquor)
    s, h, result = call_remote('add_to_inventory', [mfg,liquor,amt])

    #Check for valid status
    assert s == '200 OK'

    #Check for correct content
    assert ('Content-Type', 'application/json') in h, h

    #Check if the data has been added to inventory
    assert db.check_inventory(mfg,liquor)
Esempio n. 13
0
def test_rpc_add_to_inventory():
    db._reset_db()

    # Add bottle type first
    db.add_bottle_type("Johnnie Walker", "black label", "blended scotch")

    mfg = "Johnnie Walker"
    liquor = "black label"
    amt = "500 ml"

    s, h, result = call_remote("add_to_inventory", [mfg, liquor, amt])

    # Check for valid status
    assert s == "200 OK"

    # Check for correct content
    assert ("Content-Type", "application/json") in h, h

    # Check if the data has been added to inventory
    assert db.check_inventory(mfg, liquor)

    # Check for correct amount
    assert 500 == db.get_liquor_amount(mfg, liquor)