def test_handling_fee_precedences_1(self): # setting handling fee on event > default of account tt = create_tickettype(100, 10) link_tickettype_to_event(tt, self.event) self.account.set_handling_fee(50) self.event.set_handling_fee(40) self.assertEqual(tt.get_handling_fee(), 40)
def setUp(self): super(TicketAddingTestCase, self).setUp() create_currency("EUR", "Euro") self.event = start_event(self.account.id, "event_name") self.eventpart = add_eventpart(self.event.id) self.event2 = start_event(self.account2.id, "event_name2") self.eventpart2 = add_eventpart(self.event2.id) self.another_tickettype = create_tickettype(50, 10) self.another_tickettype.is_active = True link_tickettype_to_event(self.another_tickettype, self.event2) self.tickettype = create_tickettype(50, 10) self.tickettype.is_active = True link_tickettype_to_event(self.tickettype, self.event) self.free_tickettype = create_tickettype(0, 10) self.free_tickettype.is_active = True link_tickettype_to_event(self.free_tickettype, self.event) self.tickettype2 = create_tickettype(50, 10) self.tickettype2.is_active = True link_tickettype_to_event(self.tickettype2, self.event) self.unlinked_tickettype = create_tickettype(50, 10) self.unlinked_tickettype.is_active = True self.inactive_tickettype = create_tickettype(50, 10) self.inactive_tickettype.is_active = False link_tickettype_to_event(self.inactive_tickettype, self.event)
def setUp(self): super(OrderStartTestCase, self).setUp() self.user = create_user("*****@*****.**") create_currency("EUR", "Euro") self.account = create_account("accountname", "email") self.account.subscription = Subscription(FREE) self.event = start_event(self.account.id, "event_name") self.eventpart = add_eventpart(self.event.id) self.tickettype = create_tickettype(50, 10) self.tickettype.is_active = True link_tickettype_to_event(self.tickettype, self.event)
def test_set_handling_fee_via_account(self): tt = create_tickettype(100, 10) link_tickettype_to_event(tt, self.event) self.account.set_handling_fee(50) self.assertEqual(tt.price, 100) self.assertEqual(tt.get_handling_fee(), 50)
def test_no_handling_fee_on_free_types(self): tt = create_tickettype(0, 10) link_tickettype_to_event(tt, self.event) self.event.set_handling_fee(50) self.assertEqual(tt.get_handling_fee(), 0)
def test_create_tickettype(self): tt = create_tickettype(100, 10) link_tickettype_to_event(tt, self.event) self.assertEqual(tt.units, 10) self.assertEqual(tt.price, 100) self.assertEqual(tt.get_handling_fee(), 0)
def tickettype_create(client_id, tickettype_info, event_id=None, eventpart_id=None): """ Creates a tickettype and links it to either an event or eventpart""" # Set defaults for missing values name = tickettype_info.get('name') description = tickettype_info.get('description') price = tickettype_info.get('price') or defaults.TICKETTYPE_PRICE currency = tickettype_info.get('currency') or defaults.TICKETTYPE_CURRENCY units = tickettype_info.get('units') or defaults.TICKETTYPE_AMOUNT min_order = tickettype_info.get( 'minimum_order') or defaults.TICKETTYPE_MIN_ORDER max_order = tickettype_info.get( 'maximum_order') or defaults.TICKETTYPE_MAX_ORDER sales_start = tickettype_info.get('sales_start') sales_end = tickettype_info.get('sales_start') if event_id is None and eventpart_id is None: raise ex.TickeeError("eventpart_id or event_id required.") # price must not be less than zero if price < 0: raise ex.InvalidPriceError("The price must be 0 or more.") # units must not be less than zero if units < 0: raise ex.InvalidAmountError( "The quantity of tickets must be 0 or more.") # minimum order must not be less than zero if min_order and min_order < 0: raise ex.InvalidAmountError( "The minimum order limit must be 1 or more.") # maximum order must not be less than minimum order if max_order and max_order < min_order: raise ex.InvalidAmountError( "The maximum order limit must be equal or more than the minimum limit." ) # decide on sales start/end times if event_id: if client_id is not None: require_event_owner(client_id, event_id) event = lookup_event_by_id(event_id) default_sale_start = event.get_start_date() default_sale_end = event.get_end_date() elif eventpart_id: if client_id is not None: require_eventpart_owner(client_id, eventpart_id) eventpart = lookup_eventpart_by_id(eventpart_id) default_sale_start = eventpart.starts_on default_sale_end = eventpart.ends_on else: raise ex.EventPartNotFoundError( 'Tickettype needs to be connect to either an event or eventpart.') if sales_start is None: sales_start = default_sale_start else: sales_start = datetime.datetime.utcfromtimestamp(int(sales_start)) if sales_end is None: sales_end = default_sale_end else: sales_end = datetime.datetime.utcfromtimestamp(int(sales_end)) # create ticket type tickettype = create_tickettype(price, units, currency, name, None, min_order, max_order, sales_start, sales_end) # set description if description is not None: tickettype.set_description(description.get('text'), description.get('language')) # link new tickettype to eventpart / event if event_id: link_tickettype_to_event(tickettype, event) elif eventpart_id: link_tickettype_to_eventpart(tickettype, eventpart) return tickettype_to_dict2(tickettype)
def event_create(client_id, account_short, event_info, eventparts=[]): """ Entrypoint for creating an event and returning its information back as a dictionary. Args: client_id The id of the oauth_client who will organize the event. The event will be created for the account owning this client. account_short event_info eventparts """ account = lookup_account_by_name(account_short) if client_id is not None: require_account_owner(client_id, account) event = start_event(account.id, event_info.get('name') or EVENT_NAME) # create default eventpart if len(eventparts) == 0: add_eventpart(event.id, name=event.name) # add eventparts as described else: for eventpart in eventparts: if eventpart.get('starts_on') is not None: starts_on = datetime.datetime.fromtimestamp(eventpart.get('starts_on')) else: starts_on = defaults.EVENTPART_START minutes = eventpart.get('minutes') if starts_on is not None and minutes is not None: ends_on = None #starts_on + datetime.timedelta(minutes=minutes) else: ends_on = None add_eventpart(event_id=event.id, name=eventpart.get('name'), start_datetime=starts_on, end_datetime=ends_on, venue_id=eventpart.get('venue')) # create ticket types tickettypes = event_info.get('tickettypes') or [] for tickettype_info in tickettypes: # convert sales_end from ts to datetime if tickettype_info.get('sales_end') is not None: tickettype_info['sales_end'] = datetime.datetime.utcfromtimestamp(tickettype_info.get('sales_end')) # create ticket type tt = create_tickettype(price=tickettype_info.get('price') or TICKETTYPE_PRICE, units=tickettype_info.get('units') or TICKETTYPE_AMOUNT, currency=tickettype_info.get('currency') or "EUR", name=tickettype_info.get('name'), sales_end=tickettype_info.get('sales_end')) # link it to the event link_tickettype_to_event(tt, event) return event_to_dict2(event, short=False)