def test_defer_chain_apply_need_pre_defer_copy(self):
     chain_applies = self._mock_chain_applies()
     port = self._fake_port()
     device2port = {port["device"]: port}
     self.firewall.prepare_port_filter(port)
     with self.firewall.defer_apply():
         self.firewall.remove_port_filter(port)
     chain_applies.assert_has_calls(
         [call.remove({}), call.setup(device2port), call.remove(device2port), call.setup({})]
     )
 def test_defer_chain_apply_need_pre_defer_copy(self):
     chain_applies = self._mock_chain_applies()
     port = self._fake_port()
     device2port = {port['device']: port}
     self.firewall.prepare_port_filter(port)
     with self.firewall.defer_apply():
         self.firewall.remove_port_filter(port)
     chain_applies.assert_has_calls([call.remove({}),
                                     call.setup(device2port),
                                     call.remove(device2port),
                                     call.setup({})])
 def test_mock_chain_applies(self):
     chain_applies = self._mock_chain_applies()
     port_prepare = {'device': 'd1', 'mac_address': 'prepare'}
     port_update = {'device': 'd1', 'mac_address': 'update'}
     self.firewall.prepare_port_filter(port_prepare)
     self.firewall.update_port_filter(port_update)
     self.firewall.remove_port_filter(port_update)
     chain_applies.assert_has_calls([call.remove({}),
                                     call.setup({'d1': port_prepare}),
                                     call.remove({'d1': port_prepare}),
                                     call.setup({'d1': port_update}),
                                     call.remove({'d1': port_update}),
                                     call.setup({})])
 def test_mock_chain_applies(self):
     chain_applies = self._mock_chain_applies()
     port_prepare = {'device': 'd1', 'mac_address': 'prepare'}
     port_update = {'device': 'd1', 'mac_address': 'update'}
     self.firewall.prepare_port_filter(port_prepare)
     self.firewall.update_port_filter(port_update)
     self.firewall.remove_port_filter(port_update)
     chain_applies.assert_has_calls([call.remove({}),
                                     call.setup({'d1': port_prepare}),
                                     call.remove({'d1': port_prepare}),
                                     call.setup({'d1': port_update}),
                                     call.remove({'d1': port_update}),
                                     call.setup({})])
Beispiel #5
0
    def test_marker_interfaces(self):
        # return {Type:None}
        # don't pass when a requirement is for a type but value is None
        class Marker(object):
            pass

        m = Mock()

        def setup():
            m.setup()
            return {Marker: nothing}

        @requires(Marker)
        def use():
            m.use()

        runner = Runner()
        runner.add(setup, returns=returns_mapping(), label='setup')
        runner['setup'].add(use)
        runner()

        compare([
            call.setup(),
            call.use(),
        ], m.mock_calls)
 def test_defer_chain_apply_coalesce_simple(self):
     chain_applies = self._mock_chain_applies()
     port = self._fake_port()
     with self.firewall.defer_apply():
         self.firewall.prepare_port_filter(port)
         self.firewall.update_port_filter(port)
         self.firewall.remove_port_filter(port)
     chain_applies.assert_has_calls([call.remove({}), call.setup({})])
 def test_defer_chain_apply_coalesce_simple(self):
     chain_applies = self._mock_chain_applies()
     port = self._fake_port()
     with self.firewall.defer_apply():
         self.firewall.prepare_port_filter(port)
         self.firewall.update_port_filter(port)
         self.firewall.remove_port_filter(port)
     chain_applies.assert_has_calls([call.remove({}), call.setup({})])
 def test_mock_chain_applies(self):
     chain_applies = self._mock_chain_applies()
     port_prepare = {"device": "d1", "mac_address": "prepare"}
     port_update = {"device": "d1", "mac_address": "update"}
     self.firewall.prepare_port_filter(port_prepare)
     self.firewall.update_port_filter(port_update)
     self.firewall.remove_port_filter(port_update)
     chain_applies.assert_has_calls(
         [
             call.remove({}),
             call.setup({"d1": port_prepare}),
             call.remove({"d1": port_prepare}),
             call.setup({"d1": port_update}),
             call.remove({"d1": port_update}),
             call.setup({}),
         ]
     )
 def test_defer_chain_apply_coalesce_multiple_ports(self):
     chain_applies = self._mock_chain_applies()
     port1 = {"device": "d1", "mac_address": "mac1"}
     port2 = {"device": "d2", "mac_address": "mac2"}
     device2port = {"d1": port1, "d2": port2}
     with self.firewall.defer_apply():
         self.firewall.prepare_port_filter(port1)
         self.firewall.prepare_port_filter(port2)
     chain_applies.assert_has_calls([call.remove({}), call.setup(device2port)])
 def test_defer_chain_apply_coalesce_multiple_ports(self):
     chain_applies = self._mock_chain_applies()
     port1 = {'device': 'd1', 'mac_address': 'mac1'}
     port2 = {'device': 'd2', 'mac_address': 'mac2'}
     device2port = {'d1': port1, 'd2': port2}
     with self.firewall.defer_apply():
         self.firewall.prepare_port_filter(port1)
         self.firewall.prepare_port_filter(port2)
     chain_applies.assert_has_calls([call.remove({}),
                                     call.setup(device2port)])
 def test_defer_chain_apply_coalesce_multiple_ports(self):
     chain_applies = self._mock_chain_applies()
     port1 = {'device': 'd1', 'mac_address': 'mac1'}
     port2 = {'device': 'd2', 'mac_address': 'mac2'}
     device2port = {'d1': port1, 'd2': port2}
     with self.firewall.defer_apply():
         self.firewall.prepare_port_filter(port1)
         self.firewall.prepare_port_filter(port2)
     chain_applies.assert_has_calls([call.remove({}),
                                     call.setup(device2port)])
 def test_test_start_triggered(self, epm):
     mcp1 = epm.devcfg.devices['MCP1']
     mcp1.input = Mock(return_value=True)
     assert epm.test_start_triggered() == False
     mcp1.input = Mock(return_value=False)
     assert epm.test_start_triggered() == True
     assert mcp1.mock_calls == [
         call.setup(1, 1),
         call.pullup(1, True),
         call.input(1),
         call.input(1)
     ]
Beispiel #13
0
    def test_marker_interfaces(self):
        # return {Type:None}
        # don't pass when a requirement is for a type but value is None
        class Marker(object): pass

        m = Mock()
        
        def setup():
            m.setup()
            return {Marker: nothing}

        @requires(Marker)
        def use():
            m.use()

        Runner(use, setup)()
        
        compare([
                call.setup(),
                call.use(),
                ], m.mock_calls)
    def test_configure_pins(self, dc, yaml1):
        device_mock = Mock(name='device')
        dc.device = Mock(return_value=device_mock)
        dc.initialize_input_pins(yaml1)
        dc.initialize_output_pins(yaml1)
        dc.configure_pins()

        assert device_mock.mock_calls == [
            call.setup(1, GPIO.IN),
            call.pullup(1, True),
            call.setup(2, GPIO.IN),
            call.pullup(2, True),
            call.setup(3, GPIO.IN),
            call.setup(5, GPIO.OUT),
            call.setup(4, GPIO.OUT),
            call.setup(6, GPIO.OUT)
        ]
Beispiel #15
0
    def test_marker_interfaces(self):
        # return {Type:None}
        # don't pass when a requirement is for a type but value is None
        class Marker(object): pass

        m = Mock()

        def setup():
            m.setup()
            return {Marker: nothing}

        @requires(Marker)
        def use():
            m.use()

        runner = Runner()
        runner.add(setup, returns=returns_mapping(), label='setup')
        runner['setup'].add(use)
        runner()

        compare([
                call.setup(),
                call.use(),
                ], m.mock_calls)
    def test_init_setup(self, GPIO):
        from hocuspocus.door_controller import DoorController

        door_controller = DoorController(GPIO)
        expected_calls = [
            call.setup(
                door_controller.relay_1.read,
                GPIO.IN,
                pull_up_down=GPIO.PUD_DOWN
            ),
            call.setup(
                door_controller.relay_2.read,
                GPIO.IN,
                pull_up_down=GPIO.PUD_DOWN
            ),
            call.setup(
                door_controller.relay_1.engage,
                GPIO.OUT,
                pull_up_down=GPIO.PUD_DOWN
            ),
            call.setup(
                door_controller.relay_2.engage,
                GPIO.OUT,
                pull_up_down=GPIO.PUD_DOWN
            ),
            call.setup(
                door_controller.red_pin,
                GPIO.OUT,
                pull_up_down=GPIO.PUD_DOWN
            ),
            call.setup(
                door_controller.green_pin,
                GPIO.OUT,
                pull_up_down=GPIO.PUD_DOWN
            ),
        ]

        for expected, actual in zip(expected_calls, GPIO.mock_calls):
            assert actual == expected