예제 #1
0
def test__container_aggregator__creates_new_container_if_order_does__not_fit_to_already_existing_container(
):
    """Test."""
    ca = ContainerAggregator(50)
    order1 = Order([
        OrderItem("customer", "item1", 4, 5),
        OrderItem("customer", "item2", 1, 28)
    ])
    order2 = Order([OrderItem("customer", "item3", 1, 1)])
    order3 = Order([OrderItem("customer", "item4", 10, 2)])
    order1.destination = "Tallinn"
    order2.destination = "Tallinn"
    order3.destination = "Tallinn"

    containers = ca.prepare_containers((order1, order2, order3))

    assert len(containers) == 1

    tallinn_containers = containers['Tallinn']
    assert len(tallinn_containers) == 2

    assert tallinn_containers[0].volume == 50
    assert tallinn_containers[0].orders == [order1, order2]

    assert tallinn_containers[1].volume == 50
    assert tallinn_containers[1].orders == [order3]
예제 #2
0
def test__container_aggregator__returns_two_containers_with_correct_orders_and_volume_if_has_orders_to_two_dif_dest(
):
    """Test."""
    ca = ContainerAggregator(999999)
    order1 = Order([
        OrderItem("customer", "item1", 1, 1),
        OrderItem("customer", "item2", 1, 1)
    ])
    order2 = Order([OrderItem("customer", "item1", 1, 1)])
    order1.destination = "Tallinn"
    order2.destination = "Tokyo"

    containers = ca.prepare_containers((order1, order2))

    assert len(containers) == 2

    tallinn_containers = containers['Tallinn']
    assert len(tallinn_containers) == 1
    assert tallinn_containers[0].volume == 999999
    assert tallinn_containers[0].orders == [order1]

    tokyo_containers = containers['Tokyo']
    assert len(tokyo_containers) == 1
    assert tokyo_containers[0].volume == 999999
    assert tokyo_containers[0].orders == [order2]
예제 #3
0
def test__container_aggregator__does_not_add_dest_to_dict_if_no_containers_are_created(
):
    """Test."""
    ca = ContainerAggregator(50)
    order_that_wont_fit = Order([OrderItem("customer", "item4", 10, 10)])
    order_that_wont_fit.destination = "Tallinn"

    containers = ca.prepare_containers((order_that_wont_fit, ))

    assert containers == {}
예제 #4
0
def test__container_aggregator__sets_correct_volume_to_new_container():
    """Test."""
    ca = ContainerAggregator(999999)
    order1 = Order([
        OrderItem("customer", "item1", 1, 1),
        OrderItem("customer", "item2", 1, 1)
    ])
    order2 = Order([OrderItem("customer", "item1", 1, 1)])
    order1.destination = "Tallinn"
    order2.destination = "Tallinn"
    containers = ca.prepare_containers((order1, order2))

    assert containers['Tallinn'][0].volume == 999999
예제 #5
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]
예제 #6
0
def test__container_aggregator__correct_container_volume_is_assigned_and_not_used_orders_is_empty_list_after_creation(
):
    """Test."""
    ca = ContainerAggregator(400)

    assert ca.container_volume == 400
    assert ca.not_used_orders == []
예제 #7
0
def test__container_aggregator__puts_orders_that_cannot_be_added_to_container_to_not_used_orders_list(
):
    """Test."""
    ca = ContainerAggregator(50)
    order1 = Order([
        OrderItem("customer", "item1", 4, 5),
        OrderItem("customer", "item2", 1, 28)
    ])
    order_that_wont_fit = Order([OrderItem("customer", "item4", 10, 10)])
    order3 = Order([OrderItem("customer", "item4", 10, 2)])
    order1.destination = "Tallinn"
    order3.destination = "Tallinn"
    order_that_wont_fit.destination = "Tallinn"

    ca.prepare_containers((order1, order_that_wont_fit, order3))

    assert ca.not_used_orders == [order_that_wont_fit]
예제 #8
0
def test__container_aggregator__puts_orders_to_one_dest_container_if_possible(
):
    """Test."""
    ca = ContainerAggregator(999999)
    order1 = Order([
        OrderItem("customer", "item1", 1, 1),
        OrderItem("customer", "item2", 1, 1)
    ])
    order2 = Order([OrderItem("customer", "item1", 1, 1)])
    order3 = Order([
        OrderItem("customer5", "item1", 1, 1),
        OrderItem("customer3", "item2", 1, 1)
    ])
    order4 = Order([OrderItem("customer", "item1", 1, 1)])
    order1.destination = "Tallinn"
    order2.destination = "Tallinn"
    order3.destination = "Tallinn"
    order4.destination = "Tallinn"
    orders = (order1, order2, order3, order4)

    containers = ca.prepare_containers(orders)

    assert len(containers) == 1
    assert containers['Tallinn'][0].orders == [order1, order2, order3, order4]