From 4b668deb1e9192ea8223854762c7bc92bf83d314 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Tue, 2 Nov 2021 10:44:48 +0800 Subject: [PATCH] feat(python): add add_custom_domains --- platform/python/MailChecker.py | 4 ++++ platform/python/MailChecker.tmpl.py | 4 ++++ test/platform.python.test.py | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/platform/python/MailChecker.py b/platform/python/MailChecker.py index e68ef419..d70bbd92 100644 --- a/platform/python/MailChecker.py +++ b/platform/python/MailChecker.py @@ -34,3 +34,7 @@ def is_blacklisted(cls, email): @classmethod def is_valid_email_format(cls, email): return bool(email) and cls.valid_matcher.search(email) is not None + + @classmethod + def add_custom_domains(cls, domains = []): + cls.blacklist.update(domains) \ No newline at end of file diff --git a/platform/python/MailChecker.tmpl.py b/platform/python/MailChecker.tmpl.py index 5a4c7f95..29c80fdb 100644 --- a/platform/python/MailChecker.tmpl.py +++ b/platform/python/MailChecker.tmpl.py @@ -34,3 +34,7 @@ def is_blacklisted(cls, email): @classmethod def is_valid_email_format(cls, email): return bool(email) and cls.valid_matcher.search(email) is not None + + @classmethod + def add_custom_domains(cls, domains = []): + cls.blacklist.update(domains) \ No newline at end of file diff --git a/test/platform.python.test.py b/test/platform.python.test.py index 1b639595..c64be693 100644 --- a/test/platform.python.test.py +++ b/test/platform.python.test.py @@ -55,5 +55,16 @@ def test_return_false_for_blacklisted_domains_and_their_subdomains(self): # Should not be invalid as a subdomain of a valid domain. self.valid("test@%s.gmail.com" % blacklisted_domain) + def test_add_custom_domains(self): + self.valid('foo@youtube.com') + self.valid('foo@google.com') + self.valid('ok@gmail.com') + + MailChecker.add_custom_domains(['youtube.com', 'google.com']) + + self.invalid('foo@youtube.com') + self.invalid('foo@google.com') + self.valid('ok@gmail.com') + if __name__ == '__main__': unittest.main()