cic-internal-integration/apps/cic-ussd/cic_ussd/state_machine/logic/menu.py

142 lines
5.4 KiB
Python
Raw Permalink Normal View History

2021-02-06 16:13:47 +01:00
"""This module defines functions responsible for interaction with the ussd menu. It takes user input and navigates the
ussd menu facilitating the return of appropriate menu responses based on said user input.
"""
# standard imports
from typing import Tuple
2021-08-06 18:29:01 +02:00
# external imports
from sqlalchemy.orm.session import Session
2021-02-06 16:13:47 +01:00
# local imports
2021-04-19 10:44:40 +02:00
from cic_ussd.db.models.account import Account
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
def menu_one_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""This function checks that user input matches a string with value '1'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: str
:return: A user input's match with '1'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '1'
2021-08-06 18:29:01 +02:00
def menu_two_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""This function checks that user input matches a string with value '2'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '2'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '2'
2021-08-06 18:29:01 +02:00
def menu_three_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""This function checks that user input matches a string with value '3'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '3'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '3'
2021-08-06 18:29:01 +02:00
def menu_four_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""
This function checks that user input matches a string with value '4'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '4'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '4'
2021-08-06 18:29:01 +02:00
def menu_five_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""
This function checks that user input matches a string with value '5'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '5'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '5'
2021-08-06 18:29:01 +02:00
def menu_six_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-06-23 15:25:09 +02:00
"""
This function checks that user input matches a string with value '6'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '6'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-06-23 15:25:09 +02:00
return user_input == '6'
2021-11-29 22:24:37 +01:00
def menu_nine_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
"""
This function checks that user input matches a string with value '6'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '6'
:rtype: bool
"""
user_input, ussd_session, account, session = state_machine_data
return user_input == '9'
2021-08-06 18:29:01 +02:00
def menu_zero_zero_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""
This function checks that user input matches a string with value '00'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '00'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '00'
2021-11-29 16:04:50 +01:00
def menu_eleven_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
"""
This function checks that user input matches a string with value '11'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '99'
:rtype: bool
"""
user_input, ussd_session, account, session = state_machine_data
return user_input == '11'
def menu_twenty_two_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
"""
This function checks that user input matches a string with value '22'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '99'
:rtype: bool
"""
user_input, ussd_session, account, session = state_machine_data
return user_input == '22'
2021-08-06 18:29:01 +02:00
def menu_ninety_nine_selected(state_machine_data: Tuple[str, dict, Account, Session]) -> bool:
2021-02-06 16:13:47 +01:00
"""
This function checks that user input matches a string with value '99'
:param state_machine_data: A tuple containing user input, a ussd session and user object.
:type state_machine_data: tuple
:return: A user input's match with '99'
:rtype: bool
"""
2021-08-06 18:29:01 +02:00
user_input, ussd_session, account, session = state_machine_data
2021-02-06 16:13:47 +01:00
return user_input == '99'