def test_subscribe_input_events(self): consumer_list = [] def new_consumer(*args): consumer = BackgroundConsumer(*args) consumer_list.append(consumer) return consumer subscriber = mock.Mock() with mock.patch.object(gateway.hal.master_controller_classic, 'BackgroundConsumer', side_effect=new_consumer) as new_consumer: controller = get_classic_controller_dummy() pubsub = get_pubsub() controller._register_version_depending_background_consumers() controller._input_config = {1: InputDTO(id=1)} # TODO: cleanup pubsub.subscribe_master_events(PubSub.MasterTopics.INPUT, subscriber.callback) new_consumer.assert_called() consumer_list[-2].deliver({'input': 1}) pubsub._publish_all_events() try: consumer_list[-2]._consume() except: pass # Just ensure it has at least consumed once expected_event = MasterEvent.deserialize({'type': 'INPUT_CHANGE', 'data': {'id': 1, 'status': True, 'location': {'room_id': 255}}}) subscriber.callback.assert_called_with(expected_event)
def test_subscribe_input_events(self): consumer_list = [] def new_consumer(*args): consumer = BackgroundConsumer(*args) consumer_list.append(consumer) return consumer subscriber = mock.Mock() with mock.patch.object(gateway.hal.master_controller_core, 'BackgroundConsumer', side_effect=new_consumer) as new_consumer: controller = MasterCoreController() self.pubsub.subscribe_master_events(PubSub.MasterTopics.INPUT, subscriber.callback) new_consumer.assert_called() event_data = {'type': 1, 'action': 1, 'device_nr': 2, 'data': {}} with mock.patch.object(Queue, 'get', return_value=event_data): consumer_list[0].deliver() self.pubsub._publish_all_events() expected_event = MasterEvent.deserialize({'type': 'INPUT_CHANGE', 'data': {'id': 2, 'status': True, 'location': {'room_id': 255}}}) subscriber.callback.assert_called_with(expected_event)