Ejemplo n.º 1
0
def test_custom_display_text(test_client, init_database, menu_name, language, expecteds,
                             real_at_idx, length, unexpected, menu_nr):
    with db.session.no_autoflush:
        start_state = UssdSessionFactory(state="menu_name")

        mapping = fake_transfer_mapping(length)
        real_usage1 = TransferUsage.find_or_create('Education')
        real_usage1.translations = {'en': 'Education', 'sw': 'Elimu'}
        real_usage2 = TransferUsage.find_or_create('Health')
        real_usage2.translations = {'en': 'Health', 'sw': 'Afya'}
        mapping[real_at_idx] = UssdStateMachine.make_usage_mapping(real_usage1)
        mapping[real_at_idx + 1] = UssdStateMachine.make_usage_mapping(real_usage2)
        user = standard_user()
        user.preferred_language = language

        start_state.session_data = {
            'transfer_usage_mapping': mapping,
            'usage_menu': menu_nr,
            'usage_index_stack': [0, 8]
        }

        start_state.user = user

        menu = UssdMenu(name=menu_name, display_key="ussd.sempo.{}".format(menu_name))
        resulting_menu = UssdProcessor.custom_display_text(
            menu, start_state)

        for expected in expecteds:
            assert expected in resulting_menu
        if unexpected is not None:
            assert unexpected not in resulting_menu
Ejemplo n.º 2
0
def fake_transfer_mapping(length: int):
    mapping = []
    transfer_usage = TransferUsage.find_or_create("Food")
    db.session.commit()
    for i in range(length):
        mapping.append(UssdStateMachine.make_usage_mapping(transfer_usage))

    return mapping