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])
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_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
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
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])
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
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
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)
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('oref', 'HIGHBROW-POSTER', 10) allocation = allocate(line, [in_stock_batch, shipment_batch]) assert allocation == in_stock_batch.reference
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
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)
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
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])
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])