Exemplo n.º 1
0
def test_increments_version_number():
    line = OrderLine("oref", "SCANDI-PEN", 10)
    product = Product(sku="SCANDI-PEN",
                      batches=[Batch("b1", "SCANDI-PEN", 100, eta=None)])
    product.version_number = 7
    product.allocate(line)
    assert product.version_number == 8
Exemplo n.º 2
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine("order1", "SMALL-FORK", 10))

    with pytest.raises(OutOfStock, match="SMALL-FORK"):
        product.allocate(OrderLine("order2", "SMALL-FORK", 1))
Exemplo n.º 3
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
Exemplo n.º 4
0
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)
    product = Product(sku="HIGHBROW-POSTER",
                      batches=[in_stock_batch, shipment_batch])

    allocation = product.allocate(line)

    assert allocation == in_stock_batch.reference
Exemplo n.º 5
0
def test_records_out_of_stock_event_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None
Exemplo n.º 6
0
def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected
Exemplo n.º 7
0
def test_increment_version_number():
    product = Product(sku='SCANDI-PEN',
                      batches=[Batch('b1', 'SCANDI-PEN', 100, eta=None)])
    product.version_number = 7

    line = OrderLine('oref', 'SCANDI-PEN', 10)
    product.allocate(line)

    assert product.version_number == 8
Exemplo n.º 8
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch("batch-001", "SMALL-TABLE", qty=5, eta=today)
    line1 = OrderLine("order-1", "SMALL-TABLE", 5)
    line2 = OrderLine("order-2", "SMALL-TABLE", 5)

    product = Product(sku="SMALL-TABLE", batches=[batch])
    product.allocate(line1)

    allocation = product.allocate(line2)
    assert product.events[-1] == OutOfStock(sku="SMALL-TABLE")
    assert allocation is None
Exemplo n.º 9
0
def test_cannot_allocate_if_skus_do_not_match():
    batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 100, eta=None)
Exemplo n.º 10
0

def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected


def test_records_out_of_stock_event_if_cannot_allocate():
<<<<<<< HEAD
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine('order1', 'SMALL-FORK', 10))

    allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
=======
    batch = Batch("batch1", "SMALL-FORK", 10, eta=today)
    product = Product(sku="SMALL-FORK", batches=[batch])
    product.allocate(OrderLine("order1", "SMALL-FORK", 10))

    allocation = product.allocate(OrderLine("order2", "SMALL-FORK", 1))
>>>>>>> upstream/master
    assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
    assert allocation is None

Exemplo n.º 11
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
Exemplo n.º 12
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))
Exemplo n.º 13
0
def test_cannot_allocate_if_skus_do_not_match():
    batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 10)
    line = OrderLine("line-123", "SMALL-TABLE", 2)
    assert batch.can_allocate(line) is False
Exemplo n.º 14
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])
Exemplo n.º 15
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])
Exemplo n.º 16
0
def test_allocating_to_a_batch_reduces_the_available_quantity():
    batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=date.today())
Exemplo n.º 17
0
def test_cannot_allocate_if_skus_do_not_match():
    batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=today)
    line = OrderLine("order-123", "BIG-SOFA", 2)

    assert not batch.can_allocate(line)