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_event_with_incorrect_MessageID(self):
     events.receive({
         'event': 'open', 'time': time(),
         'MessageID': None,
         'email': '*****@*****.**',
     })
     events.receive({
         'event': 'open', 'time': time(),
         'MessageID': 'wtf',
         'email': '*****@*****.**',
     })
     events.process.consume()
 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_event_with_incorrect_status(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.OPENED, message_id=123)

        events.receive({
            'event': None, 'time': time(),
            'MessageID': 123,
            'email': '*****@*****.**',
        })
        events.receive({
            'event': 'shutupyouredrunk', 'time': time(),
            'MessageID': 123,
            'email': '*****@*****.**',
        })
        events.process.consume()
        self.assertEqual(models.Email.OPENED, models.Email.objects.get().status)