def test_get_events_with_no_bundles(self): trolley = Trolley(bundles=None) events = trolley.get_events() assert events == []
def test_get_events(self): event_one = Event(id_='abc123') event_two = Event(id_='def456') event_three = Event(id_='ghi789') event_four = Event(id_='jlk012') bundle_one = Bundle( 'tests', orders=[ Order(item=1, event=event_one), Order(item=2, event=event_two), ] ) bundle_two = Bundle( 'tests_two', orders=[ Order(item=3, event=event_three), Order(item=4, event=event_four), ] ) trolley = Trolley( bundles=[bundle_one, bundle_two] ) events = trolley.get_events() assert events == [event_one, event_two, event_three, event_four]
def test_get_bundle_when_none(self): # state trolley = Trolley(bundles=[]) # action bundle = trolley.get_bundle('tests_two') # results assert bundle is None
def test_get_bundle_when_no_match(self): # state bundle_one = Bundle('tests') bundle_two = Bundle('tests_two') trolley = Trolley(bundles=[bundle_one, bundle_two]) # action bundle = trolley.get_bundle('tests_three') # results assert bundle is None
def test_get_orders(self): #state order_one = Order(1) order_two = Order(2) order_three = Order(3) order_four = Order(4) bundle_one = Bundle('tests', orders=[order_one, order_three]) bundle_two = Bundle('tests_two', orders=[order_two, order_four]) trolley = Trolley(bundles=[bundle_one, bundle_two]) # results orders = trolley.get_orders() assert orders == [order_one, order_three, order_two, order_four]
def test_from_api_data_with_trolley_data(self): data = { 'discarded_orders': [ {'item_number': 3}, {'item_number': 6}, ], 'trolley_contents': { 'bundle': [ {'bundle_source_code': 'foo'}, {'bundle_source_code': 'bar'}, ], "purchase_result": {'success': True}, }, 'trolley_token': 'ABC123', 'trolley_order_count': 8, } trolley = Trolley.from_api_data(data) assert trolley.token == 'ABC123' assert len(trolley.bundles) == 2 assert trolley.bundles[0].source_code == 'foo' assert trolley.bundles[1].source_code == 'bar' assert len(trolley.discarded_orders) == 2 assert trolley.discarded_orders[0].item == 3 assert trolley.discarded_orders[1].item == 6 assert trolley.order_count == 8 assert trolley.purchase_result.success is True
def test_from_api_data_with_reservation_data(self): data = { 'discarded_orders': [ {'item_number': 3}, {'item_number': 6}, ], 'reserved_trolley': { 'bundle': [ {'bundle_source_code': 'foo'}, {'bundle_source_code': 'bar'}, ], 'transaction_id': 'T1000-0000', 'transaction_uuid': 'DEF456', }, } trolley = Trolley.from_api_data(data) assert trolley.transaction_uuid == 'DEF456' assert trolley.transaction_id == 'T1000-0000' assert len(trolley.bundles) == 2 assert trolley.bundles[0].source_code == 'foo' assert trolley.bundles[1].source_code == 'bar' assert len(trolley.discarded_orders) == 2 assert trolley.discarded_orders[0].item == 3 assert trolley.discarded_orders[1].item == 6
def test_get_event_ids(self): event_one = Event(id_='abc123') event_two = Event(id_='def456') event_three = Event(id_='ghi789') event_four = Event(id_='abc123') bundle_one = Bundle('tests', orders=[ Order(item=1, event=event_one), Order(item=2, event=event_two), ]) bundle_two = Bundle('tests_two', orders=[ Order(item=3, event=event_three), Order(item=4, event=event_four), ]) trolley = Trolley(bundles=[bundle_one, bundle_two]) events = trolley.get_event_ids() assert events == {'abc123', 'def456', 'ghi789'}
def from_api_data(cls, data): kwargs = { "cancelled_item_numbers": data.get("cancelled_item_numbers", []), "trolley": Trolley.from_api_data(data), } raw_must_also_cancel = data.get("must_also_cancel") if raw_must_also_cancel: must_also_cancel = [ Order.from_api_data(order) for order in raw_must_also_cancel ] kwargs.update(must_also_cancel=must_also_cancel) return cls(**kwargs)
def test_from_api_data_with_empty_trolley(self): data = { "discarded_orders": [], "input_contained_unavailable_order": True, "trolley_token": "abc123", "trolley_token_contents": { "trolley_bundle_count": 0, "trolley_order_count": 0 } } trolley = Trolley.from_api_data(data) assert trolley.token == 'abc123' assert trolley.input_contained_unavailable_order is True
def test_from_api_data_with_trolley_data(self): data = { 'discarded_orders': [ { 'item_number': 3 }, { 'item_number': 6 }, ], 'trolley_contents': { 'bundle': [ { 'bundle_source_code': 'foo' }, { 'bundle_source_code': 'bar' }, ], "purchase_result": { 'success': True }, }, 'trolley_token': 'ABC123', 'trolley_order_count': 8, } trolley = Trolley.from_api_data(data) assert trolley.token == 'ABC123' assert len(trolley.bundles) == 2 assert trolley.bundles[0].source_code == 'foo' assert trolley.bundles[1].source_code == 'bar' assert len(trolley.discarded_orders) == 2 assert trolley.discarded_orders[0].item == 3 assert trolley.discarded_orders[1].item == 6 assert trolley.order_count == 8 assert trolley.purchase_result.success is True
def test_from_api_data_with_reservation_data(self): data = { 'discarded_orders': [ { 'item_number': 3 }, { 'item_number': 6 }, ], 'reserved_trolley': { 'bundle': [ { 'bundle_source_code': 'foo' }, { 'bundle_source_code': 'bar' }, ], 'transaction_id': 'T1000-0000', 'transaction_uuid': 'DEF456', }, } trolley = Trolley.from_api_data(data) assert trolley.transaction_uuid == 'DEF456' assert trolley.transaction_id == 'T1000-0000' assert len(trolley.bundles) == 2 assert trolley.bundles[0].source_code == 'foo' assert trolley.bundles[1].source_code == 'bar' assert len(trolley.discarded_orders) == 2 assert trolley.discarded_orders[0].item == 3 assert trolley.discarded_orders[1].item == 6
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)
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)