コード例 #1
0
 def test_initial_newsletters(self):
     """
     Make sure a new form renders with the correct newsletters checked
     """
     email = EmailAddress.objects.create(user=self.user)
     email.subscribe(self.newsletter1)
     form = SubscriptionForm(user=self.user)
     soup = BeautifulSoup(form.as_ul())
     self.assertEqual(3, len(soup.findAll('input', type='checkbox')), soup)
     self.assertEqual(1, len(soup.findAll('input', checked=True)), soup)
コード例 #2
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
 def test_initial_newsletters(self):
     """
     Make sure a new form renders with the correct newsletters checked
     """
     email = EmailAddress.objects.create(user=self.user)
     email.subscribe(self.newsletter1)
     form = SubscriptionForm(user=self.user)
     soup = BeautifulSoup(form.as_ul())
     self.assertEqual(3, len(soup.findAll('input', type='checkbox')), soup)
     self.assertEqual(1, len(soup.findAll('input', checked=True)), soup)
コード例 #3
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
 def test_email_sanitization(self):
     """
     Make sure email addresses get sanitized
     """
     data = {
         'email_address': '  [email protected]   ',
         'newsletters': [self.newsletter1.id]
     }
     form = SubscriptionForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual('*****@*****.**', form.cleaned_data['email_address'])
コード例 #4
0
 def test_email_sanitization(self):
     """
     Make sure email addresses get sanitized
     """
     data = {
         'email_address': '  [email protected]   ',
         'newsletters': [self.newsletter1.id]
     }
     form = SubscriptionForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual('*****@*****.**',
                      form.cleaned_data['email_address'])
コード例 #5
0
    def test_unsubscribe(self):
        """
        Make sure removing previous subscriptions for a user works
        """
        email = EmailAddress.objects.create(user=self.user)
        email.subscribe(self.newsletter1)
        data = {'email_address': self.user.email}
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid())

        self.assertEqual(1, email.subscriptions.count())
        form.save()
        self.assertEqual(0, email.subscriptions.count())
コード例 #6
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
    def test_inactive_newsletters(self):
        """
        Make sure inactive newsletters don't get rendered
        """
        inactive_newsletter = self.newsletter1
        inactive_newsletter.active = False
        inactive_newsletter.save()

        form = SubscriptionForm(user=self.user)
        soup = BeautifulSoup(form.as_ul())
        self.assertEqual(2, len(soup.findAll('input', attrs={'name': 'newsletters'})),
                         soup)
        self.assertEqual(0, len(soup.findAll('input', attrs={'name': 'newsletters', 'value': inactive_newsletter.id})))
コード例 #7
0
    def test_multi_submit(self):
        """
        Test submitting multiple newsletter subscription changes at once
        """
        email = EmailAddress.objects.create(user=self.user)
        data = {
            'email_address': self.user.email,
            'newsletters': [n.id for n in Newsletter.objects.all()]
        }
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid(), form.errors)

        self.assertEqual(0, email.subscriptions.count())
        form.save()
        self.assertEqual(3, email.subscriptions.count())
コード例 #8
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
    def test_multi_submit(self):
        """
        Test submitting multiple newsletter subscription changes at once
        """
        email = EmailAddress.objects.create(user=self.user)
        data = {
            'email_address': self.user.email,
            'newsletters': [n.id for n in Newsletter.objects.all()]
        }
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid(), form.errors)

        self.assertEqual(0, email.subscriptions.count())
        form.save()
        self.assertEqual(3, email.subscriptions.count())
コード例 #9
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
    def test_unsubscribe(self):
        """
        Make sure removing previous subscriptions for a user works
        """
        email = EmailAddress.objects.create(user=self.user)
        email.subscribe(self.newsletter1)
        data = {
            'email_address': self.user.email
        }
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid())

        self.assertEqual(1, email.subscriptions.count())
        form.save()
        self.assertEqual(0, email.subscriptions.count())
コード例 #10
0
    def test_old_user(self):
        """
        Make sure specifying an existing user modifies that user's subscriptions
        """
        data = {
            'email_address': self.user.email,
            'newsletters': [self.newsletter1.id]
        }
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid())

        self.assertEqual(0, EmailAddress.objects.count())
        form.save()
        self.assertEqual(1, EmailAddress.objects.count())
        self.assertEqual(self.user, EmailAddress.objects.get().user)
        self.assertEqual(self.user.email, EmailAddress.objects.get().email)
コード例 #11
0
    def test_new_email(self):
        """
        Make sure saving the form creates a new user
        """
        test_email = '*****@*****.**'
        data = {
            'email_address': test_email,
            'newsletters': [self.newsletter1.id]
        }
        form = SubscriptionForm(data=data)
        self.assertTrue(form.is_valid())

        self.assertEqual(0, EmailAddress.objects.count())
        form.save()
        self.assertEqual(1, EmailAddress.objects.count())
        self.assertEqual(test_email, EmailAddress.objects.get().email)
コード例 #12
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
    def test_old_user(self):
        """
        Make sure specifying an existing user modifies that user's subscriptions
        """
        data = {
            'email_address': self.user.email,
            'newsletters': [self.newsletter1.id]
        }
        form = SubscriptionForm(data=data, user=self.user)
        self.assertTrue(form.is_valid())

        self.assertEqual(0, EmailAddress.objects.count())
        form.save()
        self.assertEqual(1, EmailAddress.objects.count())
        self.assertEqual(self.user, EmailAddress.objects.get().user)
        self.assertEqual(self.user.email, EmailAddress.objects.get().email)
コード例 #13
0
ファイル: tests.py プロジェクト: DarkHorseComics/django-nova
    def test_new_email(self):
        """
        Make sure saving the form creates a new user
        """
        test_email = '*****@*****.**'
        data = {
            'email_address': test_email,
            'newsletters': [self.newsletter1.id]
        }
        form = SubscriptionForm(data=data)
        self.assertTrue(form.is_valid())

        self.assertEqual(0, EmailAddress.objects.count())
        form.save()
        self.assertEqual(1, EmailAddress.objects.count())
        self.assertEqual(test_email, EmailAddress.objects.get().email)
コード例 #14
0
ファイル: views.py プロジェクト: DarkHorseComics/django-nova
def update_subscriptions(request, template_name='nova/subscribe.html', redirect_url=None, extra_context=None):
    """
    View that allows existing users (or even new users) to modify their subscriptions
    """
    if request.method == "POST":
        form = SubscriptionForm(data=request.POST, user=request.user)
        if form.is_valid():
            form.save()
            return redirect_to(request, redirect_url)
    else:
        form = SubscriptionForm(user=request.user)

    context = {
        'form': form
    }
    if extra_context:
        context.update(extra_context)
    return render_to_response(template_name, context, RequestContext(request))
コード例 #15
0
    def test_inactive_newsletters(self):
        """
        Make sure inactive newsletters don't get rendered
        """
        inactive_newsletter = self.newsletter1
        inactive_newsletter.active = False
        inactive_newsletter.save()

        form = SubscriptionForm(user=self.user)
        soup = BeautifulSoup(form.as_ul())
        self.assertEqual(
            2, len(soup.findAll('input', attrs={'name': 'newsletters'})), soup)
        self.assertEqual(
            0,
            len(
                soup.findAll('input',
                             attrs={
                                 'name': 'newsletters',
                                 'value': inactive_newsletter.id
                             })))
コード例 #16
0
def update_subscriptions(request,
                         template_name='nova/subscribe.html',
                         redirect_url=None,
                         extra_context=None):
    """
    View that allows existing users (or even new users) to modify their subscriptions
    """
    if request.method == "POST":
        form = SubscriptionForm(data=request.POST, user=request.user)
        if form.is_valid():
            form.save()
            return redirect_to(request, redirect_url)
    else:
        form = SubscriptionForm(user=request.user)

    context = {'form': form}
    if extra_context:
        context.update(extra_context)
    return render_to_response(template_name, context, RequestContext(request))