def test_invites_worker(self) -> None: fake_client = self.FakeClient() invitor = self.example_user('iago') prereg_alice = PreregistrationUser.objects.create( email=self.nonreg_email('alice'), referred_by=invitor, realm=invitor.realm) PreregistrationUser.objects.create(email=self.nonreg_email('bob'), referred_by=invitor, realm=invitor.realm) data = [ dict(prereg_id=prereg_alice.id, referrer_id=invitor.id, email_body=None), # Nonexistent prereg_id, as if the invitation was deleted dict(prereg_id=-1, referrer_id=invitor.id, email_body=None), # Form with `email` is from versions up to Zulip 1.7.1 dict(email=self.nonreg_email('bob'), referrer_id=invitor.id, email_body=None), ] for element in data: fake_client.queue.append(('invites', element)) with simulated_queue_client(lambda: fake_client): worker = queue_processors.ConfirmationEmailWorker() worker.setup() with patch('zerver.worker.queue_processors.do_send_confirmation_email'), \ patch('zerver.worker.queue_processors.create_confirmation_link'), \ patch('zerver.worker.queue_processors.send_future_email') \ as send_mock, \ patch('logging.info'): worker.start() self.assertEqual(send_mock.call_count, 2)
def test_invites_worker(self) -> None: fake_client = self.FakeClient() inviter = self.example_user("iago") prereg_alice = PreregistrationUser.objects.create( email=self.nonreg_email("alice"), referred_by=inviter, realm=inviter.realm ) PreregistrationUser.objects.create( email=self.nonreg_email("bob"), referred_by=inviter, realm=inviter.realm ) data: List[Dict[str, Any]] = [ dict(prereg_id=prereg_alice.id, referrer_id=inviter.id), dict( prereg_id=prereg_alice.id, referrer_id=inviter.id, email_language="en", ), # Nonexistent prereg_id, as if the invitation was deleted dict(prereg_id=-1, referrer_id=inviter.id), ] for element in data: fake_client.enqueue("invites", element) with simulated_queue_client(lambda: fake_client): worker = queue_processors.ConfirmationEmailWorker() worker.setup() with patch("zerver.lib.actions.send_email"), patch( "zerver.worker.queue_processors.send_future_email" ) as send_mock: worker.start() self.assertEqual(send_mock.call_count, 2)