Exemplo n.º 1
0
    def test_with_keys(self):

        data = {
            'min_price': 12.40,
            'max_price': 22.00,
        }

        min_price = utils.get_price(data, 'min_price')
        assert min_price == 12.40

        max_price = utils.get_price(data, 'max_price')
        assert max_price == 22.00
Exemplo n.º 2
0
    def test_with_keys(self):

        data = {
            'min_price': 12.40,
            'max_price': 22.00,
        }

        min_price = utils.get_price(data, 'min_price')
        assert min_price == 12.40

        max_price = utils.get_price(data, 'max_price')
        assert max_price == 22.00
Exemplo n.º 3
0
    def from_api_data(cls, data):
        """Creates a new CostRange object from API data from ticketswitch.

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

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

        """

        min_seatprice = utils.get_price(data, 'min_seatprice')
        min_surcharge = utils.get_price(data, 'min_surcharge')
        max_seatprice = utils.get_price(data, 'max_seatprice')
        max_surcharge = utils.get_price(data, 'max_surcharge')

        kwargs = {
            'valid_quantities': data.get('valid_quantities'),
            'min_surcharge': min_surcharge,
            'min_seatprice': min_seatprice,
            'max_surcharge': max_surcharge,
            'max_seatprice': max_seatprice,
            'allows_singles': data.get('singles', True),
            'currency': data.get('range_currency_code'),
        }

        best_value_offer = data.get('best_value_offer')
        if best_value_offer:
            best_value_offer = Offer.from_api_data(best_value_offer)
            kwargs.update(best_value_offer=best_value_offer)

        max_saving_offer = data.get('max_saving_offer')
        if max_saving_offer:
            max_saving_offer = Offer.from_api_data(max_saving_offer)
            kwargs.update(max_saving_offer=max_saving_offer)

        min_cost_offer = data.get('min_cost_offer')
        if min_cost_offer:
            min_cost_offer = Offer.from_api_data(min_cost_offer)
            kwargs.update(min_cost_offer=min_cost_offer)

        top_price_offer = data.get('top_price_offer')
        if top_price_offer:
            top_price_offer = Offer.from_api_data(top_price_offer)
            kwargs.update(top_price_offer=top_price_offer)

        return cls(**kwargs)
Exemplo n.º 4
0
    def from_api_data(cls, data):
        """Creates a new CostRange object from API data from ticketswitch.

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

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

        """

        min_seatprice = utils.get_price(data, 'min_seatprice')
        min_surcharge = utils.get_price(data, 'min_surcharge')
        max_seatprice = utils.get_price(data, 'max_seatprice')
        max_surcharge = utils.get_price(data, 'max_surcharge')

        kwargs = {
            'valid_quantities': data.get('valid_quantities'),
            'min_surcharge': min_surcharge,
            'min_seatprice': min_seatprice,
            'max_surcharge': max_surcharge,
            'max_seatprice': max_seatprice,
            'allows_singles': data.get('singles', True),
            'currency': data.get('range_currency_code'),
        }

        best_value_offer = data.get('best_value_offer')
        if best_value_offer:
            best_value_offer = Offer.from_api_data(best_value_offer)
            kwargs.update(best_value_offer=best_value_offer)

        max_saving_offer = data.get('max_saving_offer')
        if max_saving_offer:
            max_saving_offer = Offer.from_api_data(max_saving_offer)
            kwargs.update(max_saving_offer=max_saving_offer)

        min_cost_offer = data.get('min_cost_offer')
        if min_cost_offer:
            min_cost_offer = Offer.from_api_data(min_cost_offer)
            kwargs.update(min_cost_offer=min_cost_offer)

        top_price_offer = data.get('top_price_offer')
        if top_price_offer:
            top_price_offer = Offer.from_api_data(top_price_offer)
            kwargs.update(top_price_offer=top_price_offer)

        return cls(**kwargs)
Exemplo n.º 5
0
    def test_with_str_zero(self):

        data = {'price': '0'}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 0
Exemplo n.º 6
0
    def test_with_str_int(self):

        data = {'price': '12'}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 12.0
Exemplo n.º 7
0
    def test_with_float(self):

        data = {'price': 12.40}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 12.40
Exemplo n.º 8
0
    def test_with_str_zero(self):

        data = {'price': '0'}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 0
Exemplo n.º 9
0
    def test_with_str_int(self):

        data = {'price': '12'}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 12.0
Exemplo n.º 10
0
    def test_with_float(self):

        data = {'price': 12.40}

        price = utils.get_price(data, 'price')
        assert isinstance(price, float)
        assert price == 12.40
Exemplo n.º 11
0
    def test_with_missing_key(self):

        data = {'price': 12.40}

        max_price = utils.get_price(data, 'max_price')
        assert max_price is None
Exemplo n.º 12
0
    def test_with_None(self):

        data = {'price': None}

        price = utils.get_price(data, 'price')
        assert price is None
Exemplo n.º 13
0
    def test_with_missing_key(self):

        data = {'price': 12.40}

        max_price = utils.get_price(data, 'max_price')
        assert max_price is None
Exemplo n.º 14
0
    def test_with_None(self):

        data = {'price': None}

        price = utils.get_price(data, 'price')
        assert price is None