def test_domain_urlopen_args(self): with patch('bdea.client.urlopen') as urlopen_mock: urlopen_mock.return_value = StringIO('{}') cl = BDEAClient('apikey') cl.get_domain_status('example.com') url = 'http://check.block-disposable-email.com/easyapi/json/apikey/example.com' urlopen_mock.assert_called_with(url, timeout=5)
def __call__(self, value): value = force_text(value) # Catch invalid emails before we check if they're disposable try: validators.validate_email(value) except ValidationError: return user_part, domain_part = value.rsplit('@', 1) if domain_part not in self.whitelist: if self.BDEA_APIKEY: # Validate using block-disposable-email.com client = BDEAClient(self.BDEA_APIKEY, timeout=self.BDEA_TIMEOUT) response = client.get_domain_status(domain_part) if response.status() and response.is_disposable(): raise ValidationError(self.message, code=self.code) """ This will run if we are not using BDEA, we're out of BDEA credits, there was an error contacting BDEA's servers or we did not get a hit on BDEA. Basically always check using local list as a backup """ for email_group in self.chunk(self.emails, 20): regex = "(.*" + "$)|(.*".join(email_group) + "$)" if re.match(regex, value): raise ValidationError(self.message, code=self.code)
def test_do_not_accept_email(self): cl = BDEAClient('apikey') with pytest.raises(ValueError): cl.get_domain_status('*****@*****.**')