示例#1
0
def test_nx584_watcher_run_with_zone_events():
    """Test the zone events."""
    empty_me = [1, 2]

    def fake_get_events():
        """Return nothing twice, then some events."""
        if empty_me:
            empty_me.pop()
        else:
            return fake_events

    client = mock.MagicMock()
    fake_events = [
        {"zone": 1, "zone_state": True, "type": "zone_status"},
        {"zone": 2, "foo": False},
    ]
    client.get_events.side_effect = fake_get_events
    watcher = nx584.NX584Watcher(client, {})

    @mock.patch.object(watcher, "_process_zone_event")
    def run(fake_process):
        """Run a fake process."""
        fake_process.side_effect = StopMe
        with pytest.raises(StopMe):
            watcher._run()
        assert fake_process.call_count == 1
        assert fake_process.call_args == mock.call(fake_events[0])

    run()
    assert 3 == client.get_events.call_count
 def test_process_zone_event(self, mock_update):
     """Test the processing of zone events."""
     zone1 = {'number': 1, 'name': 'foo', 'state': True}
     zone2 = {'number': 2, 'name': 'bar', 'state': True}
     zones = {
         1: nx584.NX584ZoneSensor(zone1, 'motion'),
         2: nx584.NX584ZoneSensor(zone2, 'motion'),
     }
     watcher = nx584.NX584Watcher(None, zones)
     watcher._process_zone_event({'zone': 1, 'zone_state': False})
     assert not zone1['state']
     assert 1 == mock_update.call_count
示例#3
0
 def test_process_zone_event(self, mock_update):
     """Test the processing of zone events."""
     zone1 = {"number": 1, "name": "foo", "state": True}
     zone2 = {"number": 2, "name": "bar", "state": True}
     zones = {
         1: nx584.NX584ZoneSensor(zone1, "motion"),
         2: nx584.NX584ZoneSensor(zone2, "motion"),
     }
     watcher = nx584.NX584Watcher(None, zones)
     watcher._process_zone_event({"zone": 1, "zone_state": False})
     assert not zone1["state"]
     assert mock_update.call_count == 1
示例#4
0
    def test_run_retries_failures(self, mock_sleep):
        """Test the retries with failures."""
        empty_me = [1, 2]

        def fake_run():
            """Fake runner."""
            if empty_me:
                empty_me.pop()
                raise requests.exceptions.ConnectionError()
            raise StopMe()

        watcher = nx584.NX584Watcher(None, {})
        with mock.patch.object(watcher, "_run") as mock_inner:
            mock_inner.side_effect = fake_run
            with pytest.raises(StopMe):
                watcher.run()
            assert 3 == mock_inner.call_count
        mock_sleep.assert_has_calls([mock.call(10), mock.call(10)])
 def test_process_zone_event_missing_zone(self, mock_update):
     """Test the processing of zone events with missing zones."""
     watcher = nx584.NX584Watcher(None, {})
     watcher._process_zone_event({'zone': 1, 'zone_state': False})
     assert not mock_update.called
示例#6
0
def test_nx584_watcher_process_zone_event_missing_zone(mock_update):
    """Test the processing of zone events with missing zones."""
    watcher = nx584.NX584Watcher(None, {})
    watcher._process_zone_event({"zone": 1, "zone_state": False})
    assert not mock_update.called