def test_validate_name_without_name():
    """
    Should return appropriate error messages
    """
    # No Name Provided
    rslt = ContactValidationResult()
    con = {}
    validate_name(con, rslt)
    assert rslt.errors == ['NoNameFound']
    assert rslt.warnings == []
    assert not rslt.first
    assert not rslt.last
    assert not rslt.has_valid_name()
    # Empty givenName and surname
    rslt = ContactValidationResult()
    con = {'givenName': '', 'surname': ''}
    validate_name(con, rslt)
    assert rslt.errors == ['NoNameFound']
    assert rslt.warnings == []
    assert not rslt.first
    assert not rslt.last
    assert not rslt.has_valid_name()
    # Empty givenName and surname and displayName
    rslt = ContactValidationResult()
    con = {'givenName': '', 'surname': '', 'displayName': ''}
    validate_name(con, rslt)
    assert rslt.errors == ['NoNameFound']
    assert rslt.warnings == []
    assert not rslt.first
    assert not rslt.last
    assert not rslt.has_valid_name()
def test_validate_paths_with_invalid_mobile_phone():
    """
    Should return appropriate error messages
    """
    # Invalid mobile phone
    rslt = ContactValidationResult()
    con = {'mobilePhone': '12345'}
    validate_paths(con, rslt)
    assert rslt.errors == ['NoPathFound']
    assert rslt.warnings == ['NoUserPrincipalName', 'InvalidMobilePhone:12345']
    assert not rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert not rslt.email
    assert not rslt.mobile_phone
    assert not rslt.has_valid_paths()
    rslt = ContactValidationResult()
    con = {'businessPhones': ['1234567890'], 'mobilePhone': '12345'}
    validate_paths(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == ['NoUserPrincipalName', 'InvalidMobilePhone:12345']
    assert rslt.has_valid_paths()
    assert rslt.business_phones == ['1234567890']
    assert not rslt.email
    assert not rslt.mobile_phone
    assert rslt.has_valid_paths()
def test_validate_paths_with_blank_business_phones():
    """
    Should return appropriate error messages
    """
    # Empty business phone
    rslt = ContactValidationResult()
    con = {'businessPhones': ['']}
    validate_paths(con, rslt)
    assert rslt.errors == ['NoPathFound']
    assert rslt.warnings == ['NoUserPrincipalName', 'InvalidBusinessPhone:']
    assert not rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert not rslt.email
    assert not rslt.mobile_phone
    assert not rslt.has_valid_paths()
def test_validate_paths_without_userprincipalname():
    """
    Should return appropriate error messages
    """
    # Empty userPrincipalName
    rslt = ContactValidationResult()
    con = {'userPrincipalName': ''}
    validate_paths(con, rslt)
    assert rslt.errors == ['NoPathFound']
    assert rslt.warnings == ['InvalidUserPrincipalName:']
    assert not rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert not rslt.email
    assert not rslt.mobile_phone
    assert not rslt.has_valid_paths()
def test_validate_paths_without_path_data():
    """
    Should return appropriate error messages
    """
    # No Path
    rslt = ContactValidationResult()
    con = {}
    validate_paths(con, rslt)
    assert rslt.errors == ['NoPathFound']
    assert rslt.warnings == ['NoUserPrincipalName']
    assert not rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert not rslt.email
    assert not rslt.mobile_phone
    assert not rslt.has_valid_paths()
def test_validate_name_with_valid_name():
    """
    Should return no error messages but valid name
    """
    # Valid userPrincipalName
    rslt = ContactValidationResult()
    con = {'userPrincipalName': '*****@*****.**'}
    validate_name(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == ['NameExtractedFromEmail']
    assert rslt.first == 'abc'
    assert rslt.last == 'efg'
    assert rslt.has_valid_name()
    # Valid displayName
    rslt = ContactValidationResult()
    con = {'displayName': 'Aaaa Bbbb Cccc'}
    validate_name(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == ['NameExtractedFromDisplayName']
    assert rslt.first == 'Aaaa'
    assert rslt.last == 'Bbbb.Cccc'
    assert rslt.has_valid_name()
    # Valid name
    rslt = ContactValidationResult()
    con = {
        'userPrincipalName': '*****@*****.**',
        'givenName': 'Aaaa',
        'surname': 'Bbbb',
        'displayName': 'Ccc Ddd',
        'businessPhones': ['123456789X', '123456789Y'],
        'mobilePhone': '123456789Z'
    }
    validate_name(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == []
    assert rslt.first == 'Aaaa'
    assert rslt.last == 'Bbbb'
    assert rslt.has_valid_name()
def test_validate_name_with_invalid_userprincipalname():
    """
    Should return appropriate error messages
    """
    # Invalid userPrincipalName
    rslt = ContactValidationResult()
    con = {'userPrincipalName': '*****@*****.**'}
    validate_name(con, rslt)
    assert rslt.errors == ['NoNameFound']
    assert rslt.warnings == []
    assert not rslt.first
    assert not rslt.last
    assert not rslt.has_valid_name()
    # Empty userPrincipalName
    rslt = ContactValidationResult()
    con = {'userPrincipalName': ''}
    validate_name(con, rslt)
    assert rslt.errors == ['NoNameFound']
    assert rslt.warnings == []
    assert not rslt.first
    assert not rslt.last
    assert not rslt.has_valid_name()
def test_validate_paths_with_valid_data():
    """
    Should return appropriate error messages
    """
    # Valid userPrincipalName
    rslt = ContactValidationResult()
    con = {'userPrincipalName': '*****@*****.**'}
    validate_paths(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == []
    assert rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert rslt.email == '*****@*****.**'
    assert not rslt.mobile_phone
    assert rslt.has_valid_paths()
    # Valid business phone
    rslt = ContactValidationResult()
    con = {'businessPhones': ['1234567890', '1234567891']}
    validate_paths(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == ['NoUserPrincipalName']
    assert rslt.has_valid_paths()
    assert rslt.business_phones == ['1234567890', '1234567891']
    assert not rslt.email
    assert not rslt.mobile_phone
    assert rslt.has_valid_paths()
    # Valid mobile phone
    rslt = ContactValidationResult()
    con = {'mobilePhone': '1234567890'}
    validate_paths(con, rslt)
    assert rslt.errors == []
    assert rslt.warnings == ['NoUserPrincipalName']
    assert rslt.has_valid_paths()
    assert rslt.business_phones == []
    assert not rslt.email
    assert rslt.mobile_phone == '1234567890'
    assert rslt.has_valid_paths()