def test__order_aggregator__order_item_is_added_to_list_after_calling_add_item( ): """Test.""" oa = OrderAggregator() item = OrderItem("customer", "item", 11, 1) oa.add_item(item) assert len(oa.order_items) == 1 assert oa.order_items[0] is item
def test__order_aggregator__all_order_items_are_in_the_list_if_add_item_is_called_multiple_times( ): """Test.""" oa = OrderAggregator() item1 = OrderItem("customer", "item", 11, 1) item2 = OrderItem("customer", "item2", 20, 4) oa.add_item(item1) oa.add_item(item2) assert len(oa.order_items) == 2 assert oa.order_items[0] is item1 assert oa.order_items[1] is item2
def test__order_aggregator__aggregates_order_with_exact_capacity_and_quantity_for_customer( ): """Test.""" oa = OrderAggregator() item1 = OrderItem("customer", "item1", 1, 1) item2 = OrderItem("customer", "item2", 2, 2) oa.add_item(item1) oa.add_item(item2) order = oa.aggregate_order("customer", 3, 5) assert len(order.order_items) == 2 assert order.order_items[0] is item1 assert order.order_items[1] is item2
def test__order_aggregator__ignores_next_item_if_max_items_volume_is_exceeded( ): """Test.""" oa = OrderAggregator() item1 = OrderItem("customer", "item1", 1, 1) item2 = OrderItem("customer", "item2", 2, 2) oa.add_item(item1) oa.add_item(item2) order = oa.aggregate_order("customer", 3, 2) assert len(order.order_items) == 1 assert order.order_items[0] is item1 assert len(oa.order_items) == 1 assert oa.order_items[0] is item2
def test__order_aggregator__ignores_other_customers_items_when_aggregating_order( ): """Test.""" oa = OrderAggregator() c1_item = OrderItem("customer1", "item1", 1, 1) c2_item = OrderItem("customer2", "item2", 2, 2) oa.add_item(c1_item) oa.add_item(c2_item) order = oa.aggregate_order("customer1", 3, 999999999999) assert len(order.order_items) == 1 assert order.order_items[0] is c1_item assert len(oa.order_items) == 1 assert oa.order_items[0] is c2_item
def test__order_aggregator__order_item_is_removed_after_it_is_aggregated_to_order( ): """Test.""" oa = OrderAggregator() item1 = OrderItem("customer", "item1", 1, 1) item2 = OrderItem("customer", "item2", 2, 2) oa.add_item(item1) oa.add_item(item2) oa.aggregate_order("customer", 3, 5) assert len(oa.order_items) == 0
def test__components_integration__create_containers_from_order_items__happy_case( ): """Test.""" orders_items = ( OrderItem("Apple", "iPhone 11", 103, 10), OrderItem("Apple", "iPhone X", 41, 9), OrderItem("Tallink", "Laev", 1, 100000), # too big OrderItem("Nike", "Sneakers", 244, 10), OrderItem("Nike", "Other ", 145, 11), OrderItem("Paper", "Paper", 1030, 5), OrderItem("Apple", "Apple TV", 12, 5), OrderItem("???", "___", 235, 10), ) oa = OrderAggregator() for oi in orders_items: oa.add_item(oi) apple_orders_quantity = 103 + 41 apple_orders_volume = 103 * 10 + 41 * 9 apple_order = oa.aggregate_order("Apple", apple_orders_quantity, apple_orders_volume) apple_order.destination = "Somewhere" nike_order_quantity_with_buffer = 244 + 145 + 10 nike_order_volume_with_buffer = 244 * 10 + 145 * 11 + 99 nike_order = oa.aggregate_order("Nike", nike_order_quantity_with_buffer, nike_order_volume_with_buffer) nike_order.destination = "Neverland" volume = 244 * 10 + 145 * 11 ca = ContainerAggregator(volume) containers = ca.prepare_containers((nike_order, apple_order)) assert apple_order.total_quantity == apple_orders_quantity assert apple_order.total_volume == apple_orders_volume assert apple_order.order_items == [orders_items[0], orders_items[1]] assert nike_order.total_quantity == 244 + 145 assert nike_order.total_volume == 244 * 10 + 145 * 11 assert nike_order.order_items == [orders_items[3], orders_items[4]] assert len(containers) == 2 somewhere_containers = containers['Somewhere'] assert len(somewhere_containers) == 1 assert somewhere_containers[0].volume == volume assert somewhere_containers[0].orders == [apple_order] neverland_containers = containers['Neverland'] assert len(neverland_containers) == 1 assert neverland_containers[0].volume == volume assert neverland_containers[0].orders == [nike_order]
def test__order_aggregator__order_items_list_is_empty_after_creation(): """Test.""" oa = OrderAggregator() assert len(oa.order_items) == 0