Skip to content

Commit

Permalink
feat(python): add add_custom_domains
Browse files Browse the repository at this point in the history
  • Loading branch information
choznerol committed Nov 9, 2021
1 parent c3245c5 commit 4b668de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions platform/python/MailChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions platform/python/MailChecker.tmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions test/platform.python.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 4b668de

Please sign in to comment.