async def test_healthcheck_with_connector(self): activity = Activity( type=ActivityTypes.invoke, name="healthcheck", ) adapter = TestInvokeAdapter() turn_context = TurnContext(adapter, activity) mock_connector_client = MockConnectorClient() turn_context.turn_state[ BotAdapter.BOT_CONNECTOR_CLIENT_KEY] = mock_connector_client bot = ActivityHandler() await bot.on_turn(turn_context) self.assertIsNotNone(adapter.activity) self.assertIsInstance(adapter.activity.value, InvokeResponse) self.assertEqual(adapter.activity.value.status, 200) response = HealthCheckResponse.deserialize(adapter.activity.value.body) self.assertTrue(response.health_results.success) self.assertEqual(response.health_results.authorization, "Bearer awesome") self.assertEqual(response.health_results.user_agent, USER_AGENT) self.assertTrue(response.health_results.messages) self.assertEqual(response.health_results.messages[0], "Health check succeeded.")
async def test_healthcheck(self): activity = Activity(type=ActivityTypes.invoke, name="healthcheck",) adapter = TestInvokeAdapter() turn_context = TurnContext(adapter, activity) bot = ActivityHandler() await bot.on_turn(turn_context) self.assertIsNotNone(adapter.activity) self.assertIsInstance(adapter.activity.value, InvokeResponse) self.assertEqual(adapter.activity.value.status, 200) response = HealthCheckResponse.deserialize(adapter.activity.value.body) self.assertTrue(response.health_results.success) self.assertTrue(response.health_results.messages) self.assertEqual(response.health_results.messages[0], "Health check succeeded.")
def create_healthcheck_response( connector_client: ConnectorClient, ) -> HealthCheckResponse: # A derived class may override this, however, the default is that the bot is healthy given # we have got to here. health_results = HealthResults(success=True) if connector_client: health_results.authorization = "{} {}".format( "Bearer", connector_client.config.credentials.get_access_token()) health_results.user_agent = USER_AGENT success_message = "Health check succeeded." health_results.messages = ( [success_message] if health_results.authorization else [success_message, "Callbacks are not authorized."]) return HealthCheckResponse(health_results=health_results)
async def on_healthcheck(self, turn_context: TurnContext) -> HealthCheckResponse: self.record.append("on_healthcheck") return HealthCheckResponse()