Esempio n. 1
0
class ReservableHasPriceModifiersTestCase(KakaravaaraTestsBase):
    def setUp(self):
        super(ReservableHasPriceModifiersTestCase, self).setUp()
        self.reservable = ReservableProductFactory()
        self.tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.yesterday = datetime.date.today() - datetime.timedelta(days=1)

    def test_reservable_has_no_modifiers(self):
        self.assertFalse(self.reservable.has_price_modifiers)

    def test_reservable_has_per_person_modifier(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        self.assertTrue(self.reservable.has_price_modifiers)

    def test_reservable_has_period_price_modifiers(self):
        PeriodPriceModifierFactory(product=self.reservable.product,
                                   start_date=self.tomorrow,
                                   end_date=self.tomorrow)
        self.assertTrue(self.reservable.has_price_modifiers)

    def test_reservable_has_only_passed_period_price_modifiers(self):
        PeriodPriceModifierFactory(product=self.reservable.product,
                                   start_date=self.yesterday,
                                   end_date=self.yesterday)
        self.assertFalse(self.reservable.has_price_modifiers)
Esempio n. 2
0
 def setUp(self):
     super(ReservablePricePerPersonTestCase, self).setUp()
     self.request = RequestFactory().get("/")
     self.request.GET = {"persons": 3}
     self.request.shop = self.shop
     self.reservable = ReservableProductFactory(
         pricing_per_person_included=0,
         pricing_per_person_price=Decimal("10.00"),
     )
 def setUp(self):
     super(DateRangeCheckViewTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
     self.reservation = ReservationFactory(
         reservable=self.reservable,
         start_time=datetime.datetime.today(),
         end_time=datetime.datetime.today() + datetime.timedelta(days=3)
     )
     self.today = datetime.date.today()
     self.next = datetime.date.today() + relativedelta.relativedelta(months=1)
 def setUp(self):
     super(ReservablePricePerPersonTestCase, self).setUp()
     self.request = RequestFactory().get("/")
     self.request.GET = {"persons": 3}
     self.request.shop = self.shop
     self.reservable = ReservableProductFactory(
         pricing_per_person_included=0, pricing_per_person_price=Decimal("10.00"),
     )
class ReservablePricePerPersonTestCase(KakaravaaraTestsBase):
    def setUp(self):
        super(ReservablePricePerPersonTestCase, self).setUp()
        self.request = RequestFactory().get("/")
        self.request.GET = {"persons": 3}
        self.request.shop = self.shop
        self.reservable = ReservableProductFactory(
            pricing_per_person_included=0, pricing_per_person_price=Decimal("10.00"),
        )

    def test_reservable_with_pricing_per_person_disabled_person_count_doesnt_change_price(self):
        self.reservable.pricing_per_person = False
        self.reservable.save()
        price = self.reservable.product.get_price(self.request, quantity=1).quantize(Decimal("1.00"))
        shop_product = ShopProduct.objects.get(product_id=self.reservable.product_id, shop=self.shop)
        self.assertEqual(price, shop_product.default_price)

    def test_reservable_with_pricing_per_person_active_person_count_changes_price(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request, quantity=1).quantize(Decimal("1.00"))
        shop_product = ShopProduct.objects.get(product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(price.value, shop_product.default_price_value + 3 * Decimal("10.00"), 6)

    def test_reservable_with_pricing_per_person_active_person_count_changes_price_more_nights(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request, quantity=3).quantize(Decimal("1.00"))
        shop_product = ShopProduct.objects.get(product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(price.value, shop_product.default_price_value * 3 + 3 * Decimal("10.00") * 3, 6)

    def test_reservable_with_pricing_per_person_included_count_zero(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request, quantity=1).quantize(Decimal("1.00"))
        shop_product = ShopProduct.objects.get(product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(price.value, shop_product.default_price_value + 3 * Decimal("10.00"), 6)

    def test_reservable_with_pricing_per_person_included_count_above_zero(self):
        self.reservable.pricing_per_person = True
        self.reservable.pricing_per_person_included = 2
        self.reservable.save()
        price = self.reservable.product.get_price(self.request, quantity=1).quantize(Decimal("1.00"))
        shop_product = ShopProduct.objects.get(product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(price.value, shop_product.default_price_value + Decimal("10.00"), 6)
Esempio n. 6
0
 def setUp(self):
     super(ReservablePricingModulePeriodModifiersTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
     self.product = self.reservable.product
     self.modifier = PeriodPriceModifierFactory(product=self.product)
     # Verify factories
     assert self.modifier.start_date == datetime.date(2015, 11, 1)
     assert self.modifier.end_date == datetime.date(2015, 11, 30)
     self.request = RequestFactory().get("/")
     self.request.shop = self.shop
 def setUp(self):
     super(ReservableSearchViewTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
     self.today = datetime.date.today()
     self.now = datetime.time(15)
     self.next = self.today + relativedelta.relativedelta(months=1)
     self.reservation = ReservationFactory(
         reservable=self.reservable,
         start_time=datetime.datetime.combine(self.today, self.now),
         end_time=datetime.datetime.combine(
             self.today + datetime.timedelta(days=3), self.now))
     self.response = self.client.get(
         reverse('reservations:reservable.search'))
class ReservableHasPriceModifiersTestCase(KakaravaaraTestsBase):
    def setUp(self):
        super(ReservableHasPriceModifiersTestCase, self).setUp()
        self.reservable = ReservableProductFactory()
        self.tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.yesterday = datetime.date.today() - datetime.timedelta(days=1)

    def test_reservable_has_no_modifiers(self):
        self.assertFalse(self.reservable.has_price_modifiers)

    def test_reservable_has_per_person_modifier(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        self.assertTrue(self.reservable.has_price_modifiers)

    def test_reservable_has_period_price_modifiers(self):
        PeriodPriceModifierFactory(
            product=self.reservable.product, start_date=self.tomorrow, end_date=self.tomorrow)
        self.assertTrue(self.reservable.has_price_modifiers)

    def test_reservable_has_only_passed_period_price_modifiers(self):
        PeriodPriceModifierFactory(
            product=self.reservable.product, start_date=self.yesterday, end_date=self.yesterday)
        self.assertFalse(self.reservable.has_price_modifiers)
 def test_get_reserved_dates_for_period_returns_correct_dates(self):
     self.reservable2 = ReservableProductFactory()
     ReservationFactory(
         reservable=self.reservable,
         start_time=datetime.datetime(year=2015, month=6, day=30, hour=15),
         end_time=datetime.datetime(year=2015, month=7, day=5, hour=12)
     )
     ReservationFactory(
         reservable=self.reservable2,
         start_time=datetime.datetime(year=2015, month=7, day=10, hour=12),
         end_time=datetime.datetime(year=2015, month=7, day=15, hour=12)
     )
     dates = Reservation.get_reserved_days_for_period(
         start_date=datetime.date(year=2015, month=6, day=30),
         end_date=datetime.date(year=2015, month=7, day=15)
     )
     self.assertEquals(len(dates), 10)
class DateRangeCheckViewTestCase(ReservableViewsBaseTestCase):
    def setUp(self):
        super(DateRangeCheckViewTestCase, self).setUp()
        self.reservable = ReservableProductFactory()
        self.reservation = ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime.today(),
            end_time=datetime.datetime.today() + datetime.timedelta(days=3)
        )
        self.today = datetime.date.today()
        self.next = datetime.date.today() + relativedelta.relativedelta(months=1)

    def test_view_returns_bad_request_on_missing_parameters(self):
        response = self.client.get(reverse('reservations:check_period'))
        self.assertEqual(response.status_code, 400)
        url = "%s?reservable_id=1" % reverse('reservations:check_period')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 400)
        url = "%s?start=2015-10-01" % reverse('reservations:check_period')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 400)
        url = "%s?end=2015-10-01" % reverse('reservations:check_period')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 400)

    def test_free_period_should_return_period_is_free(self):
        request = RequestFactory().get("/")
        request.shop = self.shop
        response = self.client.get(
            "%s?reservable_id=%s&start=%s&end=%s" % (
                reverse('reservations:check_period'),
                self.reservable.id,
                self.next.strftime("%Y-%m-%d"),
                (self.next + datetime.timedelta(days=3)).strftime("%Y-%m-%d")
            )
        )
        price_info = self.reservable.product.get_price_info(request, quantity=3)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            "result": True,
            "price": {
                "total": format_money(price_info.price),
                "has_extra_info": False,
            }
        })

    def test_free_period_should_return_period_is_free_and_extra_info(self):
        request = RequestFactory().get("/")
        request.GET = {"persons": 3}
        request.shop = self.shop
        self.reservable.pricing_per_person = True
        self.reservable.pricing_per_person_included = 2
        self.reservable.pricing_per_person_price = Decimal("10.00")
        self.reservable.save()
        response = self.client.get(
            "%s?reservable_id=%s&start=%s&end=%s&persons=3" % (
                reverse('reservations:check_period'),
                self.reservable.id,
                self.next.strftime("%Y-%m-%d"),
                (self.next + datetime.timedelta(days=3)).strftime("%Y-%m-%d")
            )
        )
        price_info = self.reservable.product.get_price_info(request, quantity=3)
        self.assertJSONEqual(response.content.decode("utf-8"), {
            "result": True,
            "price": {
                "total": format_money(price_info.price),
                "period_modifiers": str(price_info.period_modifiers.quantize(Decimal("1.00"))),
                "per_person_modifiers": str(price_info.per_person_modifiers.quantize(Decimal("1.00"))),
                "has_extra_info": True,
                "special_period_str": "Special period",
                "persons_count_str": "Person count",
            }
        })

    def test_reserved_period_should_return_period_is_reserved(self):
        response = self.client.get(
            "%s?reservable_id=%s&start=%s&end=%s" % (
                reverse('reservations:check_period'),
                self.reservable.id,
                self.today.strftime("%Y-%m-%d"),
                (self.today + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
            )
        )
        self.assertJSONEqual(response.content.decode("utf-8"), {
            "result": False,
            "price": None,
        })
Esempio n. 11
0
 def setUp(self):
     super(ReservableHasPriceModifiersTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
     self.tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     self.yesterday = datetime.date.today() - datetime.timedelta(days=1)
Esempio n. 12
0
 def setUp(self):
     super(ReservableHasPriceModifiersTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
     self.tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     self.yesterday = datetime.date.today() - datetime.timedelta(days=1)
Esempio n. 13
0
class ReservablePricePerPersonTestCase(KakaravaaraTestsBase):
    def setUp(self):
        super(ReservablePricePerPersonTestCase, self).setUp()
        self.request = RequestFactory().get("/")
        self.request.GET = {"persons": 3}
        self.request.shop = self.shop
        self.reservable = ReservableProductFactory(
            pricing_per_person_included=0,
            pricing_per_person_price=Decimal("10.00"),
        )

    def test_reservable_with_pricing_per_person_disabled_person_count_doesnt_change_price(
            self):
        self.reservable.pricing_per_person = False
        self.reservable.save()
        price = self.reservable.product.get_price(self.request,
                                                  quantity=1).quantize(
                                                      Decimal("1.00"))
        shop_product = ShopProduct.objects.get(
            product_id=self.reservable.product_id, shop=self.shop)
        self.assertEqual(price, shop_product.default_price)

    def test_reservable_with_pricing_per_person_active_person_count_changes_price(
            self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request,
                                                  quantity=1).quantize(
                                                      Decimal("1.00"))
        shop_product = ShopProduct.objects.get(
            product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(
            price.value,
            shop_product.default_price_value + 3 * Decimal("10.00"), 6)

    def test_reservable_with_pricing_per_person_active_person_count_changes_price_more_nights(
            self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request,
                                                  quantity=3).quantize(
                                                      Decimal("1.00"))
        shop_product = ShopProduct.objects.get(
            product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(
            price.value,
            shop_product.default_price_value * 3 + 3 * Decimal("10.00") * 3, 6)

    def test_reservable_with_pricing_per_person_included_count_zero(self):
        self.reservable.pricing_per_person = True
        self.reservable.save()
        price = self.reservable.product.get_price(self.request,
                                                  quantity=1).quantize(
                                                      Decimal("1.00"))
        shop_product = ShopProduct.objects.get(
            product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(
            price.value,
            shop_product.default_price_value + 3 * Decimal("10.00"), 6)

    def test_reservable_with_pricing_per_person_included_count_above_zero(
            self):
        self.reservable.pricing_per_person = True
        self.reservable.pricing_per_person_included = 2
        self.reservable.save()
        price = self.reservable.product.get_price(self.request,
                                                  quantity=1).quantize(
                                                      Decimal("1.00"))
        shop_product = ShopProduct.objects.get(
            product_id=self.reservable.product_id, shop=self.shop)
        self.assertAlmostEqual(
            price.value, shop_product.default_price_value + Decimal("10.00"),
            6)
 def setUp(self):
     super(ReservationsGetReservedDatesTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
class ReservationsGetReservedDatesTestCase(KakaravaaraTestsBase):
    def setUp(self):
        super(ReservationsGetReservedDatesTestCase, self).setUp()
        self.reservable = ReservableProductFactory()

    def test_get_reserved_dates_returns_correct_dates(self):
        ReservationFactory(reservable=self.reservable,
                           start_time=datetime.datetime(year=2015,
                                                        month=6,
                                                        day=30,
                                                        hour=15),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=5,
                                                      hour=12))
        ReservationFactory(reservable=self.reservable,
                           start_time=datetime.datetime(year=2015,
                                                        month=7,
                                                        day=10,
                                                        hour=12),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=15,
                                                      hour=12))
        dates = self.reservable.get_reserved_dates(start=datetime.date(
            year=2015, month=5, day=1),
                                                   end=datetime.date(year=2015,
                                                                     month=8,
                                                                     day=1))
        self.assertEquals(len(dates), 10)

    def test_get_reserved_dates_for_period_returns_correct_dates(self):
        self.reservable2 = ReservableProductFactory()
        ReservationFactory(reservable=self.reservable,
                           start_time=datetime.datetime(year=2015,
                                                        month=6,
                                                        day=30,
                                                        hour=15),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=5,
                                                      hour=12))
        ReservationFactory(reservable=self.reservable2,
                           start_time=datetime.datetime(year=2015,
                                                        month=7,
                                                        day=10,
                                                        hour=12),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=15,
                                                      hour=12))
        dates = Reservation.get_reserved_days_for_period(
            start_date=datetime.date(year=2015, month=6, day=30),
            end_date=datetime.date(year=2015, month=7, day=15))
        self.assertEquals(len(dates), 10)

    def test_is_period_free(self):
        ReservationFactory(reservable=self.reservable,
                           start_time=datetime.datetime(year=2015,
                                                        month=6,
                                                        day=30,
                                                        hour=15),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=5,
                                                      hour=12))
        ReservationFactory(reservable=self.reservable,
                           start_time=datetime.datetime(year=2015,
                                                        month=7,
                                                        day=10,
                                                        hour=12),
                           end_time=datetime.datetime(year=2015,
                                                      month=7,
                                                      day=15,
                                                      hour=12))
        self.assertFalse(
            self.reservable.is_period_days_free(
                datetime.date(year=2015, month=6, day=27),
                datetime.date(year=2015, month=7, day=3)))
        self.assertTrue(
            self.reservable.is_period_days_free(
                datetime.date(year=2015, month=6, day=27),
                datetime.date(year=2015, month=6, day=29)))
        self.assertTrue(
            self.reservable.is_period_days_free(
                datetime.date(year=2015, month=6, day=27),
                datetime.date(year=2015, month=6, day=30)))
 def setUp(self):
     super(ReservableOrderCreatorTestCase, self).setUp()
     self.request = RequestFactory().get("/")
     self.reservable = ReservableProductFactory()
     self.roc = ReservableOrderCreator(request=self.request)
 def setUp(self):
     super(ReservationsGetReservedDatesTestCase, self).setUp()
     self.reservable = ReservableProductFactory()
class ReservationsGetReservedDatesTestCase(KakaravaaraTestsBase):

    def setUp(self):
        super(ReservationsGetReservedDatesTestCase, self).setUp()
        self.reservable = ReservableProductFactory()

    def test_get_reserved_dates_returns_correct_dates(self):
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=6, day=30, hour=15),
            end_time=datetime.datetime(year=2015, month=7, day=5, hour=12)
        )
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=7, day=10, hour=12),
            end_time=datetime.datetime(year=2015, month=7, day=15, hour=12)
        )
        dates = self.reservable.get_reserved_dates(
            start=datetime.date(year=2015, month=5, day=1),
            end=datetime.date(year=2015, month=8, day=1)
        )
        self.assertEquals(len(dates), 10)

    def test_get_reserved_dates_for_period_returns_correct_dates(self):
        self.reservable2 = ReservableProductFactory()
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=6, day=30, hour=15),
            end_time=datetime.datetime(year=2015, month=7, day=5, hour=12)
        )
        ReservationFactory(
            reservable=self.reservable2,
            start_time=datetime.datetime(year=2015, month=7, day=10, hour=12),
            end_time=datetime.datetime(year=2015, month=7, day=15, hour=12)
        )
        dates = Reservation.get_reserved_days_for_period(
            start_date=datetime.date(year=2015, month=6, day=30),
            end_date=datetime.date(year=2015, month=7, day=15)
        )
        self.assertEquals(len(dates), 10)

    def test_get_reserved_dates_for_period_returns_correct_dates__spanning_months(self):
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=6, day=30, hour=15),
            end_time=datetime.datetime(year=2015, month=8, day=5, hour=12)
        )
        dates = Reservation.get_reserved_days_for_period(
            start_date=datetime.date(year=2015, month=7, day=15),
            end_date=datetime.date(year=2015, month=7, day=20)
        )
        self.assertEquals(len(dates), 6)

    def test_is_period_free(self):
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=6, day=30, hour=15),
            end_time=datetime.datetime(year=2015, month=7, day=5, hour=12)
        )
        ReservationFactory(
            reservable=self.reservable,
            start_time=datetime.datetime(year=2015, month=7, day=10, hour=12),
            end_time=datetime.datetime(year=2015, month=7, day=15, hour=12)
        )
        self.assertFalse(self.reservable.is_period_days_free(
            datetime.date(year=2015, month=6, day=27),
            datetime.date(year=2015, month=7, day=3)
        ))
        self.assertTrue(self.reservable.is_period_days_free(
            datetime.date(year=2015, month=6, day=27),
            datetime.date(year=2015, month=6, day=29)
        ))
        self.assertTrue(self.reservable.is_period_days_free(
            datetime.date(year=2015, month=6, day=27),
            datetime.date(year=2015, month=6, day=30)
        ))