示例#1
0
    def add_liquor_type_recv(self, environ, start_response):
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)
        mfg = results['mfg'][0]
        liquor = results['liquor'][0]
        typ = results['typ'][0]
        db.add_bottle_type(mfg, liquor, typ)
        db.save_db('bin/sample_database')
        taste_of_success = db._check_bottle_type_exists(mfg, liquor)
        if taste_of_success == True:
            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]
示例#2
0
    def addbottletype(self, environ, start_response):
    	formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)
	try:
        	mfg = results['mfg'][0]
		liquor = results['liquor'][0]
		type = results['type'][0]
		type = type.strip()
		mfg = mfg.strip()
		liquor = liquor.strip()
		if not db._check_bottle_type_exists(mfg, liquor):
			db.add_bottle_type(mfg,liquor,type)
	 		addin = "<p>Succesfully added.</p>"
		else:
			addin= "<p> This bottle type already exists.</p>"
	except (AssertionError, KeyError, IndexError) :
		addin = """\
		<p> Incorrect format or incomplete. Please try again.</p>
	"""
	vars = dict(form=addin)
	template = env.get_template("add.html")
	data = template.render(vars)
	content_type = 'text/html'
        start_response('200 OK', list(html_headers))
        return [str(data)]
示例#3
0
def test_add_bottle_type_1():
    print 'Note that output from failing tests is printed out!'
    
    db._reset_db()

    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    assert db._check_bottle_type_exists('Johnnie Walker', 'Black Label')
示例#4
0
def test_json_add_liquor_type():
    db._reset_db()

    call_remote(method='add_liquor_type', params=['Johnnie Walker', 'black label',
                                                  'blended scotch'], id=1)

    assert db._check_bottle_type_exists('Johnnie Walker', 'black label')
示例#5
0
def test_rpc_add_liquor_type():
    db.load_db('Database')

    #making an empty environ dictionary
    environ = {}
    environ['PATH_INFO'] = '/rpc'
    d = dict(method= 'add_liquor_type',params=[("Marco Botros","vodka","like the moon")], 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_bottle_type_exists('Marco Botros', 'vodka')
    assert ('Content-Type', 'application/json') in headers
    assert status == '200 OK'
示例#6
0
    def recv_add_liquor_inventory(self, environ, start_response):
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)
	msg = ""
	status = "No values were modified\n"
	#Check if values have data
        if ( ('mfg' in results) and ('liquor' in results) and ('amt' in results)):
	        #Get manufacturer
        	mfg = results['mfg'][0]
        	#Get liquor name
        	liquor = results['liquor'][0]
        	#Get amount
        	amt = results['amt'][0]
 
		#Check if bottle type information is there
        	if not (db._check_bottle_type_exists(mfg,liquor)):
                	message = "Ooops Please add manufacturer and liquor information to bottle types first"
		
        	else:
			#check if amount unit is correct
			if not (amt.endswith('ml') or amt.endswith('oz') or amt.endswith('gallon') or amt.endswith('liter')):
				message = "Ooops unit amount is not correct. "
				msg = "Valid units: 'ml','oz','gallon','liter'"
			else:
                		#Add to inventory
                		db.add_to_inventory(mfg,liquor, amt)
		                dynamic_web.save_database('/../bin/drinkz_database')
                		message = "Added to inventory successfully"
				status = "Updated inventory\n"

	else:
		message = "Ooops at least one of the fields was empty"

        #Generate results in html format
        content_type = 'text/html'
        data= """
        <html>
        <head>
        <title>Updated inventory</title>
        <style type='text/css'>
        h1 {color:red;}
        body{
        font-size:14px;
        }
        </style>
        </head>
        <body>
        """
        data = data + "<h1>" + message + "</h1>"
        tmp = dynamic_web.generate_inventory_table()
        data = data + msg + "<p>" + status + "</p>" + tmp
	
        data = data + "<p><a href='./add_liquor_inventory.html'>add another liquor to inventory</a></p>"
        data = data + "<p><a href='./'>return to index</a></p>"
        data = data + """
        </body>
        <html>
        """
        start_response('200 OK', list(html_headers))
        return [data]
示例#7
0
    def recv3(self, environ, start_response):
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)

        liquorMfg = results['liquorMfg'][0]
        liquorName = results['liquorName'][0]
        liquorAmount = results['liquorAmount'][0]

        bottleTypeExists = db._check_bottle_type_exists(liquorMfg, liquorName)
        if(bottleTypeExists == True):
            db.add_to_inventory(liquorMfg, liquorName, liquorAmount)

        content_type = 'text/html'
        data = """
<!DOCTYPE HTML>
<html>
<head>
<title>Liquor Amount Added</title>
<style type='text/css'>
h1 {text-decoration:underline; text-align:center; color:red;}
body { font-size:14px; }
</style>
</head>
<body>"""
        if(bottleTypeExists == True):
            data += "<h1>Liquor Successfully Added to Inventory!</h1><br/>"
        else:
            data += "<h1>Error! Liquor bottle type could not be found. Liquor not added.</h1>"
        data += "<a href='./'>Return to index</a></body></html>"


        start_response('200 OK', list(html_headers))
        return [data]
示例#8
0
def test_script_load_bottle_types_1():
    db._reset_db()

    scriptpath = 'bin/load-liquor-types'
    module = imp.load_source('llt', scriptpath)
    exit_code = module.main([scriptpath, 'test-data/bottle-types-data-1.txt'])

    assert exit_code == 0, 'non zero exit code %s' % exit_code
    assert db._check_bottle_type_exists('Johnnie Walker', 'Black Label')
示例#9
0
def test_bulk_load_bottle_types_1():
    db._reset_db()

    data = "Johnnie Walker,Black Label,blended scotch"
    fp = StringIO(data)                 # make this look like a file handle
    n = load_bulk_data.load_bottle_types(fp)

    assert db._check_bottle_type_exists('Johnnie Walker', 'Black Label')
    assert n == 1, n
示例#10
0
def test_rpc_addtype_1():
	db._reset_db()
	text = call_remote(jsonrpc='1.0', method='addtype', params = ["Johnnie Walker", "black label", "scotch"], id='1')
	
	rpc_request = simplejson.loads(text)
        result = rpc_request['result']
	print result
	check = db._check_bottle_type_exists("Johnnie Walker", "black label")
	assert "Succesfully added." in result
	assert check 
示例#11
0
    def recv_add_liquor_types(self, environ, start_response):
	formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)
	msg = "No values were modified"
	#Check if values have data
	if ( ('mfg' in results) and ('liquor' in results) and ('typ' in results)):
        	#Get manufacturer
		mfg = results['mfg'][0]
        	#Get liquor name
        	liquor = results['liquor'][0]
		#Get type
		typ = results['typ'][0]
  
		if (db._check_bottle_type_exists(mfg,liquor)):
			message = "Ooops Manufacturer and Liquor information was already there"
		else:
			#Add bottle type
			db.add_bottle_type(mfg,liquor,typ)
			dynamic_web.save_database('/../bin/drinkz_database')
			message = "Liquor type has been added successfully"
			msg = "Liquor type has been added"

	#At least one of the fields is empty
	else:
		message = "Ooops at least one of the fields was empty"

        #Generate results in html format
        content_type = 'text/html'
        data= """
        <html>
        <head>
        <title>Updated Liquor Type</title>
        <style type='text/css'>
        h1 {color:red;}
        body{
        font-size:14px;
        }
        </style>
	</head>
        <body>
	"""
        data = data + "<h1>" + message + "</h1>"
	data = data + msg 
	tmp = dynamic_web.generate_liquor_type_table()
	data = data + tmp
	data = data + "<p><a href='./add_liquor_types.html'>add another liquor type</a></p>"
        data = data + "<p><a href='./'>return to index</a></p>"
        data = data + """
        </body>
        <html>
        """
        start_response('200 OK', list(html_headers))
        return [data]
示例#12
0
def test_script_load_inventory_1():
    db._reset_db()

    scriptpath = 'bin/load-liquor-inventory'
    module = imp.load_source('llt', scriptpath)
    exit_code = module.main([scriptpath, 'test-data/bottle-types-data-1.txt', 'test-data/inventory-data-1.txt'])

    assert exit_code == 0, 'non zero exit code %s' % exit_code

    assert db._check_bottle_type_exists('Johnnie Walker', 'Black Label')
    
    amount = db.get_liquor_amount('Johnnie Walker', 'Black Label')
    assert amount == 1234.0, amount
示例#13
0
    def rpc_addtype(self,mfg,liquor,type):
	try:
		type = type.strip()
		mfg = mfg.strip()
		liquor = liquor.strip()
		if not db._check_bottle_type_exists(mfg, liquor):
			db.add_bottle_type(mfg,liquor,type)
	 		addin = "Succesfully added."
		else:
			addin= " This bottle type already exists."
	except (AssertionError, KeyError, IndexError) :
		addin = """\
		 Incorrect format or incomplete. Please try again.
	"""
	return addin
示例#14
0
def test_rpc_add_bottle_type():
    db._reset_db()
    
    mfg = 'Johnnie Walker'
    liquor =  'black label'
    type =  'blended scotch'

    s, h, result = call_remote('add_bottle_type', [mfg,liquor,type])

    #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 bottle type
    assert db._check_bottle_type_exists(mfg,liquor)
示例#15
0
def test_rpc_add_bottle_type():
    db._reset_db()

    mfg = "Johnnie Walker"
    liquor = "black label"
    type = "blended scotch"

    s, h, result = call_remote("add_bottle_type", [mfg, liquor, type])

    # 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 bottle type
    assert db._check_bottle_type_exists(mfg, liquor)
示例#16
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
示例#17
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
示例#18
0
 def add_to_event(self, dest, mfg, liq, amt):
     if not dest == "req" and not dest == "inv":
         print "The 'dest' parameter must be 'req' or 'inv'"
         return
     
     if not db._check_bottle_type_exists(mfg, liq):
         err = "Missing liquor: manufacturer '%s', name '%s'" % (mfg, liq)
         raise db.LiquorMissing(err)
     
     if dest == "req":
         if not self.check_requests(mfg, liq):
             self.requested_items[(mfg, liq)] = db.to_ml(amt)
         else:
             self.requested_items[(mfg, liq)] += db.to_ml(amt)
     elif dest == "inv":
         if not self.check_inventory(mfg, liq):
             self.inventory[(mfg, liq)] = db.to_ml(amt)
         else:
             self.inventory[(mfg, liq)] += db.to_ml(amt)
示例#19
0
    def recvLiquorTypes(self, environ, start_response):
        formdata = environ['QUERY_STRING']

        results = urlparse.parse_qs(formdata)

        mfg = results['man'][0]
        name = results['name'][0]
        typ = results['type'][0]

        db.add_bottle_type(mfg, name, typ)
        if db._check_bottle_type_exists(mfg, name):
            print "ITS IN THE DATABASE"
        else:
            print "ITS NOT IN THE DATABASE"

        content_type = 'text/html'
        data = "%s <a href='/'>return to index</a>" % "Your liquor type has been added"

        start_response('200 OK', list(html_headers))
        return [data]
示例#20
0
def test_rpc_AddLiquorType():

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