def test_get_events_with_no_orders(self): bundle = Bundle('tests', orders=None) events = bundle.get_events() assert events == []
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_event_ids(self): event_one = Event(id_='abc123') event_two = Event(id_='def456') bundle = Bundle('tests', orders=[ Order(item=1, event=event_one), Order(item=2, event=event_two), ]) events = bundle.get_event_ids() assert events == {'abc123', 'def456'}
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_get_event_ids(self): event_one = Event(id_='abc123') event_two = Event(id_='def456') bundle = Bundle( 'tests', orders=[ Order(item=1, event=event_one), Order(item=2, event=event_two), ] ) events = bundle.get_event_ids() assert events == {'abc123', 'def456'}
def from_api_data(cls, data): """Creates a new Trolley object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a trolley. Returns: :class:`Trolley <pyticketswitch.trolley.Trolley>`: a new :class:`Trolley <pyticketswitch.trolley.Trolley>` object populated with the data from the api. """ raw_contents = data.get('trolley_contents', {}) if not raw_contents: raw_contents = data.get('reserved_trolley', {}) if not raw_contents: raw_contents = data.get('trolley_token_contents', {}) raw_bundles = raw_contents.get('bundle', []) bundles = [Bundle.from_api_data(bundle) for bundle in raw_bundles] raw_discarded_orders = data.get('discarded_orders', []) discarded_orders = [ Order.from_api_data(order) for order in raw_discarded_orders ] kwargs = { 'token': data.get('trolley_token'), 'bundles': bundles, 'discarded_orders': discarded_orders, 'transaction_uuid': raw_contents.get('transaction_uuid'), 'transaction_id': raw_contents.get('transaction_id'), 'order_count': data.get('trolley_order_count'), 'input_contained_unavailable_order': data.get('input_contained_unavailable_order', False), } minutes = data.get('minutes_left_on_reserve') if minutes is not None: kwargs.update(minutes_left=float(minutes)) purchase_result = raw_contents.get('purchase_result') if purchase_result: kwargs.update( purchase_result=PurchaseResult.from_api_data(purchase_result)) return cls(**kwargs)
def test_is_purchased(self): pr = PurchaseResult(success=True) bundle_orders = [Order(item=1, event=Event(id_='TEST'))] bundle = Bundle( 'tests', orders=bundle_orders, purchase_result=pr, ) no_pr_bundle = Bundle( 'tests', orders=bundle_orders, ) assert bundle.is_purchased() assert not no_pr_bundle.is_purchased()
def from_api_data(cls, data): """Creates a new Trolley object from API data from ticketswitch. Args: data (dict): the part of the response from a ticketswitch API call that concerns a trolley. Returns: :class:`Trolley <pyticketswitch.trolley.Trolley>`: a new :class:`Trolley <pyticketswitch.trolley.Trolley>` object populated with the data from the api. """ raw_contents = data.get('trolley_contents', {}) if not raw_contents: raw_contents = data.get('reserved_trolley', {}) if not raw_contents: raw_contents = data.get('trolley_token_contents', {}) raw_bundles = raw_contents.get('bundle', []) bundles = [ Bundle.from_api_data(bundle) for bundle in raw_bundles ] raw_discarded_orders = data.get('discarded_orders', []) discarded_orders = [ Order.from_api_data(order) for order in raw_discarded_orders ] kwargs = { 'token': data.get('trolley_token'), 'bundles': bundles, 'discarded_orders': discarded_orders, 'transaction_uuid': raw_contents.get('transaction_uuid'), 'transaction_id': raw_contents.get('transaction_id'), 'order_count': data.get('trolley_order_count'), 'input_contained_unavailable_order': data.get( 'input_contained_unavailable_order', False), } minutes = data.get('minutes_left_on_reserve') if minutes is not None: kwargs.update(minutes_left=float(minutes)) purchase_result = raw_contents.get('purchase_result') if purchase_result: kwargs.update( purchase_result=PurchaseResult.from_api_data(purchase_result)) return cls(**kwargs)
def test_from_api_data(self): data = { 'bundle_order_count': 1, 'bundle_source_code': 'ext_test0', 'bundle_source_desc': 'External Test Backend 0', 'bundle_total_cost': 54.7, 'bundle_total_seatprice': 51, 'bundle_total_send_cost': 1.5, 'bundle_total_surcharge': 2.2, 'currency_code': 'gbp', 'order': [ { 'item_number': 1 }, { 'item_number': 2 }, ], "debitor": { "debitor_type": "dummy" }, "source_t_and_c": 'some legal stuff', "purchase_result": { "success": True, }, } bundle = Bundle.from_api_data(data) assert bundle.source_code == 'ext_test0' assert bundle.currency_code == 'gbp' assert bundle.terms_and_conditions == 'some legal stuff' assert len(bundle.orders) == 2 assert bundle.orders[0].item == 1 assert bundle.orders[1].item == 2 assert bundle.description == 'External Test Backend 0' assert isinstance(bundle.total_seatprice, (int, float)) assert bundle.total_seatprice == 51.0 assert isinstance(bundle.total_surcharge, (int, float)) assert bundle.total_surcharge == 2.2 assert isinstance(bundle.total_send_cost, (int, float)) assert bundle.total_send_cost == 1.5 assert isinstance(bundle.total, (int, float)) assert bundle.total == 54.7 assert isinstance(bundle.debitor, Debitor) assert bundle.debitor.type == 'dummy' assert isinstance(bundle.purchase_result, PurchaseResult) assert bundle.purchase_result.success
def test_from_api_data(self): data = { 'bundle_order_count': 1, 'bundle_source_code': 'ext_test0', 'bundle_source_desc': 'External Test Backend 0', 'bundle_total_cost': 54.7, 'bundle_total_seatprice': 51, 'bundle_total_send_cost': 1.5, 'bundle_total_surcharge': 2.2, 'currency_code': 'gbp', 'order': [ {'item_number': 1}, {'item_number': 2}, ], "debitor": { "debitor_type": "dummy" }, "source_t_and_c": 'some legal stuff', "purchase_result": { "success": True, }, } bundle = Bundle.from_api_data(data) assert bundle.source_code == 'ext_test0' assert bundle.currency_code == 'gbp' assert bundle.terms_and_conditions == 'some legal stuff' assert len(bundle.orders) == 2 assert bundle.orders[0].item == 1 assert bundle.orders[1].item == 2 assert bundle.description == 'External Test Backend 0' assert isinstance(bundle.total_seatprice, (int, float)) assert bundle.total_seatprice == 51.0 assert isinstance(bundle.total_surcharge, (int, float)) assert bundle.total_surcharge == 2.2 assert isinstance(bundle.total_send_cost, (int, float)) assert bundle.total_send_cost == 1.5 assert isinstance(bundle.total, (int, float)) assert bundle.total == 54.7 assert isinstance(bundle.debitor, Debitor) assert bundle.debitor.type == 'dummy' assert isinstance(bundle.purchase_result, PurchaseResult) assert bundle.purchase_result.success
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 test_repr(self): bundle = Bundle('tests') assert repr(bundle) == '<Bundle tests>'