Luke Plant avatar Luke Plant committed 88e91c8

Ensured that 'add place' cannot be done before adding account details

Comments (0)

Files changed (2)

cciw/bookings/tests.py

 class LogInMixin(object):
     email = 'booker@bookers.com'
 
-    def login(self):
+    def login(self, add_account_details=True):
         # Easiest way is to simulate what the user actually has to do
         self.client.post(reverse('cciw.bookings.views.start'),
                          {'email': self.email})
         url, path, querydata = read_email_url(mail.outbox[-1], "https?://.*/booking/v/.*")
         self.client.get(path, querydata)
+        if add_account_details:
+            BookingAccount.objects.filter(email=self.email).update(name='Joe',
+                                                                   address='123',
+                                                                   post_code='XYZ')
 
 
 class TestAccountDetails(LogInMixin, TestCase):
         self.assertEqual(resp.status_code, 302)
 
     def test_show_if_logged_in(self):
-        self.login()
+        self.login(add_account_details=False)
         resp = self.client.get(self.url)
         self.assertEqual(resp.status_code, 200)
 
     def test_missing_name(self):
-        self.login()
+        self.login(add_account_details=False)
         resp = self.client.post(self.url, {})
         self.assertEqual(resp.status_code, 200)
         self.assertContains(resp, "This field is required")
         """
         Test that we can complete the account details page
         """
-        self.login()
+        self.login(add_account_details=False)
         resp = self.client.post(self.url,
                                 {'name': 'Mr Booker',
                                  'address': '123, A Street',
         resp = self.client.get(self.url)
         self.assertEqual(resp.status_code, 302)
 
+    def test_redirect_if_no_account_details(self):
+        self.login(add_account_details=False)
+        resp = self.client.get(self.url)
+        self.assertEqual(resp.status_code, 302)
+
     def test_show_if_logged_in(self):
         self.login()
         resp = self.client.get(self.url)

cciw/bookings/views.py

     return view
 
 
+def account_details_required(view_func):
+    @wraps(view_func)
+    def view(request, *args, **kwargs):
+        ensure_booking_acount_attr(request)
+        if not request.booking_account.has_account_details():
+            return next_step(request.booking_account)
+        return view_func(request, *args, **kwargs)
+    return view
+
+
 def is_booking_open(year):
     """
     When passed a given year, returns True if booking is open.
     else:
         return HttpResponseRedirect(reverse('cciw.bookings.views.account_details'))
 
+
 class BookingStart(DefaultMetaData, FormMixin, TemplateResponseMixin, ProcessFormView):
     metadata_title = "Booking - email address"
     form_class = EmailForm
 verify_email_failed = BookingVerifyEmailFailed.as_view()
 account_details = booking_account_required(BookingAccountDetails.as_view())
 not_logged_in = BookingNotLoggedIn.as_view()
-add_place = booking_account_required(BookingAddPlace.as_view())
-edit_place = booking_account_required(BookingEditPlace.as_view())
+add_place = booking_account_required(account_details_required(BookingAddPlace.as_view()))
+edit_place = booking_account_required(account_details_required(BookingEditPlace.as_view()))
 list_bookings = booking_account_required(BookingListBookings.as_view())
 pay = booking_account_required(BookingPay.as_view())
 pay_done = csrf_exempt(BookingPayDone.as_view())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.