Example #1
0
def test_cannot_allocate_if_sku_do_not_match():
    batch = Batch("batch-001",
                  "UNCOMFORTABLE-CHAIR",
                  100,
                  manufacture_date=None)
    different_sku_line = OrderLine("order-123", "EXPENSIVE-TOASTER", 10)
    assert batch.can_allocate(different_sku_line) is False
Example #2
0
def test_allocating_to_a_batch_reduces_the_available_quantity():
    batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=date.today())
    line = OrderLine("order-ref", "SMALL-TABLE", 2)

    batch.allocate(line)

    assert batch.available_quantity == 18
Example #3
0
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch("in-stock-batch-ref",
                           "HIGHBROW-POSTER", 100, manufacture_date=None)
    shipment_batch = Batch("shipment-batch-ref",
                           "HIGHBROW-POSTER", 100, manufacture_date=tommorrow)
    line = OrderLine("oref", "HIGHBROW-POSTER", 10)
    allocation = allocate(line, [in_stock_batch, shipment_batch])
    assert allocation == in_stock_batch.reference
Example #4
0
def test_prefers_warehouse_batches_to_shipments():
    in_stock_batch = Batch("02", "RETRO_CLOCK", 100, eta=None)
    shipment_batch = Batch("03", "RETRO_CLOCK", 100, eta=tomorrow)
    line = OrderLine("02", "RETRO_CLOCK", 10)

    allocate(line, [in_stock_batch, shipment_batch])

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Example #5
0
def test_prefers_current_stock_batches_to_shipments():
    in_stock_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=None)
    shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow)
    line = OrderLine("oref", "RETRO-CLOCK", 10)

    allocate(line, [in_stock_batch, shipment_batch])

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Example #6
0
def test_allocating_to_a_batch_reduces_the_available_quantity():
    # Arrange
    batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=date.today())
    line = OrderLine('order-ref', "SMALL-TABLE", 2)

    # Act - take action
    batch.allocate(line)

    # Assert
    assert batch.available_quantity == 18
Example #7
0
def test_allocating_to_a_batch_rquantity():
    batch = Batch("batch-001",
                  "SMALL-TABLE",
                  quantity=20,
                  manufacture_date=date.today())
    line = OrderLine("order-ref", "SMALL-TABLE", 2)

    batch.allocate(line)

    assert batch.available_quantity == 18
Example #8
0
def test_prefers_earlier_batches():
    today_batch = Batch("04", "MINIMALIST-SPOON", 100, eta=today)
    tomorrow_batch = Batch("05", "MINIMALIST-SPOON", 100, eta=tomorrow)
    later_batch = Batch("06", "MINIMALIST-SPOON", 100, eta=later)
    line = OrderLine("03", "MINIMALIST-SPOON", 10)

    allocate(line, [today_batch, tomorrow_batch, later_batch])

    assert today_batch.available_quantity == 90
    assert tomorrow_batch.available_quantity == 100
    assert later_batch.available_quantity == 100
Example #9
0
def test_prefers_earlier_batches():
    earliest = Batch("speedy-batch", "MINIMALIST-SPOON", 100, eta=today)
    medium = Batch("normal-batch", "MINIMALIST-SPOON", 100, eta=tomorrow)
    latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later)
    line = OrderLine("order1", "MINIMALIST-SPOON", 10)

    allocate(line, [medium, earliest, latest])

    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
Example #10
0
 def test_prefers_current_stock_batches_to_shipments(self=None):
     """batchesの最初のひとつめにしか処理がかからないことを確認"""
     tomorrow = (datetime.datetime.now() + datetime.timedelta(days=1))
     in_stock_batch = Batch('in-stock-batch', 'RETRO-CLOCK', 100, eta=None)
     shipment_batch = Batch('shipment-batch',
                            'RETRO-CLOCK',
                            100,
                            eta=tomorrow)
     line = OrderLine('oref', 'RETRO-CLOCK', 10)
     allocate(line, [in_stock_batch, shipment_batch])
     self.assertEqual(90, in_stock_batch.available_quantity)
     self.assertEqual(100, shipment_batch.available_quantity)
Example #11
0
 def test_returns_allocated_batch_ref(self):
     """Batchとallocateの返却が一致することを確認"""
     tomorrow = (datetime.datetime.now() + datetime.timedelta(days=1))
     in_stock_batch = Batch('in-stock-batch-ref',
                            'HIGHBROW-POSTER',
                            100,
                            eta=None)
     shipment_batch = Batch('shipment-batch-ref',
                            'HIGHBROW-POSTER',
                            100,
                            eta=tomorrow)
     line = OrderLine('oref', 'HIGHBROW-POSTER', 10)
     allocation = allocate(line, [in_stock_batch, shipment_batch])
     self.assertTrue(allocation == in_stock_batch.reference)
Example #12
0
 def test_prefers_earlier_batches(self):
     """batchesをソートした上で先頭の要素にallocateが実行されることを確認"""
     today = datetime.datetime.now()
     tomorrow = (datetime.datetime.now() + datetime.timedelta(days=1))
     later = (datetime.datetime.now() + datetime.timedelta(weeks=4))
     earliest = Batch('speedy-batch', 'MINIMALIST-SPOON', 100, eta=today)
     medium = Batch('normal-batch', 'MINIMALIST-SPOON', 100, eta=tomorrow)
     latest = Batch('slow-batch', 'MINIMALIST-SPOON', 100, eta=later)
     line = OrderLine('order1', 'MINIMALIST-SPOON', 10)
     allocate(line, [medium, earliest, latest])  # 順番に注目earliestは2番目
     self.assertEqual(
         90, earliest.available_quantity)  # 2番目にあるearliestにオーダーがかかった
     self.assertEqual(100, medium.available_quantity)
     self.assertEqual(100, latest.available_quantity)
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch("in-stock-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=None)
    shipment_batch = Batch("shipment-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=tomorrow)
    line = OrderLine("order1", "HIGHBROW-POSTER", 10)

    ref = allocate(line, [in_stock_batch, shipment_batch])

    assert ref == in_stock_batch.reference
Example #14
0
 def test_raises_out_of_stock_exception_if_cannot_allocate(self):
     batch = Batch('batch1', 'SMALL-FORK', 10, eta=datetime.datetime.now())
     line = OrderLine('order1', 'SMALL-FORK', 10)
     allocate(line, [batch])
     with pytest.raises(OutOfStock, match='SMALL-FORK'):
         line = OrderLine('order2', 'SMALL-FORK', 1)
         allocate(line, [batch])
Example #15
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("05", "SMALL_FORK", 10, eta=today)
    line1 = OrderLine("05", "SMALL_FORK", 10)
    line2 = OrderLine("05", "SMALL_FORK", 1)

    allocate(line1, [batch])
    with pytest.raises(OutOfStock, match="SMALL_FORK"):
        allocate(line2, [batch])
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("batch-ref", "SPOON", 100, eta=today)
    line = OrderLine("order1", "SPOON", 100)

    allocate(line, [batch])

    with pytest.raises(OutOfStock, match="SPOON"):
        line2 = OrderLine("order2", "SPOON", 10)
        allocate(line2, [batch])
Example #17
0
def make_batch_and_line(sku, batch_qty, line_qty):
    return (
        Batch("batch-001", sku, batch_qty, eta=date.today()),
        OrderLine("order-123", sku, line_qty),
    )
Example #18
0
def test_allocating_to_a_batch_reduces_the_available_quantity():
    batch = Batch("1", "SMALL_TABLE", qty=20, eta=today)
    line = OrderLine("1", "SMALL_TABLE", 2)

    batch.allocate(line)
    assert batch.available_quantity == 18
Example #19
0
def make_batch_and_line(sku: str, batch_qty: int, line_qty: int):
    return (Batch("Batch-001", sku, batch_qty,
                  eta=date.today()), OrderLine("Order-123", sku, line_qty))
def test_equality():
    batch1 = Batch("batch-001", "SMALL-TABLE", 20, eta=date.today())
    batch2 = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 22, eta=date.today())
    assert batch1 == batch2
Example #21
0
 def test_can_twice_allocate_ng_purchase2(self):
     """オーダー番号が違っても商品が違うと受け付けない"""
     batch = Batch('batch-001', 'ELEGANT-LAMP', 20, eta=date.today())
     batch.allocate(OrderLine('order-123', 'ELEGANT-LAMP', 2))
     batch.allocate(OrderLine('order-1233', 'ELEGANT-LAMPP', 2))
     self.assertEqual(18, batch.available_quantity)
Example #22
0
 def test_cannot_allocate_if_skus_do_not_match(self):
     """商品コードが違えば割り当てることはできない"""
     batch = Batch('batch-001', 'UNCOMFORTABLE-CHAIR', 100, eta=None)
     different_sku_line = OrderLine('order-123', 'EXPENSIVE-TOASTER', 10)
     self.assertFalse(batch.can_allocate(different_sku_line))
Example #23
0
def test_cannot_allocate_if_skus_do_not_match():
    batch = Batch('batch-001', 'UNCOMFORTABLE-CHAIR', 100, eta=None)
    different_sku_line = OrderLine('order-123', 'EXPENSIVE-TOASTER', 10)
    assert batch.can_allocate(different_sku_line) is False
Example #24
0
def make_batch_and_line(sku, batch_qty, line_qty):
    return (Batch('batch-001', sku, batch_qty,
                  eta=date.today()), OrderLine('order-123', sku, line_qty))
def test_cant_allocate_if_sku_doesnt_match():
    batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 100, eta=None)
    different_sku_line = OrderLine("order-123", "EXPENSIVE-TOASTER", 10)
    print(batch.can_allocate(different_sku_line))
def test_allocatint_to_a_batch_reduces_available_quantity():
    batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=date.today())
    line = OrderLine("order-ref", "SMALL-TABLE", 2)
    batch.allocate(line)
    print(batch._allocations)
Example #27
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
    allocate(OrderLine("order1", "SMALL-FORK", 10), [batch])

    with pytest.raises(OutOfStock, match="SMALL-FORK"):
        allocate(OrderLine("order2", "SMALL-FORK", 1), [batch])
Example #28
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    allocate(OrderLine('order1', 'SMALL-FORK', 10), [batch])

    with pytest.raises(OutOfStock, match='SMALL-FORK'):
        allocate(OrderLine('order2', 'SMALL-FORK', 1), [batch])
Example #29
0
 def test_allocating_to_a_batch_reduces_the_available_quantity(self):
     batch = Batch('batch-001', 'SMALL-TABLE', qty=20, eta=date.today())
     line = OrderLine('order-ref', "SMALL-TABLE", 2)
     batch.allocate(line)
     self.assertEqual(18, batch.available_quantity)
Example #30
0
 def test_can_twice_allocate_ok_purchase(self):
     """オーダー番号が違えば2連続注文を受け付ける"""
     batch = Batch('batch-001', 'ELEGANT-LAMP', 20, eta=date.today())
     batch.allocate(OrderLine('order-123', 'ELEGANT-LAMP', 2))
     batch.allocate(OrderLine('order-1233', 'ELEGANT-LAMP', 2))
     self.assertEqual(16, batch.available_quantity)