2019-11-21 15:41:05 +01:00
|
|
|
from unittest.case import TestCase
|
|
|
|
|
2020-04-11 14:21:52 +02:00
|
|
|
from validate_email.domainlist_check import (
|
|
|
|
domainlist_check, update_builtin_blacklist)
|
2020-04-13 09:44:50 +02:00
|
|
|
from validate_email.email_address import EmailAddress
|
2020-04-08 23:56:49 +02:00
|
|
|
from validate_email.exceptions import DomainBlacklistedError
|
2020-04-11 14:21:52 +02:00
|
|
|
from validate_email.validate_email import (
|
|
|
|
validate_email, validate_email_or_fail)
|
2019-11-21 15:41:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class BlacklistCheckTestCase(TestCase):
|
|
|
|
'Testing if the included blacklist filtering works.'
|
|
|
|
|
2021-12-06 17:58:28 +01:00
|
|
|
def setUpClass(): # type: ignore
|
2020-04-11 14:21:52 +02:00
|
|
|
update_builtin_blacklist(force=False, background=False)
|
2019-11-24 18:13:02 +01:00
|
|
|
|
2019-11-21 15:41:05 +01:00
|
|
|
def test_blacklist_positive(self):
|
|
|
|
'Disallows blacklist item: mailinator.com.'
|
2021-12-06 17:58:28 +01:00
|
|
|
# The setting of the PY3VE_IGNORE_UPDATER variable doesn't
|
|
|
|
# matter here as the module has already download an initial list
|
2020-04-08 23:56:49 +02:00
|
|
|
with self.assertRaises(DomainBlacklistedError):
|
2021-01-06 20:41:20 +01:00
|
|
|
domainlist_check(EmailAddress('pm2@mailinator.com'))
|
2020-04-08 23:56:49 +02:00
|
|
|
with self.assertRaises(DomainBlacklistedError):
|
|
|
|
validate_email_or_fail(
|
2021-03-12 01:06:13 +01:00
|
|
|
email_address='pm2@mailinator.com', check_format=False,
|
|
|
|
check_blacklist=True)
|
2020-04-08 23:56:49 +02:00
|
|
|
with self.assertRaises(DomainBlacklistedError):
|
|
|
|
validate_email_or_fail(
|
2021-03-12 01:06:13 +01:00
|
|
|
email_address='pm2@mailinator.com', check_format=True,
|
|
|
|
check_blacklist=True)
|
2020-04-08 23:56:49 +02:00
|
|
|
with self.assertLogs():
|
2020-04-10 12:53:10 +02:00
|
|
|
self.assertFalse(expr=validate_email(
|
2021-03-12 01:06:13 +01:00
|
|
|
email_address='pm2@mailinator.com', check_format=False,
|
|
|
|
check_blacklist=True))
|
2020-04-08 23:56:49 +02:00
|
|
|
with self.assertLogs():
|
2020-04-10 12:53:10 +02:00
|
|
|
self.assertFalse(expr=validate_email(
|
2021-03-12 01:06:13 +01:00
|
|
|
email_address='pm2@mailinator.com', check_format=True,
|
|
|
|
check_blacklist=True))
|
2019-11-21 15:41:05 +01:00
|
|
|
|
|
|
|
def test_blacklist_negative(self):
|
|
|
|
'Allows a domain not in the blacklist.'
|
|
|
|
self.assertTrue(expr=domainlist_check(
|
2021-01-06 20:41:20 +01:00
|
|
|
EmailAddress('pm2@some-random-domain-thats-not-blacklisted.com')))
|