I have the following code which does:
- check a schedulingStrategy
- According to the scheduling strategy
- Check the associated scheduling period
For now I only have two scheduling strategy thus my code is pretty straight forward:
def test_scheduling_parameters(schedulingStrategy: str, schedulingPeriod: str):
    """
    :param schedulingStrategy:Could be CRON_DRIVEN or TIMER_DRIVEN
    :param schedulingPeriod: If CRON would be in the form of '* * * * * ?', else XX sec (or min)
    :return:
    """
    sche_strat = ['TIMER_DRIVEN', 'CRON_DRIVEN']
    if schedulingStrategy in sche_strat:
        if schedulingStrategy == 'TIMER_DRIVEN' and re.match('\d+\s(sec|min)$', schedulingPeriod):
            return True
        elif schedulingStrategy == "CRON_DRIVEN" and croniter.is_valid(schedulingPeriod[:-2]):
            return True
        else:
            return "Error: Wrong scheduling period"
    else:
        return "Error: Wrong scheduling strategy"
I am wondering how I can do if I have more scheduling strategy without multiplying if cases?
I had an idea of having a kind of dictionnary containing, the name of strategy and a validation function, is it the best way to do it?
 
     
     
    