Exemplo n.º 1
0
    def recv_inventory_add(self, environ, start_response):
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)

        if ( 'liquor' in results.keys() ):
            liquorStr = results['liquor'][0]
        else:
            liquorStr = "#"

        content_type = 'text/html'

        data = liquorStr
        fp = StringIO(data)
        load_bulk_data.load_inventory(fp)
        data = "Added Liquor: %s<p><a href='./'>Index</a>" % liquorStr

        start_response('200 OK', list(html_headers) )
        return [data]
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_get_liquor_amount_2():
    db._reset_db()

    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    
    data = "Johnnie Walker,Black Label,1000 ml"
    fp = StringIO(data)                 # make this look like a file handle
    n = load_bulk_data.load_inventory(fp)

    amount = db.get_liquor_amount('Johnnie Walker', 'Black Label')
    assert amount == 1000.0, amount
Exemplo n.º 6
0
def test_get_liquor_amount_5():
    db._reset_db()

    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    
    data = "Johnnie Walker,Black Label,1000 ml\nJohnnie Walker,Black Label,50 gallons"
    fp = StringIO(data)                 # make this look like a file handle
    n = load_bulk_data.load_inventory(fp)

    try:
        amount = db.get_liquor_amount('Johnnie Walker', 'Black Label')
        assert 0
    except:
        pass                            # we expect to see an error about gallons
Exemplo n.º 7
0
def start_load_inventory(path):
    db._reset_db()
    
    start_load_bottle_types('test-data/bottle-types-data-1.txt', False)
    
    test_data_path = path
    fp = open(test_data_path, 'r')
    try:
        n = load_bulk_data.load_inventory(fp)
    except db.LiquorMissing:
        print "\nCould not find liquor: Incorrect string for \'load_bulk_data.load_inventory\' in \'%s\'." % test_data_path
        print "Correct usage: \'manufacturer name,liquor name,amount ml\'\n"
        pass
    except ValueError:
        print "\nIncorrect string format for \'load_bulk_data.load_inventory\' in \'%s\'." % test_data_path
        print "Correct usage: \'manufacturer name,liquor name,liquor type\'\n"
        pass
        
    print "\n%s" % db._inventory_db
Exemplo n.º 8
0
 def load_bulk_data_inventory(self,file_name):
     return load_bulk_data.load_inventory(file_name)
Exemplo n.º 9
0
 def rpc_inventory_add( self, item ):
     data = item
     fp = StringIO(data)
     load_bulk_data.load_inventory(fp)