예제 #1
0
def check_hardware(skip_keyboard_input = False):    
    # first the GPIO pins        
    sound_check_passed = 'skip-gpio-test' in sys.argv;
    while not sound_check_passed:
        print 'Checking device control - you should hear both devices turn on/off or off/on...'
        time.sleep(1)
        try:
            chestfreezer_gpio.output_pin_for_time(configuration.heater_pin(), False, 1)            
            time.sleep(1)                        
            chestfreezer_gpio.output_pin_for_time(configuration.freezer_pin(), False, 1)
        except ValueError as e:            
            sys.exit('Pins could not be activated, reason:\n' + str(e) + '\nTerminating.')
        try:
            if skip_keyboard_input: raise termios.error
            # eclipse cannot handle this!
            sound_check_passed = do_sound_check()
        except termios.error:
            print 'You are using eclipse or some other IDE or are running tests, check passed.'
            sound_check_passed = True  
    print 'GPIO pins #' + configuration.heater_pin() + ' and #' + configuration.freezer_pin() + ' connected correctly.'            
    
    # then the temperature sensor(s)
    temperature_probes.initialize_probes()
    probes = temperature_probes.probe_ids        
    if probes is None:    
        sys.exit('No temperature probes were detected, check your wiring. Terminating.')
    else:
        print 'Found ' + str(len(probes)) + ' functional temperature sensor(s).'
        temperature_probes.determine_master_probe()
        if 'insert-test-data' in sys.argv:                        
            data_for_testing.insert_dummy_temperatures()                
 def test_get_temperatures(self):
     """ gets all the temperatures """
     data_for_testing.insert_dummy_temperatures(10)        
     response, content = self._call_GET_with_credentials('http://localhost:8080/chestfreezer/api/temperature')         
     assert(response.status == 200)        
     data = json.loads(content)
     assert(len(data) == 30)
 def test_get_temperatures_for_timestamps(self):
     """ asks for temperatures within time bounds """
     data_for_testing.insert_dummy_temperatures(20)
     startMillis = str(int(time.time()) - 70)  # a little over a  minute ago        
     endMillis = str(int(time.time()))
     response, content = self._call_GET_with_credentials('http://localhost:8080/chestfreezer/api/temperature?start=' + startMillis + '&end=' + endMillis)        
     assert(response.status == 200)                
     data = json.loads(content)
     assert(len(data) == 6)
예제 #4
0
 def test_get_temperature_readings(self):        
     data_for_testing.insert_dummy_temperatures(10)
     startSeconds = str(int(time.time()) - 30)  # less than one minute ago        
     endSeconds = str(int(time.time()))
     result = db_adapter.get_temperature_readings(startSeconds, endSeconds)
     assert(len(result) == 3)
     startSeconds = str(int(time.time()) - 70)  # should go over one minute
     result = db_adapter.get_temperature_readings(startSeconds, endSeconds)
     assert(len(result) == 6)        
     result = db_adapter.get_temperature_readings(0, 0)
     assert(len(result) == 0)