Beispiel #1
0
def test_email_address_mutability():
    """EmailAddress can be mutated to change casing or delete the address only"""
    ea = EmailAddress('*****@*****.**')
    assert ea.email == '*****@*****.**'
    assert ea.domain == 'example.com'
    assert ea.blake2b160 == hash_map['*****@*****.**']

    # Case changes allowed, hash remains the same
    ea.email = '*****@*****.**'
    assert ea.email == '*****@*****.**'
    assert ea.domain == 'example.com'
    assert ea.blake2b160 == hash_map['*****@*****.**']

    # Setting it to existing value is allowed
    ea.email = '*****@*****.**'
    assert ea.email == '*****@*****.**'
    assert ea.domain == 'example.com'
    assert ea.blake2b160 == hash_map['*****@*****.**']

    # Nulling allowed, hash remains intact
    ea.email = None
    assert ea.email is None
    assert ea.domain is None
    assert ea.blake2b160 == hash_map['*****@*****.**']

    # Restoring allowed (case insensitive)
    ea.email = '*****@*****.**'
    assert ea.email == '*****@*****.**'
    assert ea.domain == 'example.com'
    assert ea.blake2b160 == hash_map['*****@*****.**']

    # But changing to another email address is not allowed
    with pytest.raises(ValueError):
        ea.email = '*****@*****.**'

    # Change is also not allowed by blanking and then setting to another
    ea.email = None
    with pytest.raises(ValueError):
        ea.email = '*****@*****.**'

    # Changing the domain is also not allowed
    with pytest.raises(AttributeError):
        ea.domain = 'gmail.com'

    # Setting to an invalid value is not allowed
    with pytest.raises(ValueError):
        ea.email = ''
Beispiel #2
0
def test_email_address_md5():
    """EmailAddress has an MD5 method for legacy applications"""
    ea = EmailAddress('*****@*****.**')
    assert ea.md5() == '23463b99b62a72f26ed677cc556c44e8'
    ea.email = None
    assert ea.md5() is None