Пример #1
0
    def test_non_offer_combined_price_missing_prices(self):
        inst = SeatPricingMixin(non_offer_seatprice=123.45)
        with pytest.raises(AssertionError):
            inst.non_offer_combined_price()

        inst = SeatPricingMixin(non_offer_surcharge=6.78)
        with pytest.raises(AssertionError):
            inst.non_offer_combined_price()
Пример #2
0
    def test_non_offer_combined_price_missing_prices(self):
        inst = SeatPricingMixin(non_offer_seatprice=123.45)
        with pytest.raises(AssertionError):
            inst.non_offer_combined_price()

        inst = SeatPricingMixin(non_offer_surcharge=6.78)
        with pytest.raises(AssertionError):
            inst.non_offer_combined_price()
Пример #3
0
    def test_kwargs_from_api_data(self):

        data = {
            'sale_seatprice': 160,
            'sale_surcharge': 5.5,
            'non_offer_sale_seatprice': 200,
            'non_offer_sale_surcharge': 5.5,
        }

        kwargs = SeatPricingMixin.kwargs_from_api_data(data)

        assert kwargs['seatprice'] == 160.00
        assert kwargs['surcharge'] == 5.5
        assert kwargs['non_offer_seatprice'] == 200
        assert kwargs['non_offer_surcharge'] == 5.5
Пример #4
0
    def test_kwargs_from_api_data(self):

        data = {
            'sale_seatprice': 160,
            'sale_surcharge': 5.5,
            'non_offer_sale_seatprice': 200,
            'non_offer_sale_surcharge': 5.5,
        }

        kwargs = SeatPricingMixin.kwargs_from_api_data(data)

        assert kwargs['seatprice'] == 160.00
        assert kwargs['surcharge'] == 5.5
        assert kwargs['non_offer_seatprice'] == 200
        assert kwargs['non_offer_surcharge'] == 5.5
Пример #5
0
    def from_api_data(cls, data):
        """Creates a new Discount object from API data from ticketswitch.

        Args:
            data (dict): the part of the response from a ticketswitch API call
                that concerns a discount.

        Returns:
            :class:`Discount <pyticketswitch.discount.Discount>`: a new
            :class:`Discount <pyticketswitch.discount.Discount>` object
            populated with the data from the api.

        """
        gross_commission = data.get('predicted_gross_commission')
        if gross_commission:
            gross_commission = Commission.from_api_data(gross_commission)

        user_commission = data.get('predicted_user_commission')
        if user_commission:
            user_commission = Commission.from_api_data(user_commission)

        kwargs = {
            'code': data.get('discount_code'),
            'description': data.get('discount_desc'),
            'disallowed_seat_nos': data.get('discount_disallowed_seat_nos'),
            'price_band_code': data.get('price_band_code'),
            'is_offer': data.get('is_offer', False),
            'seatprice': data.get('sale_seatprice'),
            'surcharge': data.get('sale_surcharge'),
            'non_offer_seatprice': data.get('non_offer_sale_seatprice'),
            'non_offer_surcharge': data.get('non_offer_sale_surcharge'),
            'availability': data.get('number_available'),
            'percentage_saving': data.get('percentage_saving'),
            'absolute_saving': data.get('absolute_saving'),
            'gross_commission': gross_commission,
            'user_commission': user_commission,
        }
        kwargs.update(SeatPricingMixin.kwargs_from_api_data(data))

        return cls(**kwargs)
Пример #6
0
    def from_api_data(cls, data):
        """Creates a new Discount object from API data from ticketswitch.

        Args:
            data (dict): the part of the response from a ticketswitch API call
                that concerns a discount.

        Returns:
            :class:`Discount <pyticketswitch.discount.Discount>`: a new
            :class:`Discount <pyticketswitch.discount.Discount>` object
            populated with the data from the api.

        """
        gross_commission = data.get('predicted_gross_commission')
        if gross_commission:
            gross_commission = Commission.from_api_data(gross_commission)

        user_commission = data.get('predicted_user_commission')
        if user_commission:
            user_commission = Commission.from_api_data(user_commission)

        kwargs = {
            'code': data.get('discount_code'),
            'description': data.get('discount_desc'),
            'disallowed_seat_nos': data.get('discount_disallowed_seat_nos'),
            'price_band_code': data.get('price_band_code'),
            'is_offer': data.get('is_offer', False),
            'seatprice': data.get('sale_seatprice'),
            'surcharge': data.get('sale_surcharge'),
            'non_offer_seatprice': data.get('non_offer_sale_seatprice'),
            'non_offer_surcharge': data.get('non_offer_sale_surcharge'),
            'availability': data.get('number_available'),
            'percentage_saving': data.get('percentage_saving'),
            'absolute_saving': data.get('absolute_saving'),
            'gross_commission': gross_commission,
            'user_commission': user_commission,
        }
        kwargs.update(SeatPricingMixin.kwargs_from_api_data(data))

        return cls(**kwargs)
Пример #7
0
    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)
Пример #8
0
 def test_non_offer_combined_price_decimal(self):
     inst = SeatPricingMixin(non_offer_seatprice=Decimal('123.45'),
                             non_offer_surcharge=Decimal('6.78'))
     assert inst.non_offer_combined_price() == Decimal('130.23')
Пример #9
0
 def test_non_offer_combined_price_inexact_floats(self):
     inst = SeatPricingMixin(non_offer_seatprice=1.1,
                             non_offer_surcharge=2.2)
     assert inst.non_offer_combined_price() == 3.3
Пример #10
0
 def test_combined_price_inexact_floats(self):
     inst = SeatPricingMixin(seatprice=1.1, surcharge=2.2)
     assert inst.combined_price() == 3.3
Пример #11
0
    def test_non_offer_combined_price(self):
        inst = SeatPricingMixin(non_offer_seatprice=123.45,
                                non_offer_surcharge=6.78)

        assert inst.non_offer_combined_price() == 130.23
Пример #12
0
 def test_combined_price_inexact_floats(self):
     inst = SeatPricingMixin(seatprice=1.1, surcharge=2.2)
     assert inst.combined_price() == 3.3
Пример #13
0
 def test_combined_price(self):
     inst = SeatPricingMixin(seatprice=123.45, surcharge=6.78)
     assert inst.combined_price() == 130.23
Пример #14
0
 def test_combined_price(self):
     inst = SeatPricingMixin(seatprice=123.45, surcharge=6.78)
     assert inst.combined_price() == 130.23
Пример #15
0
    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)
Пример #16
0
 def test_non_offer_combined_price_decimal(self):
     inst = SeatPricingMixin(
         non_offer_seatprice=Decimal('123.45'),
         non_offer_surcharge=Decimal('6.78')
     )
     assert inst.non_offer_combined_price() == Decimal('130.23')
Пример #17
0
 def test_non_offer_combined_price_inexact_floats(self):
     inst = SeatPricingMixin(non_offer_seatprice=1.1, non_offer_surcharge=2.2)
     assert inst.non_offer_combined_price() == 3.3
Пример #18
0
    def test_non_offer_combined_price(self):
        inst = SeatPricingMixin(non_offer_seatprice=123.45,
                                non_offer_surcharge=6.78)

        assert inst.non_offer_combined_price() == 130.23