Luke Plant avatar Luke Plant committed 8fb3fb3

Increased test coverage by adding some simple tests for booking 'index' page

Comments (0)

Files changed (1)

cciw/bookings/tests.py

 from cciw.cciwmain.common import get_thisyear
 from cciw.cciwmain.models import Camp
 from cciw.cciwmain.tests.mailhelpers import read_email_url
+from cciw.sitecontent.models import HtmlChunk
+
+
+class CreateCampMixin(object):
+
+    camp_minimum_age = 11
+    camp_maximum_age = 17
+
+    def create_camp(self):
+        # Need to create a Camp that we can choose i.e. is in the future
+        self.camp = Camp.objects.create(year=get_thisyear(), number=1,
+                                        minimum_age=self.camp_minimum_age,
+                                        maximum_age=self.camp_maximum_age,
+                                        start_date=datetime.now() + timedelta(20),
+                                        end_date=datetime.now() + timedelta(27),
+                                        site_id=1)
+
+
+class CreatePricesMixin(object):
+    def add_prices(self):
+        year = get_thisyear()
+        Price.objects.get_or_create(year=year,
+                                    price_type=PRICE_FULL,
+                                    price=Decimal('100.00'))
+        Price.objects.get_or_create(year=year,
+                                    price_type=PRICE_2ND_CHILD,
+                                    price=Decimal('75.00'))
+        Price.objects.get_or_create(year=year,
+                                    price_type=PRICE_3RD_CHILD,
+                                    price=Decimal('50.00'))
+        Price.objects.get_or_create(year=year,
+                                    price_type=PRICE_SOUTH_WALES_TRANSPORT,
+                                    price=Decimal('20.00'))
+
+
+class TestBookingIndex(CreatePricesMixin, CreateCampMixin, TestCase):
+
+    fixtures = ['basic.json']
+
+    def setUp(self):
+        super(TestBookingIndex, self).setUp()
+        HtmlChunk.objects.get_or_create(name="booking_overview")
+        HtmlChunk.objects.get_or_create(name="bookingform_start")
+        HtmlChunk.objects.get_or_create(name="bookingform_end")
+        HtmlChunk.objects.get_or_create(name="no_bookingform_yet")
+
+    def test_show_with_no_prices(self):
+        resp = self.client.get(reverse('cciw.bookings.views.index'))
+        self.assertContains(resp, "Prices for %d have not been finalised yet" % get_thisyear())
+
+
+    def test_show_with_prices(self):
+        self.add_prices()
+        self.create_camp() # need for booking to be open
+        resp = self.client.get(reverse('cciw.bookings.views.index'))
+        self.assertContains(resp, "£100")
 
 
 class TestBookingStart(TestCase):
         self.assertEqual(b.name, 'Mr Booker')
 
 
-class CreatePlaceMixin(LogInMixin):
+class CreatePlaceMixin(CreatePricesMixin, CreateCampMixin, LogInMixin):
     @property
     def place_details(self):
         return {
             'price_type': '0',
             }
 
-    def add_prices(self):
-        year = get_thisyear()
-        Price.objects.get_or_create(year=year,
-                                    price_type=PRICE_FULL,
-                                    price=Decimal('100.00'))
-        Price.objects.get_or_create(year=year,
-                                    price_type=PRICE_2ND_CHILD,
-                                    price=Decimal('75.00'))
-        Price.objects.get_or_create(year=year,
-                                    price_type=PRICE_3RD_CHILD,
-                                    price=Decimal('50.00'))
-        Price.objects.get_or_create(year=year,
-                                    price_type=PRICE_SOUTH_WALES_TRANSPORT,
-                                    price=Decimal('20.00'))
-
-    camp_minimum_age = 11
-    camp_maximum_age = 17
-
-    def create_camp(self):
-        # Need to create a Camp that we can choose i.e. is in the future
-        self.camp = Camp.objects.create(year=get_thisyear(), number=1,
-                                        minimum_age=self.camp_minimum_age,
-                                        maximum_age=self.camp_maximum_age,
-                                        start_date=datetime.now() + timedelta(20),
-                                        end_date=datetime.now() + timedelta(27),
-                                        site_id=1)
-
     def create_place(self, extra=None):
         # We use public views to create place, to ensure that they are created
         # in the same way that a user would.
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.