def test_should_not_be_able_to_set_responded_to_false(self):
     context = TurnContext(SimpleAdapter(), ACTIVITY)
     try:
         context.responded = False
     except ValueError:
         pass
     except Exception as error:
         raise error
    def test_copy_to_should_copy_all_references(self):
        # pylint: disable=protected-access
        old_adapter = SimpleAdapter()
        old_activity = Activity(id="2", type="message", text="test copy")
        old_context = TurnContext(old_adapter, old_activity)
        old_context.responded = True

        async def send_activities_handler(context, activities, next_handler):
            assert context is not None
            assert activities is not None
            assert next_handler is not None
            await next_handler

        async def delete_activity_handler(context, reference, next_handler):
            assert context is not None
            assert reference is not None
            assert next_handler is not None
            await next_handler

        async def update_activity_handler(context, activity, next_handler):
            assert context is not None
            assert activity is not None
            assert next_handler is not None
            await next_handler

        old_context.on_send_activities(send_activities_handler)
        old_context.on_delete_activity(delete_activity_handler)
        old_context.on_update_activity(update_activity_handler)

        adapter = SimpleAdapter()
        new_context = TurnContext(adapter, ACTIVITY)
        assert not new_context._on_send_activities  # pylint: disable=protected-access
        assert not new_context._on_update_activity  # pylint: disable=protected-access
        assert not new_context._on_delete_activity  # pylint: disable=protected-access

        old_context.copy_to(new_context)

        assert new_context.adapter == old_adapter
        assert new_context.activity == old_activity
        assert new_context.responded is True
        assert (
            len(new_context._on_send_activities) == 1
        )  # pylint: disable=protected-access
        assert (
            len(new_context._on_update_activity) == 1
        )  # pylint: disable=protected-access
        assert (
            len(new_context._on_delete_activity) == 1
        )  # pylint: disable=protected-access
Esempio n. 3
0
    def test_copy_to_should_copy_all_references(self):
        old_adapter = SimpleAdapter()
        old_activity = Activity(id='2', type='message', text='test copy')
        old_context = TurnContext(old_adapter, old_activity)
        old_context.responded = True

        async def send_activities_handler(context, activities, next_handler):
            assert context is not None
            assert activities is not None
            assert next_handler is not None
            await next_handler

        async def delete_activity_handler(context, reference, next_handler):
            assert context is not None
            assert reference is not None
            assert next_handler is not None
            await next_handler

        async def update_activity_handler(context, activity, next_handler):
            assert context is not None
            assert activity is not None
            assert next_handler is not None
            await next_handler

        old_context.on_send_activities(send_activities_handler)
        old_context.on_delete_activity(delete_activity_handler)
        old_context.on_update_activity(update_activity_handler)

        adapter = SimpleAdapter()
        new_context = TurnContext(adapter, ACTIVITY)
        assert len(new_context._on_send_activities) == 0
        assert len(new_context._on_update_activity) == 0
        assert len(new_context._on_delete_activity) == 0

        old_context.copy_to(new_context)

        assert new_context.adapter == old_adapter
        assert new_context.activity == old_activity
        assert new_context.responded is True
        assert len(new_context._on_send_activities) == 1
        assert len(new_context._on_update_activity) == 1
        assert len(new_context._on_delete_activity) == 1
Esempio n. 4
0
 async def capture_sent_activities(self, context: TurnContext, activities,
                                   next):  # pylint: disable=unused-argument
     self.sent += activities
     context.responded = True
 def test_should_be_able_to_set_responded_to_true(self):
     context = TurnContext(SimpleAdapter(), ACTIVITY)
     assert context.responded is False
     context.responded = True
     assert context.responded
Esempio n. 6
0
 async def capture_sent_activities(self, context: TurnContext, activities,
                                   next):
     self.sent += activities
     context.responded = True