コード例 #1
0
ファイル: test_utils.py プロジェクト: hiteshsondhi88/apprise
def test_is_email():
    """
    API: is_email() function

    """
    # Valid Emails
    assert utils.is_email('*****@*****.**') is True
    assert utils.is_email('*****@*****.**') is True

    # Invalid Emails
    assert utils.is_email('invalid.com') is False
    assert utils.is_email(object()) is False
    assert utils.is_email(None) is False
コード例 #2
0
def test_is_email():
    """
    API: is_email() function

    """
    # Valid Emails
    results = utils.is_email('*****@*****.**')
    assert '' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'gmail.com' == results['domain']
    assert 'test' == results['user']
    assert '' == results['label']

    results = utils.is_email('test@my-valid_host.com')
    assert '' == results['name']
    assert 'test@my-valid_host.com' == results['email']
    assert 'test@my-valid_host.com' == results['full_email']
    assert 'my-valid_host.com' == results['domain']
    assert 'test' == results['user']
    assert '' == results['label']

    results = utils.is_email('*****@*****.**')
    assert '' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'gmail.com' == results['domain']
    assert 'test' == results['user']
    assert 'tag' == results['label']

    # Support Full Names as well
    results = utils.is_email('Bill Gates: [email protected]')
    assert 'Bill Gates' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'microsoft.com' == results['domain']
    assert 'bgates' == results['user']
    assert '' == results['label']

    results = utils.is_email('Bill Gates <*****@*****.**>')
    assert 'Bill Gates' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'microsoft.com' == results['domain']
    assert 'bgates' == results['user']
    assert '' == results['label']

    results = utils.is_email('Bill Gates: <*****@*****.**>')
    assert 'Bill Gates' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'microsoft.com' == results['domain']
    assert 'bgates' == results['user']
    assert '' == results['label']

    results = utils.is_email('Sundar Pichai <*****@*****.**>')
    assert 'Sundar Pichai' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'gmail.com' == results['domain']
    assert 'spichai' == results['user']
    assert 'ceo' == results['label']

    # An email without name, but contains delimiters
    results = utils.is_email('      <*****@*****.**>')
    assert '' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'gmail.com' == results['domain']
    assert 'spichai' == results['user']
    assert '' == results['label']

    # a valid email not properly delimited with a colon or angle bracket
    # We do a best guess and still parse it correctly
    results = utils.is_email("Name [email protected]")
    assert 'Name' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'example.com' == results['domain']
    assert 'valid' == results['user']
    assert '' == results['label']

    # a valid email not properly delimited with a colon or angle bracket
    # We do a best guess and still parse it correctly
    results = utils.is_email("Руслан Эра [email protected]")
    assert 'Руслан Эра' == results['name']
    assert '*****@*****.**' == results['email']
    assert '*****@*****.**' == results['full_email']
    assert 'example.ru' == results['domain']
    assert 'russia' == results['user']
    assert 'russian' == results['label']

    # Invalid Emails
    assert utils.is_email('invalid.com') is False
    assert utils.is_email(object()) is False
    assert utils.is_email(None) is False
    assert utils.is_email("Just A Name") is False
    assert utils.is_email("Name <bademail>") is False