def test_check_mx_records(self):
        assert check_mx_records('google.com', 1) is True
        assert check_mx_records('corver.it') is True
        assert check_mx_records('does-not-exist.domain') is False

        assert check_mx_records('google.com') is True

        assert 'google.com' in _mx_records_cache

        sleep(1)

        assert _mx_records_cache['google.com'][0] < time()
        assert check_mx_records('google.com') is True
        assert _mx_records_cache['google.com'][0] > time()
Beispiel #2
0
def Email(error='Invalid e-mail address.',
          error_dot='Missing dot in e-mail address.',
          error_at='Missing at in e-mail address.',
          check_mx=False):
    from validate_email_address import validate_email

    commands = [
        String(min_len=5, max_len=256),
        validate(lambda v: '.' in v, error_dot),
        validate(lambda v: '@' in v, error_at),
        validate(lambda v: validate_email(v), error),
    ]

    if check_mx:
        commands.append(validate(lambda v: check_mx_records(v), error))

    return Test(commands)