Beispiel #1
0
def test_allocate_errors_for_invalid_sku():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "AREALSKU", 100, None, uow)

    with pytest.raises(services.InvalidSku,
                       match="Invalid sku NONEXISTENTSKU"):
        services.allocate("o1", "NONEXISTENTSKU", 10, uow)
Beispiel #2
0
def test_deallocate_decrements_available_quantity():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "BLUE-PLINTH", 100, None, uow)
    services.allocate('o1', 'BLUE-PLINTH', 10, uow)
    batch = uow.batches.get(sku="BLUE-PLINTH")
    assert batch.available_quantity == 90

    services.deallocate('o1', 'BLUE-PLINTH', 10, uow)
    batch = uow.batches.get(sku='BLUE-PLINTH')
    assert batch.available_quantity == 100
Beispiel #3
0
def allocate_endpoint():
    # return jsonify({'message': 'dentro.. al enpoint'})
    uow = unit_of_work.SqlAlchemyUnitOfWork()
    try:
        batchref = services.allocate(request.json['orderid'],
                                     request.json['sku'], request.json['qty'],
                                     uow)
        # batchref=request.json['orderid']+"lalalla"
    except (model.OutOfStock, services.InvalidSku) as e:
        return jsonify({'message': str(e)}), 400
    return jsonify({'batchref': batchref}), 201
Beispiel #4
0
def allocate_endpoint():
    session = get_session()
    repo = repository.SqlAlchemyRepository(session)
    line = model.OrderLine(request.json['orderid'], request.json['sku'],
                           request.json['qty'])

    try:
        batchref = services.allocate(line, repo, session)
    except (model.OutOfStock, services.InvalidSku) as e:
        return jsonify({'message': str(e)}), 400

    session.commit()
    return jsonify({'batchref': batchref}), 201
Beispiel #5
0
def test_commits():
    uow = FakeUnitOfWork()
    services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow)
    services.allocate("o1", "OMINOUS-MIRROR", 10, uow)
    assert uow.committed
Beispiel #6
0
def test_allocate_returns_allocation():
    uow = FakeUnitOfWork()
    services.add_batch("batch1", "COMPLICATED-LAMP", 100, None, uow)
    result = services.allocate("o1", "COMPLICATED-LAMP", 10, uow)
    assert result == "batch1"
Beispiel #7
0
def test_error_for_invalid_sku():
    uow = FakeUnitOfWork()
    services.add_batch("batch", "EXISTINGSKU", 100, None, uow)
    with pytest.raises(services.InvalidSku,
                       match="Invalid sku NONEXISTINGSKU"):
        services.allocate("o1", 'NONEXISTINGSKU', 10, uow)