cic-stack/apps/cic-ussd/cic_ussd/state_machine/logic/menu.py

103 lines
3.8 KiB
Python
Raw 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
# 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-04-19 10:44:40 +02:00
def menu_one_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '1'
2021-04-19 10:44:40 +02:00
def menu_two_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '2'
2021-04-19 10:44:40 +02:00
def menu_three_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '3'
2021-04-19 10:44:40 +02:00
def menu_four_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '4'
2021-04-19 10:44:40 +02:00
def menu_five_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '5'
2021-06-23 15:25:09 +02:00
def menu_six_selected(state_machine_data: Tuple[str, dict, Account]) -> 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, user = state_machine_data
return user_input == '6'
2021-04-19 10:44:40 +02:00
def menu_zero_zero_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '00'
2021-04-19 10:44:40 +02:00
def menu_ninety_nine_selected(state_machine_data: Tuple[str, dict, Account]) -> 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
"""
user_input, ussd_session, user = state_machine_data
return user_input == '99'