def validate_presenters(presenters):
    """Check validity of  the list of presenters.

    This function should never fail since the checks should already have been made client-side.
     """
    mandatory_keys = ['is_lead', 'email', 'name', 'bio', 'country']
    leads_found = []
    for presenter in presenters:
        for key in mandatory_keys:
            if key not in presenter:
                return False, '{} attribute is mandatory for Presenters'.format(key)
            if presenter[key] is None:
                return False, '{} attribute should have valid data'.format(key)
        if not is_valid_email(presenter['email']):
            return False, '{} not a valid email'.format(presenter['email'])
        if not is_valid_name(presenter['name']):
            return False, '{} not a valid name'.format(presenter['name'])
        if not is_valid_bio(presenter['bio']):
            return False, '{} not a valid bio'.format(presenter['bio'])
        if not is_valid_country(presenter['country']):
            return False, '{} not a valid country'.format(presenter['country'])
        if presenter['is_lead']:
            leads_found.append(presenter['email'])
    lead_count = len(leads_found)
    if lead_count == 0:
        return False, 'No lead presenter.'
    elif lead_count > 1:
        return False, '{} marked as lead presenters'.format(leads_found)
    return True, 'validated'
예제 #2
0
def test_unknown_country_is_not_valid_country():
    assert not utils.is_valid_country('Middle Earth')
예제 #3
0
def test_known_country_is_valid_country(country):
    assert utils.is_valid_country(country)