コード例 #1
0
    def from_api_data(cls, data):

        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:
            cost_range = CostRange.from_api_data(api_cost_range)

        if api_no_singles_cost_range:
            no_singles_cost_range = CostRange.from_api_data(
                api_no_singles_cost_range)

        kwargs = {
            'cost_range': cost_range,
            'no_singles_cost_range': no_singles_cost_range,
            'month': MONTH_NUMBERS.get(data.get('month')),
            'year': data.get('year'),
            'description': data.get('month_desc'),
            'dates_bitmask': data.get('month_dates_bitmask'),
            'weekday_bitmask': data.get('month_weekdays_bitmask'),
        }

        return cls(**kwargs)
コード例 #2
0
    def test_from_api_data(self):
        data = {
            "best_value_offer": {
                "absolute_saving": 10,
            },
            "max_saving_offer": {
                "absolute_saving": 8,
            },
            "max_seatprice": 149.5,
            "max_surcharge": 29.65,
            "min_cost_offer": {
                "absolute_saving": 7,
            },
            "min_seatprice": 37.5,
            "min_surcharge": 7.25,
            "range_currency_code": "usd",
            "top_price_offer": {
                "absolute_saving": 9,
            },
            "valid_quantities": [1, 2, 3, 4]
        }
        cost_range = CostRange.from_api_data(data)

        assert cost_range.max_surcharge == 29.65
        assert cost_range.max_seatprice == 149.5
        assert cost_range.min_surcharge == 7.25
        assert cost_range.min_seatprice == 37.5

        assert cost_range.top_price_offer.absolute_saving == 9.0
        assert cost_range.min_cost_offer.absolute_saving == 7.0
        assert cost_range.max_saving_offer.absolute_saving == 8.0
        assert cost_range.best_value_offer.absolute_saving == 10.0

        assert cost_range.currency == 'usd'
        assert cost_range.valid_quantities == [1, 2, 3, 4]
コード例 #3
0
    def test_from_api_data(self):
        data = {
            "best_value_offer": {
                "absolute_saving": 10,
            },
            "max_saving_offer": {
                "absolute_saving": 8,
            },
            "max_seatprice": 149.5,
            "max_surcharge": 29.65,
            "min_cost_offer": {
                "absolute_saving": 7,
            },
            "min_seatprice": 37.5,
            "min_surcharge": 7.25,
            "range_currency_code": "usd",
            "top_price_offer": {
                "absolute_saving": 9,
            },
            "valid_quantities": [1, 2, 3, 4]
        }
        cost_range = CostRange.from_api_data(data)

        assert cost_range.max_surcharge == 29.65
        assert cost_range.max_seatprice == 149.5
        assert cost_range.min_surcharge == 7.25
        assert cost_range.min_seatprice == 37.5

        assert cost_range.top_price_offer.absolute_saving == 9.0
        assert cost_range.min_cost_offer.absolute_saving == 7.0
        assert cost_range.max_saving_offer.absolute_saving == 8.0
        assert cost_range.best_value_offer.absolute_saving == 10.0

        assert cost_range.currency == 'usd'
        assert cost_range.valid_quantities == [1, 2, 3, 4]
コード例 #4
0
 def test_has_offer_with_best_value_offer(self):
     offer = Offer()
     cost_range = CostRange(best_value_offer=offer)
     assert cost_range.has_offer() is True
コード例 #5
0
 def test_has_offer_with_no_offers(self):
     cost_range = CostRange()
     assert cost_range.has_offer() is False
コード例 #6
0
ファイル: price_band.py プロジェクト: shubh234/pyticketswitch
    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)
コード例 #7
0
ファイル: event.py プロジェクト: shubh234/pyticketswitch
    def class_dict_from_api_data(cls, data):
        """Creates a dict of Event data from a raw ticketswitch API call

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

        Returns:
            dict: a new dict populated with the data from the api for creating
            an :class:`Event <pyticketswitch.event.Event>` object

        """

        id_ = data.get('event_id')

        if not id_:
            raise IntegrityError("event_id not found in event data", data=data)

        geo_data = data.get('geo_data', {})

        # the raw field 'has_no_perfs' is a negative flag, so I'm inverting it
        has_performances = not data.get('has_no_perfs', False)

        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)

        api_cost_range_details = data.get('cost_range_details', {})
        ticket_type_list = api_cost_range_details.get('ticket_type', [])
        cost_range_details = [
            TicketType.from_api_data(ticket_type)
            for ticket_type in ticket_type_list
        ]

        api_content = data.get('structured_info', {})
        content = {
            key: Content.from_api_data(value)
            for key, value in api_content.items()
        }

        fields = {
            field.get('custom_field_name'): Field.from_api_data(field)
            for field in data.get('custom_fields', {})
        }

        media = {}
        api_media = data.get('media', {})
        for asset in api_media.get('media_asset', []):
            new_media = Media.from_api_data(asset)
            media[new_media.name] = new_media

        api_video = data.get('video_iframe')
        if api_video:
            kwargs = {
                'secure_complete_url':
                api_video.get('video_iframe_url_when_secure'),
                'insecure_complete_url':
                api_video.get('video_iframe_url_when_insecure'),
                'caption':
                api_video.get('video_iframe_caption'),
                'caption_html':
                api_video.get('video_iframe_caption_html'),
                'width':
                api_video.get('video_iframe_width'),
                'height':
                api_video.get('video_iframe_height'),
                'name':
                'video',
            }
            new_video = Media.from_api_data(kwargs)
            media['video'] = new_video

        api_reviews = data.get('reviews', {})
        reviews = [
            Review.from_api_data(api_review)
            for api_review in api_reviews.get('review', [])
        ]

        availability_details = AvailabilityDetails.from_api_data(
            data.get('avail_details', {}))
        api_component_events = data.get('meta_event_component_events', {})
        component_events = [
            Event.from_api_data(meta_event)
            for meta_event in api_component_events.get('event', [])
        ]

        lingo_code = None
        raw_lingo_data = data.get('lingo_data')
        if raw_lingo_data:
            lingo_code = raw_lingo_data.get('lingo_code')

        kwargs = {
            'id_': id_,
            'description': data.get('event_desc', None),
            'status': data.get('event_status'),
            'event_type': data.get('event_type'),
            'source_code': data.get('source_code'),
            'source': data.get('source_desc'),
            'venue': data.get('venue_desc'),
            'classes': data.get('classes'),
            #TODO: don't actually know what filters look like yet...
            'filters': data.get('custom_filter', []),
            'fields': fields,
            'postcode': data.get('postcode'),
            'city': data.get('city_desc'),
            'city_code': data.get('city_code'),
            'country': data.get('country_desc'),
            'country_code': data.get('country_code'),
            'latitude': geo_data.get('latitude'),
            'longitude': geo_data.get('longitude'),
            'max_running_time': data.get('max_running_time'),
            'min_running_time': data.get('min_running_time'),
            'has_performances': has_performances,
            'show_performance_time': data.get('show_perf_time', False),
            'is_seated': data.get('is_seated', False),
            'needs_departure_date': data.get('need_departure_date', False),
            'needs_duration': data.get('need_duration', False),
            'needs_performance': data.get('need_performance', False),
            'upsell_list': data.get('event_upsell_list',
                                    {}).get('event_id', []),
            'cost_range': cost_range,
            'no_singles_cost_range': no_singles_cost_range,
            'cost_range_details': cost_range_details,

            # extra info
            'event_info_html': data.get('event_info_html'),
            'event_info': data.get('event_info'),
            'venue_addr_html': data.get('venue_addr_html'),
            'venue_addr': data.get('venue_addr'),
            'venue_info': data.get('venue_info'),
            'venue_info_html': data.get('venue_info_html'),
            'content': content,
            'media': media,
            'reviews': reviews,
            'critic_review_percent': data.get('critic_review_percent'),
            'availability_details': availability_details,
            'component_events': component_events,
            'valid_quantities': data.get('valid_quantities'),
            'raw': data,
            'is_add_on': data.get('is_add_on', False),
            'is_auto_quantity_add_on': data.get('is_auto_quantity_add_on',
                                                False),
            'venue_code': data.get('venue_code'),
            'area_code': data.get('area_code'),
            'lingo_code': lingo_code,
        }

        return kwargs
コード例 #8
0
 def test_has_offer_with_no_offers(self):
     cost_range = CostRange()
     assert cost_range.has_offer() is False
コード例 #9
0
 def test_get_min_combined_price(self):
     cost_range = CostRange(min_seatprice=10, min_surcharge=5)
     assert cost_range.get_min_combined_price() == 15.0
コード例 #10
0
 def test_has_offer_with_min_cost_offer(self):
     offer = Offer()
     cost_range = CostRange(min_cost_offer=offer)
     assert cost_range.has_offer() is True
コード例 #11
0
 def test_get_min_combined_price(self):
     cost_range = CostRange(min_seatprice=10, min_surcharge=5)
     assert cost_range.get_min_combined_price() == 15.0
コード例 #12
0
 def test_has_offer_with_top_price_offer(self):
     offer = Offer()
     cost_range = CostRange(top_price_offer=offer)
     assert cost_range.has_offer() is True
コード例 #13
0
 def test_has_offer_with_min_cost_offer(self):
     offer = Offer()
     cost_range = CostRange(min_cost_offer=offer)
     assert cost_range.has_offer() is True
コード例 #14
0
 def test_has_offer_with_max_saving_offer(self):
     offer = Offer()
     cost_range = CostRange(max_saving_offer=offer)
     assert cost_range.has_offer() is True
コード例 #15
0
 def test_has_offer_with_best_value_offer(self):
     offer = Offer()
     cost_range = CostRange(best_value_offer=offer)
     assert cost_range.has_offer() is True
コード例 #16
0
 def test_has_offer_with_max_saving_offer(self):
     offer = Offer()
     cost_range = CostRange(max_saving_offer=offer)
     assert cost_range.has_offer() is True
コード例 #17
0
 def test_get_max_combined_price(self):
     cost_range = CostRange(max_seatprice=22, max_surcharge=8)
     assert cost_range.get_max_combined_price() == 30.0
コード例 #18
0
 def test_has_offer_with_top_price_offer(self):
     offer = Offer()
     cost_range = CostRange(top_price_offer=offer)
     assert cost_range.has_offer() is True
コード例 #19
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)
コード例 #20
0
 def test_get_max_combined_price(self):
     cost_range = CostRange(max_seatprice=22, max_surcharge=8)
     assert cost_range.get_max_combined_price() == 30.0
コード例 #21
0
    def class_dict_from_api_data(cls, data):
        """Creates a dict of Event data from a raw ticketswitch API call

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

        Returns:
            dict: a new dict populated with the data from the api for creating
            an :class:`Event <pyticketswitch.event.Event>` object

        """

        id_ = data.get('event_id')

        if not id_:
            raise IntegrityError("event_id not found in event data", data=data)

        geo_data = data.get('geo_data', {})

        # the raw field 'has_no_perfs' is a negative flag, so I'm inverting it
        has_performances = not data.get('has_no_perfs', False)

        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)

        api_cost_range_details = data.get('cost_range_details', {})
        ticket_type_list = api_cost_range_details.get('ticket_type', [])
        cost_range_details = [
            TicketType.from_api_data(ticket_type)
            for ticket_type in ticket_type_list
        ]

        api_content = data.get('structured_info', {})
        content = {
            key: Content.from_api_data(value)
            for key, value in api_content.items()
        }

        fields = {
            field.get('custom_field_name'): Field.from_api_data(field)
            for field in data.get('custom_fields', {})
        }

        media = {}
        api_media = data.get('media', {})
        for asset in api_media.get('media_asset', []):
            new_media = Media.from_api_data(asset)
            media[new_media.name] = new_media

        api_video = data.get('video_iframe')
        if api_video:
            kwargs = {
                'secure_complete_url': api_video.get('video_iframe_url_when_secure'),
                'insecure_complete_url': api_video.get('video_iframe_url_when_insecure'),
                'caption': api_video.get('video_iframe_caption'),
                'caption_html': api_video.get('video_iframe_caption_html'),
                'width': api_video.get('video_iframe_width'),
                'height': api_video.get('video_iframe_height'),
                'name': 'video',
            }
            new_video = Media.from_api_data(kwargs)
            media['video'] = new_video

        api_reviews = data.get('reviews', {})
        reviews = [
            Review.from_api_data(api_review)
            for api_review in api_reviews.get('review', [])
        ]

        availability_details = AvailabilityDetails.from_api_data(
            data.get('avail_details', {}))
        api_component_events = data.get('meta_event_component_events', {})
        component_events = [
            Event.from_api_data(meta_event)
            for meta_event in api_component_events.get('event', [])
        ]

        lingo_code = None
        raw_lingo_data = data.get('lingo_data')
        if raw_lingo_data:
            lingo_code = raw_lingo_data.get('lingo_code')

        kwargs = {
            'id_': id_,
            'description': data.get('event_desc', None),
            'status': data.get('event_status'),
            'event_type': data.get('event_type'),
            'source_code': data.get('source_code'),
            'source': data.get('source_desc'),
            'venue': data.get('venue_desc'),

            'classes': data.get('classes'),
            #TODO: don't actually know what filters look like yet...
            'filters': data.get('custom_filter', []),
            'fields': fields,

            'postcode': data.get('postcode'),
            'city': data.get('city_desc'),
            'city_code': data.get('city_code'),
            'country': data.get('country_desc'),
            'country_code': data.get('country_code'),

            'latitude': geo_data.get('latitude'),
            'longitude': geo_data.get('longitude'),

            'max_running_time': data.get('max_running_time'),
            'min_running_time': data.get('min_running_time'),

            'has_performances': has_performances,
            'show_performance_time': data.get('show_perf_time', False),
            'is_seated': data.get('is_seated', False),
            'needs_departure_date': data.get('need_departure_date', False),
            'needs_duration': data.get('need_duration', False),
            'needs_performance': data.get('need_performance', False),

            'upsell_list': data.get('event_upsell_list', {}).get('event_id', []),

            'cost_range': cost_range,
            'no_singles_cost_range': no_singles_cost_range,
            'cost_range_details': cost_range_details,

            # extra info
            'event_info_html': data.get('event_info_html'),
            'event_info': data.get('event_info'),
            'venue_addr_html': data.get('venue_addr_html'),
            'venue_addr': data.get('venue_addr'),
            'venue_info': data.get('venue_info'),
            'venue_info_html': data.get('venue_info_html'),
            'content': content,

            'media': media,
            'reviews': reviews,
            'critic_review_percent': data.get('critic_review_percent'),

            'availability_details': availability_details,
            'component_events': component_events,
            'valid_quantities': data.get('valid_quantities'),
            'raw': data,

            'is_add_on': data.get('is_add_on', False),
            'is_auto_quantity_add_on': data.get('is_auto_quantity_add_on', False),

            'venue_code': data.get('venue_code'),
            'area_code': data.get('area_code'),
            'lingo_code': lingo_code,
        }

        return kwargs