def test_delete_bot_intents_called(intent_builder, put_bot_response, mocker):
    lex, intents = setup()
    delete_intent_response = {'test': 'response'}
    # delete_response = {'test': 'bot response'}

    with Stubber(lex) as stubber:
        context = mocker.Mock()
        intent_builder_instance = intent_builder.return_value
        intent_builder_instance.delete_intents.return_value = delete_intent_response

        stub_get_request(stubber)
        stubber.add_response('delete_bot', {}, {'name': BOT_NAME})

        bot_builder = LexBotBuilder(Mock(),
                                    context,
                                    lex_sdk=lex,
                                    intent_builder=intent_builder_instance)
        bot = Bot.create_bot(BOT_NAME, intents, {})

        bot_builder.delete(bot)

        assert intent_builder_instance.delete_intents.call_count == 1
        intent_builder_instance.delete_intents.assert_called_with(
            ['greeting', 'farewell'])
        stubber.assert_no_pending_responses()
def test_update_puts_bot(intent_builder, intent_defs, put_bot_response,
                         bot_properties, mocker):
    """ test_update_puts_bot"""
    lex, intents = setup()
    expected_put_params = put_bot_request(BOT_NAME,
                                          intents,
                                          MESSAGES,
                                          has_checksum=True)

    with Stubber(lex) as stubber:
        context = mock_context(mocker)
        intent_builder_instance = stub_put_intent(intent_builder)
        stub_get_request(stubber)
        stub_put_bot(stubber, put_bot_response, expected_put_params)

        bot_builder = LexBotBuilder(Mock(),
                                    context,
                                    lex_sdk=lex,
                                    intent_builder=intent_builder_instance)
        bot = Bot.create_bot(BOT_NAME, intents, MESSAGES, **bot_properties)
        response = bot_builder.put(bot)

        assert response['name'] == BOT_NAME
        assert response['version'] == BOT_VERSION
        stubber.assert_no_pending_responses()
def test_create_put_intent_called(intent_builder, put_bot_response,
                                  bot_properties, mocker):
    """ create put intent called test """
    lex, intents = setup()
    expected_put_params = put_bot_request(BOT_NAME, intents, MESSAGES)

    with Stubber(lex) as stubber:
        context = mock_context(mocker)
        intent_builder_instance = stub_put_intent(intent_builder)
        stub_not_found_get_request(stubber)
        stub_put_bot(stubber, put_bot_response, expected_put_params)

        bot_builder = LexBotBuilder(Mock(),
                                    context,
                                    lex_sdk=lex,
                                    intent_builder=intent_builder_instance)
        bot = Bot.create_bot(BOT_NAME, intents, MESSAGES, **bot_properties)
        bot_builder.put(bot)

        assert intent_builder_instance.put_intent.call_count == 2
        intent_builder_instance.put_intent.assert_called_with(intents[1])
def test_delete_bot_on_deleted_bot(intent_builder, put_bot_response, mocker):
    """ delete bot does not fail test """
    lex, intents = setup()
    delete_intent_response = {'test': 'response'}

    with Stubber(lex) as stubber:
        context = mocker.Mock()
        intent_builder_instance = intent_builder.return_value
        intent_builder_instance.delete_intents.return_value = delete_intent_response

        stub_not_found_get_request(stubber)
        stubber.add_response('delete_bot', {}, {'name': BOT_NAME})

        bot_builder = LexBotBuilder(Mock(),
                                    context,
                                    lex_sdk=lex,
                                    intent_builder=intent_builder_instance)
        bot = Bot.create_bot(BOT_NAME, intents, {})

        bot_builder.delete(bot)

        assert intent_builder_instance.delete_intents.call_count == 1
def test_delete_bot_called(intent_builder, put_bot_response, bot_properties,
                           mocker):
    """ delete bot called test """

    lex, intents = setup()
    delete_intent_response = {'test': 'response'}

    with Stubber(lex) as stubber:
        context = mocker.Mock()
        intent_builder_instance = intent_builder.return_value
        intent_builder_instance.delete_intents.return_value = delete_intent_response

        stub_get_request(stubber)
        stubber.add_response('delete_bot', {}, {'name': BOT_NAME})

        bot_builder = LexBotBuilder(Mock(),
                                    context,
                                    lex_sdk=lex,
                                    intent_builder=intent_builder_instance)

        bot = Bot.create_bot(BOT_NAME, intents, MESSAGES, **bot_properties)
        bot_builder.delete(bot)
        stubber.assert_no_pending_responses()
Esempio n. 6
0
def lex_builder_instance(context):
    """Creates an instance of LexBotBuilder"""
    return LexBotBuilder(logger, context)