Exemplo n.º 1
0
def create_beer():
    beer_name = _get_parameter_value('name',True)
    try:
        db_adapter.get_beer_by_name(beer_name)
        abort(400, 'Beer named "' + beer_name + '" already exists')
    except BeerException:
        new_beer = brew_logic.Beer(beer_name, "Undefined", -1, -1, -1, -1, 0)
        db_adapter.store_beer(new_beer);
        response.status = 204
Exemplo n.º 2
0
 def test_beer_status_emails(self):
     # swap out the email sending methods
     def print_email_to_be_sent(beer, is_for_tomorrow, name):
         print 'Send email due to ' + name + ' for beer "' + beer.name + ', for tomorrow: ' + str(is_for_tomorrow) 
     emailer.send_fermentation_email = lambda beer, is_for_tomorrow : print_email_to_be_sent(beer, is_for_tomorrow, 'Fermentation')        
     emailer.send_dryhopping_email = lambda beer, is_for_tomorrow : print_email_to_be_sent(beer, is_for_tomorrow, 'Dryhopping')
     emailer.send_conditioning_email = lambda beer, is_for_tomorrow : print_email_to_be_sent(beer, is_for_tomorrow, 'Conditioning')
     # create the beer
     fermenting_from = datetime.datetime(2014,2,6).strftime("%s")
     fermenting_to = datetime.datetime(2014,2,10).strftime("%s")
     dryhopping_from = datetime.datetime(2014,2,10).strftime("%s")
     dryhopping_to = datetime.datetime(2014,2,14).strftime("%s")
     conditioning_from = datetime.datetime(2014,2,14).strftime("%s")
     conditioning_to = datetime.datetime(2014,2,22).strftime("%s")
     beer = Beer('Random Encounter', 'Hefeweizen', fermenting_from, fermenting_to, conditioning_from, conditioning_to, 7, 'Test Beer', 0, dryhopping_from, dryhopping_to);        
     db_adapter.store_beer(beer)
     print db_adapter.get_beer_by_name('Random Encounter')        
     
     # so as to not wait
     brew_logic._get_seconds_in_day = lambda : 1
     brew_logic._get_seconds_in_hour = lambda : 1
     
     # we start at the specified date
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,01,31);
     brew_logic.start_beer_monitoring_thread()
             
     # nothing should happen, we move the time to one day before  the fermenting starts
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,5);
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,6);
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,9);
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,10);
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,14);
     time.sleep(1)
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,20);
     brew_logic._get_current_datetime = lambda : datetime.datetime(2014,2,22);
     
     # VERIFICATION STILL NEEDS TO OCCUR! I just don't have time for it :p
     brew_logic.should_threads_run = False  # @UndefinedVariable end!
 def test_modify_beer(self):
     beer = brew_logic.Beer('Test Beer', 'Weirdstyle', -1, -1, -1, -1, 4, 'S.M.A.S.H', 10);
     db_adapter.store_beer(beer)
     response = self._call_PUT_with_credentials_and_body('http://localhost:8080/chestfreezer/api/beer/10', '{ "name":"Test Beer Mk2","style":"S.M.A.S.H.","fermenting_from":100000,"fermenting_to":200000,"conditioning_from":300000,"conditioning_to":400000,"rating":10,"comments":"this is cool" }', 'application/json')[0]        
     assert(response.status == 200)
     modified_beer = db_adapter.get_beer_by_name('Test Beer Mk2')
     assert modified_beer.style == 'S.M.A.S.H.'
     assert modified_beer.fermenting_from_timestamp == 82800
     assert modified_beer.fermenting_to_timestamp == 169200
     assert modified_beer.conditioning_from_timestamp == 255600
     assert modified_beer.conditioning_to_timestamp == 342000
     assert modified_beer.rating == 10
     assert modified_beer.comments == "this is cool"
Exemplo n.º 4
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