Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Made billing view require login
Browse files Browse the repository at this point in the history
  • Loading branch information
melinath committed Apr 27, 2020
1 parent 17539b8 commit 981312f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions brambling/tests/functional/test_user_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.core.urlresolvers import reverse
from django.test import TestCase

from brambling.tests.factories import PersonFactory


class BillingViewTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.password = 'password'
cls.person = PersonFactory(password=cls.password)
super(BillingViewTestCase, cls).setUpTestData()

def test_anonymous_user_redirected_to_login(self):
response = self.client.get('/billing/')
self.assertEqual(response.status_code, 302)
self.assertEqual(
response['Location'],
'{}?next=/billing/'.format(reverse('login')),
)

def test_authenticated_user_gets_billing_settings(self):
self.client.login(
username=self.person.email,
password=self.password,
)
response = self.client.get('/billing/')
self.assertEqual(response.status_code, 200)
response.render()
self.assertIn('Billing settings', response.content)
6 changes: 6 additions & 0 deletions brambling/views/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.sites.shortcuts import get_current_site
from django.core.urlresolvers import reverse
from django.db.models import Max, Sum, Q
from django.http import Http404, HttpResponseRedirect, HttpResponse
from django.utils.decorators import method_decorator
from django.utils.http import urlsafe_base64_decode, is_safe_url
from django.views.generic import (DetailView, CreateView, UpdateView,
TemplateView, View, ListView, DeleteView)
Expand Down Expand Up @@ -146,6 +148,10 @@ class BillingView(TemplateView):
model = Person
template_name = 'brambling/user/billing.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(BillingView, self).dispatch(*args, **kwargs)

def get_context_data(self, **kwargs):
context = super(BillingView, self).get_context_data(**kwargs)
cards_qs = self.request.user.cards.filter(is_saved=True).order_by('-added')
Expand Down

0 comments on commit 981312f

Please sign in to comment.