Commits

Luke Plant committed fe62dda

Test cleanups

Comments (0)

Files changed (1)

cciw/bookings/tests.py

                                                                    address='123',
                                                                    post_code='XYZ')
 
+    def get_account(self):
+        return BookingAccount.objects.get(email=self.email)
+
 
 class TestAccountDetails(LogInMixin, TestCase):
 
         self.login()
         self.add_prices()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         resp = self.client.get(reverse('cciw.bookings.views.edit_place', kwargs={'id':str(b.id)}))
         self.assertEqual(resp.status_code, 200)
         self.login()
         self.add_prices()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         resp = self.client.post(reverse('cciw.bookings.views.edit_place', kwargs={'id':str(b.id)}), {})
         self.assertEqual(resp.status_code, 200)
         self.login()
         self.add_prices()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
 
         data = self.place_details.copy()
         self.login()
         self.add_prices()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
 
         for state in [BOOKING_APPROVED, BOOKING_BOOKED]:
     def test_move_to_shelf(self):
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         self.assertEqual(b.shelved, False)
         resp = self.client.post(self.url)
     def test_move_to_basket(self):
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         b.shelved = True
         b.save()
     def test_delete_place(self):
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         resp = self.client.post(self.url)
 
     def test_edit_place_btn(self):
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         resp = self.client.post(self.url)
 
         state_token = re.search(r'name="state_token" value="(.*)"', resp.content).groups()[0]
         resp2 = self.client.post(self.url, {'state_token': state_token,
                                             'book_now': '1'})
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         self.assertEqual(b.state, BOOKING_BOOKED)
         self.assertEqual(resp2.status_code, 302)
         state_token = re.search(r'name="state_token" value="(.*)"', resp.content).groups()[0]
         resp2 = self.client.post(self.url, {'state_token': state_token,
                                             'book_now': '1'})
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         self.assertEqual(b.state, BOOKING_INFO_COMPLETE)
         self.assertContains(resp2, "These places cannot be booked")
         state_token = re.search(r'name="state_token" value="(.*)"', resp.content).groups()[0]
         resp2 = self.client.post(self.url, {'state_token': state_token,
                                             'book_now': '1'})
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         for b in acc.bookings.all():
             self.assertEqual(b.state, BOOKING_INFO_COMPLETE)
         self.assertContains(resp2, "These places cannot be booked")
         state_token = re.search(r'name="state_token" value="(.*)"', resp.content).groups()[0]
 
         # Now modify
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         b = acc.bookings.all()[0]
         b.south_wales_transport = True
         b.auto_set_amount_due()
         self.create_place()
 
         # Put some money in my account.
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         acc.total_received = acc.bookings.all()[0].amount_due
         acc.save()
 
         self.assertEqual(b.booking_expires, None)
 
         # balance should be zero
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         self.assertEqual(acc.get_balance(), Decimal('0.00'))
         self.assertEqual(acc.get_balance(confirmed_only=True), Decimal('0.00'))
 
         self.login()
         self.create_place()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         acc.bookings.all().update(state=BOOKING_BOOKED)
 
         resp = self.client.get(reverse('cciw.bookings.views.pay'))
     def test_receive_payment(self):
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         book_basket_now(acc.bookings.basket(self.camp.year))
         self.assertTrue(acc.bookings.all()[0].booking_expires is not None)
 
         p = Price.objects.get(year=get_thisyear(), price_type=PRICE_FULL).price
         acc.receive_payment(p)
 
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
 
         # Check we updated the account
         self.assertEqual(acc.total_received, p)
         self.login()
         self.create_place()
         self.create_place({'price_type': PRICE_2ND_CHILD})
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         book_basket_now(acc.bookings.basket(self.camp.year))
         self.assertTrue(acc.bookings.all()[0].booking_expires is not None)
 
 
         self.login()
         self.create_place()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         book_basket_now(acc.bookings.basket(self.camp.year))
 
         mail.outbox = []
         self.create_place()
         self.create_place({'name': 'Another Child'})
 
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         book_basket_now(acc.bookings.basket(self.camp.year))
 
         mail.outbox = []
 
     def test_account_json(self):
         self.login()
-        acc = BookingAccount.objects.get(email=self.email)
+        acc = self.get_account()
         acc.address = '123 Main Street'
         acc.save()