Esempio n. 1
0
class ValveUpdateProcessTest(unittest.TestCase):
    def setUp(self):
        self.valve = Valve()
        self.config_backup = config.copy()

    def tearDown(self):
        config.update(self.config_backup)

    def test_1_process_success(self):
        success = self.valve.valve_update_process()
        self.assertTrue(success)

    def test_2_process_fail_invalid_key(self):
        TestUtils.configure_invalid_product_key()
        success = self.valve.valve_update_process()
        self.assertFalse(success)
        self.assertEqual(self.valve.state, pins.LOW)

    def test_3_process_fail_server_down(self):
        TestUtils.configure_server_down()
        success = self.valve.valve_update_process()
        self.assertFalse(success)
        self.assertEqual(self.valve.state, pins.LOW)
Esempio n. 2
0
class ValveStateUpdateTest(unittest.TestCase):
    def setUp(self):
        self.valve = Valve()

    def test_1_open_close_scenarios(self):
        self.assertEqual(self.valve.state, pins.LOW)
        ops = [pins.LOW, pins.HIGH, pins.HIGH, pins.LOW]
        for state in ops:
            success = self.valve.update(state)
            self.assertTrue(success)
            self.assertEqual(self.valve.state, state)

    def test_2_update_state_None(self):
        self.assertEqual(self.valve.state, pins.LOW)
        success = self.valve.update(None)
        self.assertFalse(success)
        self.assertEqual(self.valve.state, pins.LOW)

    def test_2_update_state_invalid(self):
        self.assertEqual(self.valve.state, pins.LOW)
        success = self.valve.update(-1)
        self.assertFalse(success)
        self.assertEqual(self.valve.state, pins.LOW)
Esempio n. 3
0
 def test_1_valid_request(self):
     valve_info = Valve.get_valve_info()
     self.assertTrue('id' in valve_info)
     self.assertTrue('state' in valve_info)
Esempio n. 4
0
 def setUp(self):
     self.valve = Valve()
     self.config_backup = config.copy()
Esempio n. 5
0
 def setUp(self):
     self.valve = Valve()
Esempio n. 6
0
 def test_2_invalid_request(self):
     TestUtils.configure_invalid_product_key()
     valve_info = {'state': 0}
     success = Valve.send_success(valve_info)
     self.assertFalse(success)
Esempio n. 7
0
 def test_3_server_down(self):
     TestUtils.configure_server_down()
     valve_info = {'state': 0}
     success = Valve.send_success(valve_info)
     self.assertFalse(success)
Esempio n. 8
0
 def test_2_invalid_valve_info(self):
     valve_info = {}
     success = Valve.send_success(valve_info)
     self.assertFalse(success)
Esempio n. 9
0
 def test_1_valid_request(self):
     valve_info = {'state': 0}
     success = Valve.send_success(valve_info)
     self.assertTrue(success)
Esempio n. 10
0
 def test_3_server_down(self):
     TestUtils.configure_server_down()
     valve_info = Valve.get_valve_info()
     self.assertIsNone(valve_info)
Esempio n. 11
0
 def test_2_invalid_request(self):
     TestUtils.configure_invalid_product_key()
     valve_info = Valve.get_valve_info()
     self.assertIsNone(valve_info)
Esempio n. 12
0
import SprinklerLogging
from FlowSensorControl import FlowSensor
from PinsControl import PinsController
from ValveControl import Valve

# App entry point
active = True

# Configure logging
SprinklerLogging.configure_logging()

logger = logging.getLogger(__name__)

# Start components
pins_controller = PinsController()
valve = Valve()
valve.start()
flow_sensor = FlowSensor()
flow_sensor.start()


# Cleanup
def cleanup(sig_num, stack_frame):
    logger.info('Interrupted by sig_num %d. Cleaning up before exit', sig_num)
    valve.stop()
    flow_sensor.stop()
    pins_controller.clean_up()
    global active
    active = False