def iter_applications(): redis_client = redis() for key in redis_client.keys(REDIS_KEY + ":*"): candidate_email = key.decode().split(":")[1] if is_blacklisted(candidate_email): continue sirets = [siret.decode() for siret in redis_client.lrange(key, 0, -1)] yield candidate_email, sirets
def test_spam_event_incorrect_timestamp(self): event = { 'event': 'spam', 'time': 'wtf', 'MessageID': 58265320973912910, 'email': '*****@*****.**', } events.receive(event) events.process.consume() self.assertTrue(blacklist.is_blacklisted("*****@*****.**"))
def test_spam_event_in_the_past(self): event = { 'event': 'spam', 'time': time() - 2, 'MessageID': 58265320973912910, 'email': '*****@*****.**', } events.receive(event) events.process.consume() self.assertFalse(blacklist.is_blacklisted("*****@*****.**"))
def test_open_event(self): job_application = models.JobApplication.objects.create( employer_email='*****@*****.**', candidate_email='*****@*****.**', client_platform=self.client_platform, ) event = job_application.events.create( name=models.JobApplicationEvent.SENT_TO_EMPLOYER ) models.Email.objects.create(event=event, status=models.Email.SENT, message_id=123) events.receive({ 'event': 'open', 'time': time(), 'MessageID': 123, 'email': '*****@*****.**', }) events.process.consume() self.assertEqual(models.Email.OPENED, models.Email.objects.get().status) self.assertFalse(blacklist.is_blacklisted("*****@*****.**"))
def test_blacklisted_email(self): blacklist.add("*****@*****.**") self.assertTrue(blacklist.is_blacklisted("*****@*****.**"))
def test_add_remove(self): blacklist.add("*****@*****.**") self.assertTrue(blacklist.is_blacklisted("*****@*****.**")) blacklist.remove("*****@*****.**") self.assertFalse(blacklist.is_blacklisted("*****@*****.**"))
def is_employer_blacklisted(self, obj): return blacklist.is_blacklisted(obj.employer_email)
def is_candidate_blacklisted(self, obj): return blacklist.is_blacklisted(obj.candidate_email)