Пример #1
0
def delete_beer(beer_id):
    try:
        beer = db_adapter.get_beer_by_id(beer_id)
        db_adapter.delete_beer_by_name(beer.name)
        response.status = 204
    except BeerException:
        abort(404, 'Beer with id "' + beer_id + '" does not exist')
Пример #2
0
 def test_store_retrieve_beer(self):
     new_beer = Beer('Random Encounter', 'Hefeweizen', time.time() - 20000, time.time() - 10000, time.time() - 4900, time.time(), 7, 'Awesome hefe!', dryhopping_from_timestamp = (time.time() - 10000), dryhopping_to_timestamp = (time.time() - 5000))
     assert len(db_adapter.get_all_beers()) == 0
     db_adapter.store_beer(new_beer)
     assert len(db_adapter.get_all_beers()) == 1
     try:
         assert len(db_adapter.get_beer_by_name('wrong_name'))
         assert False                 
     except BeerException:
         pass #all good, beer did not exist (as expected)                
     retrieved_beer = db_adapter.get_beer_by_name('Random Encounter')
     assert retrieved_beer.name == new_beer.name
     # also modify some data
     retrieved_beer.name = 'Random Encounter Mk2'
     retrieved_beer.comments = 'Improved version!'
     retrieved_beer.rating = 10
     retrieved_beer._verifyDataMakeSense();
     db_adapter.store_beer(retrieved_beer)
     twice_retriever = db_adapter.get_beer_by_name('Random Encounter Mk2')
     assert twice_retriever.rating == 10
     db_adapter.delete_beer_by_name('Random Encounter Mk2')
     assert len(db_adapter.get_all_beers()) == 0
     print new_beer