예제 #1
0
def test_deallocation(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch('b1', 'sku1', 50, None))
    sqlite_bus.handle(commands.CreateBatch('b2', 'sku1', 50, today))
    sqlite_bus.handle(commands.Allocate('o1', 'sku1', 40))
    sqlite_bus.handle(commands.ChangeBatchQuantity('b1', 10))

    assert views.allocations('o1') == [{'sku': 'sku1', 'batchref': 'b2'}]
예제 #2
0
def test_allocations_view(sqlite_bus):
    # uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    sqlite_bus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None))
    sqlite_bus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, None))
    sqlite_bus.handle(commands.Allocate(
        'order1',
        'sku1',
        20,
    ))
    sqlite_bus.handle(commands.Allocate(
        'order1',
        'sku2',
        20,
    ))

    sqlite_bus.handle(
        commands.CreateBatch('sku1batch-later', 'sku1', 50, today))
    sqlite_bus.handle(commands.Allocate('other-order', 'sku1', 30))
    sqlite_bus.handle(commands.Allocate('other-order', 'sku2', 10))

    assert views.allocations('order1', sqlite_bus.uow) == [
        {
            'sku': 'sku1',
            'batchref': 'sku1batch'
        },
        {
            'sku': 'sku2',
            'batchref': 'sku2batch'
        },
    ]
예제 #3
0
def fetch_allocations(order_id: str = None) -> tuple:
    uow = unit_of_work.SqlAlchemyUnitOfWork()
    if order_id:
        result = views.allocations(order_id, uow)
        if result:
            return jsonify(result), 200
        return jsonify({"message": "not found"}), 404
    result = views.all_allocations(uow)
    return jsonify(result), 200
예제 #4
0
def test_deallocation(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch("b1", "sku1", 50, None))
    sqlite_bus.handle(commands.CreateBatch("b2", "sku1", 50, today))
    sqlite_bus.handle(commands.Allocate("o1", "sku1", 40))
    sqlite_bus.handle(commands.ChangeBatchQuantity("b1", 10))

    assert views.allocations("o1", sqlite_bus.uow) == [
        {"sku": "sku1", "batchref": "b2"},
    ]
예제 #5
0
def test_deallocation(sqlite_session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    messagebus.handle(commands.CreateBatch("b1", "sku1", 50, None), uow)
    messagebus.handle(commands.CreateBatch("b2", "sku1", 50, today), uow)
    messagebus.handle(commands.Allocate("o1", "sku1", 40), uow)
    messagebus.handle(commands.ChangeBatchQuantity("b1", 10), uow)

    assert views.allocations("o1", uow) == [
        {"sku": "sku1", "batchref": "b2"},
    ]
예제 #6
0
def test_allocations_view(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch('b1', 'sku1', 50, None))
    sqlite_bus.handle(commands.CreateBatch('b2', 'sku2', 50, date.today()))
    sqlite_bus.handle(commands.Allocate('o1', 'sku1', 20))
    sqlite_bus.handle(commands.Allocate('o1', 'sku2', 20))

    assert views.allocations('o1', sqlite_bus.uow) == [
        {'sku': 'sku1', 'batchref': 'b1'},
        {'sku': 'sku2', 'batchref': 'b2'},
    ]
예제 #7
0
def test_deallocation(messagebus, random_orderid):
    orderid = random_orderid()
    messagebus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None))
    messagebus.handle(commands.CreateBatch("sku2batch", "sku1", 50, today))
    messagebus.handle(commands.Allocate(orderid, "sku1", 20))
    assert views.allocations(orderid, messagebus.uow) == [
        {
            "sku": "sku1",
            "qty": 20,
            "batchref": "sku1batch"
        },
    ]
    messagebus.handle(commands.ChangeBatchQuantity("sku1batch", 10))

    assert views.allocations(orderid, messagebus.uow) == [
        {
            "sku": "sku1",
            "qty": 20,
            "batchref": "sku2batch"
        },
    ]
예제 #8
0
def test_deallocation(sqlite_session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    messagebus.handle(commands.CreateBatch('b1', 'sku1', 50, None), uow)
    messagebus.handle(commands.CreateBatch('b2', 'sku1', 50, today), uow)
    messagebus.handle(commands.Allocate('o1', 'sku1', 40), uow)
    messagebus.handle(commands.ChangeBatchQuantity('b1', 10), uow)

    assert views.allocations('o1', uow) == [
        {
            'sku': 'sku1',
            'batchref': 'b2'
        },
    ]
예제 #9
0
def test_allocations_view(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None))
    sqlite_bus.handle(commands.CreateBatch("sku2batch", "sku2", 50, today))
    sqlite_bus.handle(commands.Allocate("order1", "sku1", 20))
    sqlite_bus.handle(commands.Allocate("order1", "sku2", 20))
    # add a spurious batch and order to make sure we're getting the right ones
    sqlite_bus.handle(commands.CreateBatch("sku1batch-later", "sku1", 50, today))
    sqlite_bus.handle(commands.Allocate("otherorder", "sku1", 30))
    sqlite_bus.handle(commands.Allocate("otherorder", "sku2", 10))

    assert views.allocations("order1", sqlite_bus.uow) == [
        {"sku": "sku1", "batchref": "sku1batch"},
        {"sku": "sku2", "batchref": "sku2batch"},
    ]
예제 #10
0
def test_deallocation(sqlite_bus):
    sqlite_bus.handle([
        commands.CreateBatch('b1', 'sku1', 50, None),
        commands.CreateBatch('b2', 'sku1', 50, date.today()),
        commands.Allocate('o1', 'sku1', 40),
        commands.ChangeBatchQuantity('b1', 10)
    ])

    assert views.allocations('o1', sqlite_bus.uow) == [
        {
            'sku': 'sku1',
            'batchid': 'b2'
        },
    ]
예제 #11
0
def test_allocations_view(sqlite_bus):
    sqlite_bus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None))
    sqlite_bus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, date.today()))
    sqlite_bus.handle(commands.Allocate('order1', 'sku1', 20))
    sqlite_bus.handle(commands.Allocate('order1', 'sku2', 20))
    # add a spurious batch and order to make sure we're getting the right ones
    sqlite_bus.handle(commands.CreateBatch('sku1batch-later', 'sku1', 50, date.today()))
    sqlite_bus.handle(commands.Allocate('otherorder', 'sku1', 30))
    sqlite_bus.handle(commands.Allocate('otherorder', 'sku2', 10))

    assert views.allocations('order1', sqlite_bus.uow) == [
        {'sku': 'sku1', 'batchref': 'sku1batch'},
        {'sku': 'sku2', 'batchref': 'sku2batch'},
    ]
예제 #12
0
def test_allocations_view(sqlite_session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    messagebus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None), uow)
    messagebus.handle(commands.CreateBatch("sku2batch", "sku2", 50, today), uow)
    messagebus.handle(commands.Allocate("order1", "sku1", 20), uow)
    messagebus.handle(commands.Allocate("order1", "sku2", 20), uow)
    # add a spurious batch and order to make sure we're getting the right ones
    messagebus.handle(commands.CreateBatch("sku1batch-later", "sku1", 50, today), uow)
    messagebus.handle(commands.Allocate("otherorder", "sku1", 30), uow)
    messagebus.handle(commands.Allocate("otherorder", "sku2", 10), uow)

    assert views.allocations("order1", uow) == [
        {"sku": "sku1", "batchref": "sku1batch"},
        {"sku": "sku2", "batchref": "sku2batch"},
    ]
예제 #13
0
def test_allocations_view(sqlite_session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    messagebus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None), uow)
    messagebus.handle(commands.CreateBatch('sku2batch', 'sku2', 50, today),
                      uow)
    messagebus.handle(commands.Allocate('order1', 'sku1', 20), uow)
    messagebus.handle(commands.Allocate('order1', 'sku2', 20), uow)

    assert views.allocations('order1', uow) == [
        {
            'sku': 'sku1',
            'batchref': 'sku1batch'
        },
        {
            'sku': 'sku2',
            'batchref': 'sku2batch'
        },
    ]
예제 #14
0
def test_allocations_view(session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(session_factory)
    messagebus.handle(commands.CreateBatch('sku1batch', 'sku1', 50, None), uow)
    messagebus.handle(
        commands.CreateBatch('sku2batch', 'sku2', 50, date.today()), uow)
    messagebus.handle(commands.Allocate('vieworder1', 'sku1', 20), uow)
    messagebus.handle(commands.Allocate('vieworder1', 'sku2', 20), uow)
    # add a spurious batch and order to make sure we're getting the right ones
    messagebus.handle(
        commands.CreateBatch('sku1batch-later', 'sku1', 50, date.today()), uow)
    messagebus.handle(commands.Allocate('otherorder', 'sku1', 30), uow)
    messagebus.handle(commands.Allocate('otherorder', 'sku2', 10), uow)

    assert views.allocations('vieworder1', uow) == [{
        'sku': 'sku1',
        'batchref': 'sku1batch'
    }, {
        'sku': 'sku2',
        'batchref': 'sku2batch'
    }]
예제 #15
0
def test_allocations_view(messagebus, random_orderid):
    orderid = random_orderid()
    messagebus.handle(commands.CreateBatch("sku1batch", "sku1", 50, None))
    messagebus.handle(commands.CreateBatch("sku2batch", "sku2", 50, today))
    messagebus.handle(commands.Allocate(orderid, "sku1", 20))
    messagebus.handle(commands.Allocate(orderid, "sku2", 20))
    # add a spurious batch and order to make sure we're getting the right ones
    messagebus.handle(
        commands.CreateBatch("sku1batch-later", "sku1", 50, today))
    messagebus.handle(commands.Allocate(random_orderid(), "sku1", 30))
    messagebus.handle(commands.Allocate(random_orderid(), "sku2", 10))

    assert views.allocations(orderid, messagebus.uow) == [
        {
            "sku": "sku1",
            "batchref": "sku1batch",
            "qty": 20
        },
        {
            "sku": "sku2",
            "batchref": "sku2batch",
            "qty": 20
        },
    ]
예제 #16
0
def allocations_view_endpoint(orderid):
    uow = SqlAlchemyUnitOfWork()
    result = views.allocations(orderid, uow)
    if not result:
        return 'not fount', 404
    return jsonify(result), 200
예제 #17
0
def allocations_view_endpoint(orderid):
    uow = unit_of_work.SqlAlchemyUnitOfWork()
    result = views.allocations(orderid, uow)
    if not result:
        return {"message": "Not found"}, 404
    return jsonify(result), 200
예제 #18
0
def allocations_view_endpoint(orderid):
    result = views.allocations(orderid, bus.uow)
    if not result:
        return "not found", 404
예제 #19
0
파일: flask_app.py 프로젝트: hbeemster/code
def allocations_view_endpoint(orderid):
    result = views.allocations(orderid, bus.uow)
    if not result:
        return 'not found', 404
    return jsonify(result), 200
예제 #20
0
def test_view_specific_orderline(sqlite_session_factory):
    uow = unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory)
    batchref, orderid, sku = create_and_allocate_batch(uow)

    [orderline] = views.allocations(orderid, uow)
    assert orderline["batchref"] == batchref