def test_inviting(self): user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) self.assertFalse(user.is_active) self.assertEqual(1, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Resend the mail user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) self.assertFalse(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Don't resend the mail user, sent = invite("*****@*****.**", self.inviter, resend=False) self.assertFalse(sent) self.assertFalse(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Don't send the email to active users user, sent = invite("*****@*****.**", self.inviter) self.assertFalse(sent) self.assertTrue(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count())
def test_opt_out(self): self.assertEqual(2, User.objects.count()) user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) self.assertEqual(1, len(mail.outbox)) self.assertEqual(3, User.objects.count()) url_parts = int_to_base36(user.id), token_generator.make_token(user) url = reverse('inviter:opt-out', args=url_parts) resp = self.client.get(url) self.assertEqual(200, resp.status_code, resp.status_code) resp = self.client.post(url, {}) self.assertEqual(302, resp.status_code, resp.status_code) self.assertEqual(reverse('inviter:opt-out-done'), urlparse.urlparse(resp['Location']).path) self.assertEqual(2, User.objects.count()) user, sent = invite("*****@*****.**", self.inviter) self.assertFalse(sent) self.assertEqual(1, len(mail.outbox)) self.assertEqual(1, OptOut.objects.count()) self.assertTrue(OptOut.objects.is_blocked("*****@*****.**")) self.assertIsNone(user)
def test_inviting(self): user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) self.assertFalse(user.is_active) self.assertEqual(1, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Resend the mail user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) self.assertFalse(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Don't resend the mail user, sent = invite("*****@*****.**", self.inviter, resend = False) self.assertFalse(sent) self.assertFalse(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count()) # Don't send the email to active users user, sent = invite("*****@*****.**", self.inviter) self.assertFalse(sent) self.assertTrue(user.is_active) self.assertEqual(2, len(mail.outbox)) self.assertEqual(3, User.objects.count())
def form_valid(self, form): if form.is_valid(): invite(form.cleaned_data['email'], self.request.user, current_time=datetime.now()) return HttpResponseRedirect(self.success_url) else: return self.render_to_response(self.get_context_data(form=form(self.request.POST)))
def test_views(self): user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) url_parts = int_to_base36(user.id), token_generator.make_token(user) url = reverse('inviter:register', args=url_parts) resp = self.client.get(url) self.assertEqual(200, resp.status_code, resp.status_code) resp = self.client.post( url, { 'username': '******', 'email': '*****@*****.**', 'new_password1': 'test-1234', 'new_password2': 'test-1234' }) self.assertEqual(302, resp.status_code, resp.content) self.client.login(username='******', password='******') resp = self.client.get(reverse('inviter:done')) self.assertEqual(200, resp.status_code, resp.status_code)
def test_views(self): user, sent = invite("*****@*****.**", self.inviter) self.assertTrue(sent) url_parts = int_to_base36(user.id), token_generator.make_token(user) url = reverse('inviter:register', args=url_parts) resp = self.client.get(url) self.assertEqual(200, resp.status_code, resp.status_code) resp = self.client.post(url, {'username': '******', 'email': '*****@*****.**', 'new_password1': 'test-1234', 'new_password2': 'test-1234'}) self.assertEqual(302, resp.status_code, resp.content) self.client.login(username='******', password='******') resp = self.client.get(reverse('inviter:done')) self.assertEqual(200, resp.status_code, resp.status_code)