def test_create_instruction(self):        
     json = '{ "description" : "Instruction created from web API", "target_temperature_C" : "15.5", "from_timestamp" : "10", "to_timestamp" : "1000" }'        
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/instruction', json, 'application/json')[0]
     assert(response.status == 201)
     assert(len(db_adapter.get_all_instructions()) == 1)
     new_instruction = db_adapter.get_all_instructions()[0]
     assert(new_instruction.target_temperature_C == 15.5)
     assert(new_instruction.from_timestamp == 10)        
     assert(new_instruction.description == 'Instruction created from web API')
 def test_add_modify_delete_instruction(self):
     instruction = Instruction(None, 10, time.time() - 600, time.time(), 'Test Instruction')        
     brew_logic.store_instruction_for_unique_time(instruction)        
     instructions = db_adapter.get_all_instructions()
     assert(len(instructions) == 1)        
     new_description = 'New Description, Bla Bla Bla'
     old_instruction = db_adapter.get_all_instructions()[0]
     old_instruction.description = new_description        
     brew_logic.store_instruction_for_unique_time(old_instruction)
     instructions = db_adapter.get_all_instructions()        
     assert(len(instructions) == 1)
     assert(instructions[0].description == new_description)
     db_adapter.delete_instruction(old_instruction.instruction_id)
     assert(len(db_adapter.get_all_instructions()) == 0)
 def test_instructions_for_times(self):
     instruction1 = Instruction(1, 10, time.time() - 599, time.time() - 100, 'Test instruction low')
     instruction2 = Instruction(2, 30, time.time() - 1200, time.time() - 600, 'Test instruction high')
     brew_logic.store_instruction_for_unique_time(instruction1)        
     brew_logic.store_instruction_for_unique_time(instruction2)        
     assert(len(db_adapter.get_all_instructions()) == 2)        
     assert(len(db_adapter.get_instructions()) == 0)        
     results = db_adapter.get_instructions(time.time() - 300, time.time() - 300)        
     assert(instruction1.target_temperature_C == results[0].target_temperature_C)        
     results = db_adapter.get_instructions(time.time() - 1300, time.time() - 650)        
     assert(instruction2.target_temperature_C == results[0].target_temperature_C)        
     results = db_adapter.get_instructions(time.time() - 700, time.time() - 200)
     assert(len(results) == 2)
 def test_delete_instruction(self):
     instruction = Instruction(1, 15, time.time() - 600, time.time() + 6000, 'Bla bla')
     brew_logic.store_instruction_for_unique_time(instruction)        
     response = self._call_DELETE_with_credentials('http://localhost:8080/chestfreezer/api/instruction/1')[0]
     assert(response.status == 204)        
     assert(len(db_adapter.get_all_instructions()) == 0)