Exemplo n.º 1
0
def test_add_recipe():
    db._reset_db()
    r = recipes.Recipe('vodka martini', [('vodka', '6 oz'), ('vermouth', '1 oz')])
    db.add_recipe(r)

    assert len(db._recipe_db) == 1
    print db._recipe_db
Exemplo n.º 2
0
def test_get_liquor_amount_1():
    db._reset_db()

    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    db.add_to_inventory('Johnnie Walker', 'Black Label', '1000 ml')
    amount = db.get_liquor_amount('Johnnie Walker', 'Black Label')
    assert amount == 1000.0, amount
Exemplo n.º 3
0
def test_app():
    db._reset_db()
    recipe1 = recipes.Recipe('vodka martini', [('vermouth', '1.5 oz')])

    recipe2 =  recipes.Recipe('vomit inducing martini', [('blended scotch',
                                                          '2 oz'),
                                                         ('unflavored vodka',
                                                          '1.5 oz')])

    db.add_recipe(recipe1)
    db.add_recipe(recipe2)
    
    environ = {}
    environ['PATH_INFO'] = '/recipes'
    
    
    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 text.find('vodka martini') != -1, text
    assert text.find('vomit inducing martini') != -1, text
    assert ('Content-type', 'text/html') in headers
    assert status == '200 OK'
Exemplo n.º 4
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'
Exemplo n.º 5
0
def test_app_recipes():

    db._reset_db()

    r = recipes.Recipe('scotch on the rocks', [('blended scotch', '4 oz')])
    db.add_recipe(r)

    r2 = recipes.Recipe('vomit inducing martini', [('orange juice', '6 oz'), ('vermouth', '1.5 oz')])
    db.add_recipe(r2)

    r3 = recipes.Recipe('whiskey bath', [('blended scotch', '6 liter')])
    db.add_recipe(r3)

    environ = {}
    environ['PATH_INFO'] = '/recipes'

    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 text.find('scotch on the rocks') != -1, text
    assert text.find('vomit inducing martini') != -1, text
    assert text.find('whiskey bath') != -1, text
    assert ('Content-type', 'text/html') in headers
    assert status == '200 OK'
Exemplo n.º 6
0
def test_getinventory():
	db._reset_db() #Reset database
	db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
	db.add_to_inventory('Johnnie Walker', 'black label', '500 ml')

	db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch')
	db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter')
        
	db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
	db.add_to_inventory('Gray Goose', 'vodka', '1 liter')

	db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth')
	db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz')

	
	
	text = call_remote(jsonrpc='1.0', method='get_liquor_inventory', params = [], id='1')
	rpc_request = simplejson.loads(text)
	print rpc_request
        result = rpc_request['result']
	assert result[0][0] == 'Johnnie Walker'
	assert result[0][1] == 'black label'
	assert result[2][1] == 'moonshine'
	assert result[3][0] == 'Gray Goose'
	assert result[1][1] == 'extra dry vermouth'
Exemplo n.º 7
0
def test_get_mixable_recipes():
    db._reset_db()
    
    db.add_bottle_type('Johnnie Walker', 'Black Label', 'blended scotch')
    db.add_to_inventory('Johnnie Walker', 'Black Label', '1000 ml')
    
    db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch')
    db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter')
        
    db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
    db.add_to_inventory('Gray Goose', 'vodka', '1 liter')

    db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth')
    db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz')
    
    db.add_bottle_type('Meijer', 'pulp free orange juice', 'orange juice')
    db.add_to_inventory('Meijer', 'pulp free orange juice', '24 oz')
    
    r = recipes.Recipe('scotch on the rocks', [('blended scotch',
                                                   '4 oz')])
    db.add_recipe(r)
    
    r = recipes.Recipe('vodka gimlit', [('unflavored vodka', '4 oz'), ('lime juice', '1 oz')])
    db.add_recipe(r)
    
    r = recipes.Recipe('vomit inducing martini', [('orange juice',
                                                      '6 oz'),
                                                     ('vermouth',
                                                      '1.5 oz')])
    db.add_recipe(r)
    
    mixable_recs = db.get_mixable_recipes()
    
    for rec in mixable_recs:
        print rec.name
Exemplo n.º 8
0
def test_json_liquor_inventory():
    db._reset_db()
    db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
    db.add_to_inventory('Johnnie Walker', 'black label', '500 ml')

    db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch')
    db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter')
        
    db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
    db.add_to_inventory('Gray Goose', 'vodka', '1 liter')

    db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth')
    db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz')

    liquor_inventory = call_remote(method='get_liquor_inventory', params = [], id='1')

    rpc_request = simplejson.loads(liquor_inventory)

    result = rpc_request['result']

    
    print result

    assert ['Johnnie Walker', 'black label'] in result
    assert ['Rossi', 'extra dry vermouth'] in result
    assert ["Uncle Herman's", 'moonshine'] in result
    assert ['Gray Goose', 'vodka'] in result
Exemplo n.º 9
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'
Exemplo n.º 10
0
def test_rpc_get_recipe_names():
    db._reset_db()
    recipe1 = recipes.Recipe("youth fountain martini", [("vermouth", "1.5 oz"), ("elve tear", "2 oz")])
    recipe2 = recipes.Recipe("godly vodka", [("mermaid tear", "1.5 oz"), ("unicorn blood", "2 oz")])
    db.add_recipe(recipe1)
    db.add_recipe(recipe2)

    method = "get_recipe_names"
    params = []
    id = 1
    environ = {}
    environ["PATH_INFO"] = "/rpc"
    environ["REQUEST_METHOD"] = "POST"
    dic = dict(method=method, params=params, id=id)
    s_input = simplejson.dumps(dic)
    environ["wsgi.input"] = StringIO(s_input)  # looking for a socket? suuuuure, here's "one"
    environ["CONTENT_LENGTH"] = len(s_input)

    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 text.find("youth fountain martini") != -1, text
    assert text.find("godly vodka") != -1, text

    assert ("Content-Type", "application/json") in headers
    assert status == "200 OK"
Exemplo n.º 11
0
def add_items():
        #Reset database
        db._reset_db()

	db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
	db.add_to_inventory('Johnnie Walker', 'black label', '500 ml')

	db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch')
	db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter')
        
	db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
	db.add_to_inventory('Gray Goose', 'vodka', '1 liter')

	db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth')
	db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz')

	#Add recipes
	r = recipes.Recipe('scotch on the rocks', [('blended scotch','4 oz')])
	db.add_recipe(r)
	r = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'),('vermouth', '1.5 oz')])
	db.add_recipe(r)
	r = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')])
	db.add_recipe(r)
	r = recipes.Recipe('whiskey bath', [('blended scotch', '2 liter')])
	db.add_recipe(r)
Exemplo n.º 12
0
def test_rpc_get_recipe_names():
    db._reset_db()
    recipe1 = recipes.Recipe('Equalizer', [('punch', '1 oz'),('Freedom','2 oz')])

    db.add_recipe(recipe1)
    
    method = 'get_recipe_names'
    params = []
    id = 1
    environ = {}
    environ['PATH_INFO'] = '/rpc'
    environ['REQUEST_METHOD'] = ('POST')
    dic = dict(method=method, params=params, id=id)
    s_input = simplejson.dumps(dic)
    environ['wsgi.input'] = StringIO(s_input)    # looking for a socket? suuuuure, here's "one"
    environ['CONTENT_LENGTH'] = len(s_input)
    
    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 text.find("Equalizer") != -1, text
 
    assert ('Content-Type', 'application/json') in headers
    assert status == '200 OK'
Exemplo n.º 13
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')
Exemplo n.º 14
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')
Exemplo n.º 15
0
def test_rpc_GetLiquorInventory():
	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)
	results = call_remote(method='GetLiquorInventory', params=[], id=1)

	assert results['result'] == [['Jack Daniels', 'Old No. 7']]
Exemplo n.º 16
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.º 17
0
def create_data(filename):
	try:
		db.load_db(filename)
	except Exception:
		db._reset_db()

		db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
		db.add_to_inventory('Johnnie Walker', 'black label', '1 gallon')
		db.add_to_inventory('Johnnie Walker', 'black label', '500 ml')

		db.add_bottle_type('Uncle Herman\'s', 'moonshine', 'blended scotch')
		db.add_to_inventory('Uncle Herman\'s', 'moonshine', '5 liter')

		db.add_bottle_type('Gray Goose', 'vodka', 'unflavored vodka')
		db.add_to_inventory('Gray Goose', 'vodka', '1 liter')

		db.add_bottle_type('Rossi', 'extra dry vermouth', 'vermouth')
		db.add_to_inventory('Rossi', 'extra dry vermouth', '24 oz')

		db.add_bottle_type('Jose Cuervo', 'Silver', 'tequila')
		db.add_to_inventory('Jose Cuervo', 'Silver', '1 liter')

		r = recipes.Recipe('scotch on the rocks', [('blended scotch','4 oz')])
		db.add_recipe(r)
		r = recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'),('vermouth', '1.5 oz')])
		db.add_recipe(r)
		r = recipes.Recipe('vomit inducing martini', [('orange juice','6 oz'),('vermouth','1.5 oz')])
		db.add_recipe(r)
		r = recipes.Recipe('whiskey bath', [('blended scotch', '2 liter')])
		db.add_recipe(r)
Exemplo n.º 18
0
def test_rpc_add_recipe():
    db._reset_db()

    name = "whiskey bath"
    ingred = [("blended scotch", "5.5 liter")]
    method = "add_recipe"
    params = [name, ingred]
    id = 1
    environ = {}
    environ["PATH_INFO"] = "/rpc"
    environ["REQUEST_METHOD"] = "POST"
    dic = dict(method=method, params=params, id=id)
    s_input = simplejson.dumps(dic)
    environ["wsgi.input"] = StringIO(s_input)  # looking for a socket? suuuuure, here's "one"
    environ["CONTENT_LENGTH"] = len(s_input)

    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 text.find("Added One Recipe") != -1, text

    assert ("Content-Type", "application/json") in headers
    assert status == "200 OK"
Exemplo n.º 19
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')
Exemplo n.º 20
0
def test_rpc_addinventory_1():
	text = call_remote(jsonrpc='1.0', method='addinventory', params = ["Greyer", "goose", "25 gallon"], id='1')
	db._reset_db()
	rpc_request = simplejson.loads(text)
	#print rpc_request
        result = rpc_request['result']
	print result
	assert "You must first add this bottle" in result
Exemplo n.º 21
0
def test_bulk_load_bottle_types_4():
    db._reset_db()

    data = "a,b"
    fp = StringIO(data)                 # make this look like a file handle
    n = load_bulk_data.load_bottle_types(fp)

    assert n == 0, n
Exemplo n.º 22
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.º 23
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
Exemplo n.º 24
0
def test_rpc_addtype_2():
	db._reset_db()
	db.add_bottle_type('Johnnie Walker', 'black label', 'blended scotch')
	text = call_remote(jsonrpc='1.0', method='addtype', params = ["Johnnie Walker", "black label", "blended scotch"], id='1')
	
	rpc_request = simplejson.loads(text)
        result = rpc_request['result']
	print result
	assert "This bottle type already exists." in result
Exemplo n.º 25
0
def test_add_to_inventory_2():
    db._reset_db()

    try:
        db.add_to_inventory('Johnnie Walker', 'Black Label', '1000 ml')
        assert False, 'the above command should have failed!'
    except db.LiquorMissing:
        # this is the correct result: catch exception.
        pass
Exemplo n.º 26
0
def test_json_recipe_names():
    db._reset_db()

    r = recipes.Recipe('scotch on the rocks', [('blended scotch', '4 oz')])
    db.add_recipe(r)

    results = call_remote(method='get_recipe_names', params=[], id=1)

    assert 'scotch on the rocks' in results['result'], results['result']
Exemplo n.º 27
0
def test_json_add_to_inventory():
    db._reset_db()

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

    assert db.get_liquor_amount('Johnnie Walker', 'black label') == 118.294
Exemplo n.º 28
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')
Exemplo n.º 29
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 
Exemplo n.º 30
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