def test_get_seats(self): ticket_type = TicketType( 'STALLS', price_bands=[ PriceBand('A/pool', Discount('ADULT'), allows_leaving_single_seats='always', seat_blocks=[ SeatBlock(2, seats=[ Seat(id_='A1'), Seat(id_='A2'), ]), SeatBlock(3, seats=[ Seat(id_='B1'), Seat(id_='B2'), Seat(id_='B3'), ]), ]), PriceBand('B/pool', Discount('ADULT'), allows_leaving_single_seats='always', seat_blocks=[ SeatBlock(1, seats=[ Seat(id_='C1'), ]), SeatBlock(2, seats=[ Seat(id_='D1'), Seat(id_='D2'), ]), ]), ]) seats = ticket_type.get_seats() assert seats[0].id == 'A1' assert seats[1].id == 'A2' assert seats[2].id == 'B1' assert seats[3].id == 'B2' assert seats[4].id == 'B3' assert seats[5].id == 'C1' assert seats[6].id == 'D1' assert seats[7].id == 'D2'
def from_api_data(cls, data): """Creates a new **TicketOrder** object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a ticket order. Returns: :class:`TicketOrder <pyticketswitch.order.TicketOrder>`: a new :class:`TicketOrder <pyticketswitch.order.TicketOrder>` object populated with the data from the api. """ kwargs = { 'code': data.get('discount_code'), 'number_of_seats': data.get('no_of_seats'), 'description': data.get('discount_desc'), } # Below we are explicital checking for not None because we want to # differentiate between situtations where a value is 0 and a value is # missing from the response. raw_seatprice = data.get('sale_seatprice') if raw_seatprice is not None: kwargs.update(seatprice=raw_seatprice) raw_surcharge = data.get('sale_surcharge') if raw_surcharge is not None: kwargs.update(surcharge=raw_surcharge) raw_total_seatprice = data.get('total_sale_seatprice') if raw_total_seatprice is not None: kwargs.update(total_seatprice=raw_total_seatprice) raw_total_surcharge = data.get('total_sale_surcharge') if raw_total_surcharge is not None: kwargs.update(total_surcharge=raw_total_surcharge) seats_data = data.get('seats') if seats_data: seats = [ Seat.from_api_data(seat) for seat in seats_data ] kwargs.update(seats=seats) return cls(**kwargs)
def from_api_data(cls, data): """Creates a new **TicketOrder** object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a ticket order. Returns: :class:`TicketOrder <pyticketswitch.order.TicketOrder>`: a new :class:`TicketOrder <pyticketswitch.order.TicketOrder>` object populated with the data from the api. """ kwargs = { 'code': data.get('discount_code'), 'number_of_seats': data.get('no_of_seats'), 'description': data.get('discount_desc'), } # Below we are explicital checking for not None because we want to # differentiate between situtations where a value is 0 and a value is # missing from the response. raw_seatprice = data.get('sale_seatprice') if raw_seatprice is not None: kwargs.update(seatprice=raw_seatprice) raw_surcharge = data.get('sale_surcharge') if raw_surcharge is not None: kwargs.update(surcharge=raw_surcharge) raw_total_seatprice = data.get('total_sale_seatprice') if raw_total_seatprice is not None: kwargs.update(total_seatprice=raw_total_seatprice) raw_total_surcharge = data.get('total_sale_surcharge') if raw_total_surcharge is not None: kwargs.update(total_surcharge=raw_total_surcharge) seats_data = data.get('seats') if seats_data: seats = [Seat.from_api_data(seat) for seat in seats_data] kwargs.update(seats=seats) return cls(**kwargs)
def test_get_seat_ids_where_ids_are_missing(self): ticket_order_one = TicketOrder('a', seats=[ Seat('A1'), Seat('A2'), Seat(None), ]) ticket_order_two = TicketOrder('b', seats=[ Seat('B1'), Seat(None), Seat('B3'), ]) order = Order(1, ticket_orders=[ticket_order_one, ticket_order_two]) seat_ids = order.get_seat_ids() assert seat_ids == ['A1', 'A2', 'B1', 'B3']
def test_unique_seat_text(self): ticket_order_one = TicketOrder('a', seats=[ Seat('A1', seat_text='Hell bad'), Seat('A2'), Seat('A3'), ]) ticket_order_two = TicketOrder('b', seats=[ Seat('B1', seat_text='Hell good'), Seat('B2'), Seat('B3'), ]) order = Order(1, ticket_orders=[ticket_order_one, ticket_order_two]) seat_text = order.unique_seat_text() assert 'Hell bad' in seat_text assert 'Hell good' in seat_text
def test_get_seats(self): ticket_order_one = TicketOrder('a', seats=[ Seat('A1'), Seat('A2'), Seat('A3'), ]) ticket_order_two = TicketOrder('b', seats=[ Seat('B1'), Seat('B2'), Seat('B3'), ]) order = Order(1, ticket_orders=[ticket_order_one, ticket_order_two]) seats = order.get_seats() assert [seat.id for seat in seats] == [ 'A1', 'A2', 'A3', 'B1', 'B2', 'B3', ]
def from_api_data(self): data = { 'col_id': '361', 'full_id': 'GQ361', 'is_restricted_view': True, 'row_id': 'GQ', 'seat_text_code': 'NEARTOILET', 'separator': '-', 'barcode': '0987654321', } seat = Seat.from_api_data(data) assert seat.id == 'GQ-361' assert seat.column == '361' assert seat.row == 'GQ' assert seat.separator == '-' assert seat.is_restricted is True assert seat.text_code == 'NEARTOILET' assert seat.barcode == '0987654321'
def from_api_data(cls, data): """Creates a new **PriceBand** object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a price band. Returns: :class:`PriceBand <pyticketswitch.order.PriceBand>`: a new :class:`PriceBand <pyticketswitch.order.PriceBand>` object populated with the data from the api. """ api_cost_range = data.get('cost_range', {}) api_no_singles_cost_range = api_cost_range.get('no_singles_cost_range', {}) cost_range = None no_singles_cost_range = None if api_cost_range: api_cost_range['singles'] = True cost_range = CostRange.from_api_data(api_cost_range) if api_no_singles_cost_range: api_no_singles_cost_range['singles'] = False no_singles_cost_range = CostRange.from_api_data( api_no_singles_cost_range) discount = Discount.from_api_data(data) kwargs = { 'code': data.get('price_band_code'), 'description': data.get('price_band_desc'), 'availability': data.get('number_available'), 'cost_range': cost_range, 'no_singles_cost_range': no_singles_cost_range, 'default_discount': discount, 'example_seats_are_real': data.get('example_seats_are_real', True), 'allows_leaving_single_seats': data.get('allows_leaving_single_seats'), 'percentage_saving': data.get('percentage_saving'), 'is_offer': data.get('is_offer'), } example_seats_data = data.get('example_seats') if example_seats_data: example_seats = [ Seat.from_api_data(seat) for seat in example_seats_data ] kwargs.update(example_seats=example_seats) seat_block_data = data.get('free_seat_blocks') if seat_block_data: separators_by_row = seat_block_data.get('separators_by_row') restricted_view_seats = seat_block_data.get( 'restricted_view_seats') seats_by_text_message = seat_block_data.get( 'seats_by_text_message') blocks_by_row = seat_block_data.get('blocks_by_row') seat_blocks = [] if blocks_by_row: for row_id, row in blocks_by_row.items(): for block in row: separator = separators_by_row.get(row_id) seat_block = SeatBlock.from_api_data( block=block, row_id=row_id, separator=separator, restricted_view_seats=restricted_view_seats, seats_by_text_message=seats_by_text_message, ) seat_blocks.append(seat_block) kwargs.update(seat_blocks=seat_blocks) user_commission_data = data.get('predicted_user_commission') if user_commission_data: user_commission = Commission.from_api_data(user_commission_data) kwargs.update(user_commission=user_commission) discounts_data = data.get('possible_discounts', {}).get('discount') if discounts_data: discounts = [ Discount.from_api_data(discount_data) for discount_data in discounts_data ] kwargs.update(discounts=discounts) kwargs.update(SeatPricingMixin.kwargs_from_api_data(data)) return cls(**kwargs)
def from_api_data(cls, data): """Creates a new **PriceBand** object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a price band. Returns: :class:`PriceBand <pyticketswitch.order.PriceBand>`: a new :class:`PriceBand <pyticketswitch.order.PriceBand>` object populated with the data from the api. """ api_cost_range = data.get('cost_range', {}) api_no_singles_cost_range = api_cost_range.get('no_singles_cost_range', {}) cost_range = None no_singles_cost_range = None if api_cost_range: api_cost_range['singles'] = True cost_range = CostRange.from_api_data(api_cost_range) if api_no_singles_cost_range: api_no_singles_cost_range['singles'] = False no_singles_cost_range = CostRange.from_api_data( api_no_singles_cost_range) discount = Discount.from_api_data(data) kwargs = { 'code': data.get('price_band_code'), 'description': data.get('price_band_desc'), 'availability': data.get('number_available'), 'cost_range': cost_range, 'no_singles_cost_range': no_singles_cost_range, 'default_discount': discount, 'example_seats_are_real': data.get('example_seats_are_real', True), 'allows_leaving_single_seats': data.get('allows_leaving_single_seats'), } example_seats_data = data.get('example_seats') if example_seats_data: example_seats = [ Seat.from_api_data(seat) for seat in example_seats_data ] kwargs.update(example_seats=example_seats) seat_block_data = data.get('free_seat_blocks') if seat_block_data: separators_by_row = seat_block_data.get('separators_by_row') restricted_view_seats = seat_block_data.get('restricted_view_seats') seats_by_text_message = seat_block_data.get('seats_by_text_message') blocks_by_row = seat_block_data.get('blocks_by_row') seat_blocks = [] if blocks_by_row: for row_id, row in blocks_by_row.items(): for block in row: separator = separators_by_row.get(row_id) seat_block = SeatBlock.from_api_data( block=block, row_id=row_id, separator=separator, restricted_view_seats=restricted_view_seats, seats_by_text_message=seats_by_text_message, ) seat_blocks.append(seat_block) kwargs.update(seat_blocks=seat_blocks) user_commission_data = data.get('predicted_user_commission') if user_commission_data: user_commission = Commission.from_api_data(user_commission_data) kwargs.update(user_commission=user_commission) discounts_data = data.get('possible_discounts', {}).get('discount') if discounts_data: discounts = [ Discount.from_api_data(discount_data) for discount_data in discounts_data ] kwargs.update(discounts=discounts) kwargs.update(SeatPricingMixin.kwargs_from_api_data(data)) return cls(**kwargs)