def tearDown(self) -> None: # Delete any queues and exchanges which are common across many tests connect_to_rabbit(self.test_telegram_commands_handler.rabbitmq) delete_queue_if_exists(self.test_telegram_commands_handler.rabbitmq, self.test_rabbit_queue_name) delete_queue_if_exists( self.test_telegram_commands_handler.rabbitmq, self. test_telegram_commands_handler._telegram_commands_handler_queue) delete_exchange_if_exists(self.test_telegram_commands_handler.rabbitmq, HEALTH_CHECK_EXCHANGE) disconnect_from_rabbit(self.test_telegram_commands_handler.rabbitmq) self.dummy_logger = None self.test_channel_logger = None self.test_command_handlers_logger = None self.rabbitmq = None self.cmd_handlers_rabbit = None self.test_alert = None self.test_channel = None self.test_api = None self.redis = None self.mongo = None self.test_telegram_commands_handler._updater.stop() self.test_telegram_command_handlers = None self.test_telegram_commands_handler = None
def test_send_data(self, config: Dict[str, Any]): route_key = "test.route" CONFIG_QUEUE = "hb_test" try: self.test_config_manager._initialise_rabbitmq() connect_to_rabbit(self.rabbitmq) queue_res = self.rabbitmq.queue_declare(queue=CONFIG_QUEUE, durable=True, exclusive=False, auto_delete=False, passive=False) self.assertEqual(0, queue_res.method.message_count) self.rabbitmq.queue_bind(CONFIG_QUEUE, CONFIG_EXCHANGE, route_key) self.test_config_manager._send_data(copy.deepcopy(config), route_key) # By re-declaring the queue again we can get the number of messages # in the queue. queue_res = self.rabbitmq.queue_declare(queue=CONFIG_QUEUE, durable=True, exclusive=False, auto_delete=False, passive=True) self.assertEqual(1, queue_res.method.message_count) # Check that the message received is what's expected _, _, body = self.rabbitmq.basic_get(CONFIG_QUEUE) self.assertDictEqual(config, json.loads(body)) finally: delete_queue_if_exists(self.rabbitmq, CONFIG_QUEUE) disconnect_from_rabbit(self.test_config_manager._rabbitmq) disconnect_from_rabbit(self.test_config_manager._heartbeat_rabbit)
def test__process_ping_sends_valid_hb(self, mock_is_alive: MagicMock): mock_is_alive.return_value = True expected_output = { 'component_name': self.CONFIG_MANAGER_NAME, 'is_alive': True, 'timestamp': datetime(year=1997, month=8, day=15, hour=10, minute=21, second=33, microsecond=30).timestamp() } HEARTBEAT_QUEUE = "hb_test" try: connect_to_rabbit(self.rabbitmq) self.rabbitmq.exchange_declare(HEALTH_CHECK_EXCHANGE, "topic", False, True, False, False) queue_res = self.rabbitmq.queue_declare(queue=HEARTBEAT_QUEUE, durable=True, exclusive=False, auto_delete=False, passive=False) self.assertEqual(0, queue_res.method.message_count) self.rabbitmq.queue_bind(HEARTBEAT_QUEUE, HEALTH_CHECK_EXCHANGE, "heartbeat.*") self.test_config_manager._initialise_rabbitmq() blocking_channel = self.test_config_manager._rabbitmq.channel method_chains = pika.spec.Basic.Deliver(routing_key="ping") properties = pika.spec.BasicProperties() self.test_config_manager._process_ping(blocking_channel, method_chains, properties, b"ping") # By re-declaring the queue again we can get the number of messages # in the queue. queue_res = self.rabbitmq.queue_declare(queue=HEARTBEAT_QUEUE, durable=True, exclusive=False, auto_delete=False, passive=True) self.assertEqual(1, queue_res.method.message_count) # Check that the message received is a valid HB _, _, body = self.rabbitmq.basic_get(HEARTBEAT_QUEUE) self.assertDictEqual(expected_output, json.loads(body)) finally: delete_queue_if_exists(self.rabbitmq, HEARTBEAT_QUEUE) delete_exchange_if_exists(self.rabbitmq, HEALTH_CHECK_EXCHANGE) disconnect_from_rabbit(self.test_config_manager._rabbitmq) disconnect_from_rabbit(self.test_config_manager._heartbeat_rabbit)
def tearDown(self) -> None: connect_to_rabbit(self.rabbitmq) delete_queue_if_exists(self.rabbitmq, DATA_STORE_MAN_INPUT_QUEUE) delete_exchange_if_exists(self.rabbitmq, HEALTH_CHECK_EXCHANGE) disconnect_from_rabbit(self.rabbitmq) connect_to_rabbit(self.test_rabbit_manager) delete_queue_if_exists(self.test_rabbit_manager, self.test_queue_name) disconnect_from_rabbit(self.test_rabbit_manager) self.dummy_logger = None self.dummy_process = None self.connection_check_time_interval = None self.rabbitmq = None self.test_rabbit_manager = None
def tearDown(self) -> None: connect_to_rabbit(self.rabbitmq) delete_queue_if_exists(self.rabbitmq, STORE_CONFIGS_QUEUE_NAME) delete_exchange_if_exists(self.rabbitmq, CONFIG_EXCHANGE) delete_exchange_if_exists(self.rabbitmq, HEALTH_CHECK_EXCHANGE) disconnect_from_rabbit(self.rabbitmq) connect_to_rabbit(self.test_rabbit_manager) delete_queue_if_exists(self.test_rabbit_manager, self.test_queue_name) disconnect_from_rabbit(self.test_rabbit_manager) self.redis.delete_all_unsafe() self.redis = None self.dummy_logger = None self.connection_check_time_interval = None self.rabbitmq = None self.test_rabbit_manager = None
def tearDown(self) -> None: # flush and consume all from rabbit queues and exchanges connect_to_rabbit(self.rabbitmq) queues = [CONFIG_PING_QUEUE] for queue in queues: delete_queue_if_exists(self.rabbitmq, queue) exchanges = [CONFIG_EXCHANGE, HEALTH_CHECK_EXCHANGE] for exchange in exchanges: delete_exchange_if_exists(self.rabbitmq, exchange) disconnect_from_rabbit(self.rabbitmq) self.rabbitmq = None self.test_config_manager._rabbitmq = None self.test_config_manager._heartbeat_rabbit = None self.test_config_manager = None
def tearDown(self) -> None: connect_to_rabbit(self.rabbitmq) delete_queue_if_exists(self.rabbitmq, ALERT_STORE_INPUT_QUEUE) delete_exchange_if_exists(self.rabbitmq, STORE_EXCHANGE) delete_exchange_if_exists(self.rabbitmq, HEALTH_CHECK_EXCHANGE) disconnect_from_rabbit(self.rabbitmq) connect_to_rabbit(self.test_rabbit_manager) delete_queue_if_exists(self.test_rabbit_manager, self.test_queue_name) disconnect_from_rabbit(self.test_rabbit_manager) self.dummy_logger = None self.connection_check_time_interval = None self.rabbitmq = None self.test_rabbit_manager = None self.redis.delete_all_unsafe() self.redis = None self.mongo.drop_collection(self.parent_id) self.mongo = None self.test_store = None
def tearDown(self) -> None: # Delete any queues and exchanges which are common across many tests connect_to_rabbit(self.test_console_alerts_handler.rabbitmq) delete_queue_if_exists(self.test_console_alerts_handler.rabbitmq, self.test_rabbit_queue_name) delete_queue_if_exists( self.test_console_alerts_handler.rabbitmq, self.test_console_alerts_handler._console_alerts_handler_queue) delete_exchange_if_exists(self.test_console_alerts_handler.rabbitmq, HEALTH_CHECK_EXCHANGE) delete_exchange_if_exists(self.test_console_alerts_handler.rabbitmq, ALERT_EXCHANGE) disconnect_from_rabbit(self.test_console_alerts_handler.rabbitmq) self.dummy_logger = None self.test_channel_logger = None self.rabbitmq = None self.test_channel = None self.test_console_alerts_handler = None self.test_alert = None