def test_campers_and_registration(self): event = models.Event( organization=self.organization, name="Test Camper/Registration Event", pricing=self.pricing, registration_pricing_logic=self.registration_pricing_logic, camper_pricing_logic=self.camper_pricing_logic) registration = models.Registration(event=event, attributes={ "number_of_cabins": 3, "number_of_parking_passes": 2 }) campers = [ models.Camper(attributes={"age": 2}), models.Camper(attributes={"age": 17}), models.Camper(attributes={"age": 18}), models.Camper(attributes={"age": 42}) ] price_components = pricing.calculate_price(registration, campers) self.assertEqual( price_components, { "tuition": 1200, "meals": 700, "cabins": 300, "parking_passes": 100, "total": 2300, })
def test_registration_type(self): event = models.Event( organization=self.organization, name="Test Registration Event", pricing=self.pricing, registration_pricing_logic=[ { 'var': 'total', 'exp': { 'if': [ { '==': [ { 'var': 'registration.registration_type' }, 'worktrade', ] }, 100, 200, ] }, }, ], camper_pricing_logic=[], ) # default registration type (None) registration = models.Registration( event=event, attributes={}, ) price_components = pricing.calculate_price(registration, []) self.assertEqual(price_components, { 'campers': [], 'total': 200, }) # 'worktrade' registration type registration = models.Registration( event=event, attributes={}, registration_type=models.RegistrationType( event=event, name='worktrade', label='Work-trade', ), ) price_components = pricing.calculate_price(registration, []) self.assertEqual(price_components, { 'campers': [], 'total': 100, })
def test_calculate_campers(self): event = models.Event( organization=self.organization, name="Test Camper Event", pricing=self.pricing, registration_pricing_logic=[], camper_pricing_logic=self.camper_pricing_logic, ) registration = models.Registration(event=event) campers = [ models.Camper(attributes={"age": 2}), models.Camper(attributes={"age": 17}), models.Camper(attributes={"age": 18}), models.Camper(attributes={"age": 42}), ] price_components = pricing.calculate_price(registration, campers) self.assertEqual( price_components, { "is_adult": 2, "tuition": 1200, "meals": 700, "campers": [ { "is_adult": False, "meals": 50, "total": 250, "tuition": 200 }, { "is_adult": False, "meals": 50, "total": 250, "tuition": 200 }, { "is_adult": True, "meals": 300, "total": 700, "tuition": 400 }, { "is_adult": True, "meals": 300, "total": 700, "tuition": 400 }, ], "total": 1900, })
def test_calculate_registration(self): event = models.Event( organization=self.organization, name="Test Registration Event", pricing=self.pricing, registration_pricing_logic=self.registration_pricing_logic, camper_pricing_logic={}) registration = models.Registration(event=event, attributes={ "number_of_cabins": 3, "number_of_parking_passes": 2 }) price_components = pricing.calculate_price(registration, []) self.assertEqual(price_components, { "cabins": 300, "parking_passes": 100, "total": 400, })
def test_calculate_campers(self): event = models.Event(organization=self.organization, name="Test Camper Event", pricing=self.pricing, registration_pricing_logic={}, camper_pricing_logic=self.camper_pricing_logic) registration = models.Registration(event=event) campers = [ models.Camper(attributes={"age": 2}), models.Camper(attributes={"age": 17}), models.Camper(attributes={"age": 18}), models.Camper(attributes={"age": 42}) ] price_components = pricing.calculate_price(registration, campers) self.assertEqual(price_components, { "tuition": 1200, "meals": 700, "total": 1900, })
def test_dates(self): event = models.Event( organization=self.organization, name="Test Registration Event", start=datetime.datetime(2019, 2, 25, 17, 0, 5, tzinfo=timezone.utc), camper_schema={ "type": "object", "properties": { "birthdate": { "type": "string", "format": "date", }, }, }, pricing=self.pricing, registration_pricing_logic=[ { "var": "date_parts", "exp": [ { "var": "event.start.year" }, { "var": "event.start.month" }, { "var": "event.start.day" }, ], }, ], camper_pricing_logic=[ { "var": "birthdate_parts", "exp": [ { "var": "camper.birthdate.year" }, { "var": "camper.birthdate.month" }, { "var": "camper.birthdate.day" }, ], }, ], ) self.assertIsNotNone(event.start) registration = models.Registration(event=event, attributes={}) camper = models.Camper( registration=registration, attributes={ "birthdate": "2000-12-31", }, ) price_components = pricing.calculate_price(registration, [camper]) self.assertEqual( price_components, { "date_parts": [2019, 2, 25], "campers": [{ "birthdate_parts": [2000, 12, 31] }], })