예제 #1
0
    def from_api_data(cls, data):
        """Creates a new **Review** object from ticketswitch API data.

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

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

        """

        review_date = isostr_to_datetime(
            data.get('review_iso8601_date_and_time'))

        kwargs = {
            'body': data.get('review_body', None),
            'date_time': review_date,
            'star_rating': data.get('star_rating', None),
            'lang': data.get('review_lang', None),
            'title': data.get('review_title', None),
            'is_user': data.get('is_user_review', False),
            'author': data.get('review_author', None),
            'url': data.get('review_original_url', None),
        }

        return cls(**kwargs)
예제 #2
0
    def from_api_data(cls, data):
        """Creates a new **Review** object from ticketswitch API data.

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

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

        """

        review_date = isostr_to_datetime(
            data.get('review_iso8601_date_and_time')
        )

        kwargs = {
            'body': data.get('review_body', None),
            'date_time': review_date,
            'star_rating': data.get('star_rating', None),
            'lang': data.get('review_lang', None),
            'title': data.get('review_title', None),
            'is_user': data.get('is_user_review', False),
            'author': data.get('review_author', None),
            'url': data.get('review_original_url', None),
        }

        return cls(**kwargs)
예제 #3
0
    def test_with_core_zulu(self):
        date_str = '2016-09-16T19:30:00Z'
        dt = utils.isostr_to_datetime(date_str)

        assert dt == datetime.datetime(2016,
                                       9,
                                       16,
                                       19,
                                       30,
                                       0,
                                       tzinfo=self.ZULU)
예제 #4
0
    def from_api_data(cls, data):
        """Creates a new Status object from API data from ticketswitch.

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

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

        """
        accepted_cards = [
            CardType(code=key, description=value)
            for key, value in data.get('accepted_payment_cards', {}).items()
        ]

        customer = None
        customer_api_data = data.get('customer')
        if customer_api_data:
            customer = Customer.from_api_data(customer_api_data)

        kwargs = {
            'status': data.get('transaction_status'),
            'trolley': Trolley.from_api_data(data),
            'remote_site': data.get('remote_site'),
            'can_edit_address': data.get('can_edit_address'),
            'needs_agent_reference': data.get('needs_agent_reference'),
            'needs_email_address': data.get('needs_email_address'),
            'needs_payment_card': data.get('needs_payment_card'),
            'minutes_left': data.get('minutes_left_on_reserve'),
            'supports_billing_address': data.get('supports_billing_address'),
            'accepted_cards': accepted_cards,
            'customer': customer,
        }

        reserved_raw = data.get('reserve_iso8601_date_and_time')
        if reserved_raw:
            kwargs.update(reserved_at=isostr_to_datetime(reserved_raw))

        purchased_raw = data.get('purchase_iso8601_date_and_time')
        if purchased_raw:
            kwargs.update(purchased_at=isostr_to_datetime(purchased_raw))

        external_sale_page_raw = data.get('external_sale_page_raw')
        if external_sale_page_raw:
            raise NotImplementedError("don't know what this looks like yet")

        reserve_user_data = data.get('reserve_user')
        if reserve_user_data:
            reserve_user = User.from_api_data(reserve_user_data)
            kwargs.update(reserve_user=reserve_user)

        languages_raw = data.get('language_list')
        if languages_raw:
            kwargs.update(languages=languages_raw)

        allowed_countries = data.get('allowed_countries')
        if allowed_countries is not None:
            countries = [
                Country(key, description=description)
                for key, description in allowed_countries.items()
            ]
            countries.sort(key=lambda x: x.code)
            kwargs.update(allowed_countries=countries)

        address = data.get('prefilled_address')
        if address:
            kwargs.update(prefilled_address=Address.from_api_data(address))

        pending_callout = data.get('pending_callout')
        if pending_callout:
            kwargs.update(pending_callout=Callout.from_api_data(pending_callout))

        return cls(**kwargs)
예제 #5
0
 def test_with_empty(self):
     date_str = ''
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #6
0
 def test_with_none(self):
     date_str = None
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #7
0
 def test_with_not_datetime(self):
     date_str = 'When the moon is in the forth corner of the jelly bean'
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #8
0
    def test_with_python_iso(self):
        date_str = '2016-09-16T19:30:00+0100'
        dt = utils.isostr_to_datetime(date_str)

        assert dt == datetime.datetime(2016, 9, 16, 19, 30, 0, tzinfo=self.BST)
예제 #9
0
 def test_with_empty(self):
     date_str = ''
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #10
0
 def test_with_none(self):
     date_str = None
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #11
0
 def test_with_not_datetime(self):
     date_str = 'When the moon is in the forth corner of the jelly bean'
     with pytest.raises(ValueError):
         utils.isostr_to_datetime(date_str)
예제 #12
0
    def test_with_python_iso(self):
        date_str = '2016-09-16T19:30:00+0100'
        dt = utils.isostr_to_datetime(date_str)

        assert dt == datetime.datetime(2016, 9, 16, 19, 30, 0, tzinfo=self.BST)
예제 #13
0
    def test_with_core_zulu(self):
        date_str = '2016-09-16T19:30:00Z'
        dt = utils.isostr_to_datetime(date_str)

        assert dt == datetime.datetime(2016, 9, 16, 19, 30, 0, tzinfo=self.ZULU)
예제 #14
0
    def from_api_data(cls, data):
        """Creates a new Status object from API data from ticketswitch.

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

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

        """
        accepted_cards = [
            CardType(code=key, description=value)
            for key, value in data.get('accepted_payment_cards', {}).items()
        ]

        customer = None
        customer_api_data = data.get('customer')
        if customer_api_data:
            customer = Customer.from_api_data(customer_api_data)

        kwargs = {
            'status': data.get('transaction_status'),
            'trolley': Trolley.from_api_data(data),
            'remote_site': data.get('remote_site'),
            'can_edit_address': data.get('can_edit_address'),
            'needs_agent_reference': data.get('needs_agent_reference'),
            'needs_email_address': data.get('needs_email_address'),
            'needs_payment_card': data.get('needs_payment_card'),
            'minutes_left': data.get('minutes_left_on_reserve'),
            'supports_billing_address': data.get('supports_billing_address'),
            'accepted_cards': accepted_cards,
            'customer': customer,
        }

        reserved_raw = data.get('reserve_iso8601_date_and_time')
        if reserved_raw:
            kwargs.update(reserved_at=isostr_to_datetime(reserved_raw))

        purchased_raw = data.get('purchase_iso8601_date_and_time')
        if purchased_raw:
            kwargs.update(purchased_at=isostr_to_datetime(purchased_raw))

        external_sale_page_raw = data.get('external_sale_page_raw')
        if external_sale_page_raw:
            raise NotImplementedError("don't know what this looks like yet")

        reserve_user_data = data.get('reserve_user')
        if reserve_user_data:
            reserve_user = User.from_api_data(reserve_user_data)
            kwargs.update(reserve_user=reserve_user)

        languages_raw = data.get('language_list')
        if languages_raw:
            kwargs.update(languages=languages_raw)

        allowed_countries = data.get('allowed_countries')
        if allowed_countries is not None:
            countries = [
                Country(key, description=description)
                for key, description in allowed_countries.items()
            ]
            countries.sort(key=lambda x: x.code)
            kwargs.update(allowed_countries=countries)

        address = data.get('prefilled_address')
        if address:
            kwargs.update(prefilled_address=Address.from_api_data(address))

        pending_callout = data.get('pending_callout')
        if pending_callout:
            kwargs.update(
                pending_callout=Callout.from_api_data(pending_callout))

        return cls(**kwargs)