Exemple #1
0
def add_batch():
    session = get_session()
    repo = repository.SqlAlchemyRepository(session)
    eta = request.json['eta']
    if eta is not None:
        eta = datetime.fromisoformat(eta).date()
    services.add_batch(request.json['ref'], request.json['sku'],
                       request.json['qty'], eta, repo, session)
Exemple #2
0
def test_repository_can_save_a_batch(session_factory):
    session = session_factory
    batch = model.Batch("batch1", "RUSTY-SOAPDISH", 100, eta=None)

    repo = repository.SqlAlchemyRepository(session)
    repo.add(batch)
    session.commit()

    rows = list(
        session.execute(
            'SELECT reference, sku, _purchased_quantity, eta FROM "batches"'))
    assert rows == [("batch1", "RUSTY-SOAPDISH", 100, None)]
def test_get_by_batchref(sqlite_session_factory):
    session = sqlite_session_factory()
    repo = repository.SqlAlchemyRepository(session)
    b1 = model.Batch(ref='b1', sku='sku1', qty=100, eta=None)
    b2 = model.Batch(ref='b2', sku='sku1', qty=100, eta=None)
    b3 = model.Batch(ref='b3', sku='sku2', qty=100, eta=None)
    p1 = model.Product(sku='sku1', batches=[b1, b2])
    p2 = model.Product(sku='sku2', batches=[b3])
    repo.add(p1)
    repo.add(p2)
    assert repo.get_by_batchref('b2') == p1
    assert repo.get_by_batchref('b3') == p2
Exemple #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.deallocate(line, repo, session)
    except (model.NotAllocatedOrder, services.InvalidSku) as e:
        return jsonify({'message': str(e)}), 400

    session.commit()
    return jsonify({'batchref': batchref}), 201
Exemple #5
0
def test_repository_can_retrieve_a_batch_with_allocations(session_factory):
    session = session_factory
    orderline_id = insert_order_line(session)
    batch1_id = insert_batch(session, "batch1")
    insert_batch(session, "batch2")
    insert_allocation(session, orderline_id, batch1_id)

    retrieved = repository.SqlAlchemyRepository(session).get("batch1")
    #retrieved = repo.get("batch1")

    expected = model.Batch("batch1", "GENERIC-SOFA", 100, eta=None)
    assert retrieved == expected  # Batch.__eq__ only compares reference
    assert retrieved.sku == expected.sku
    assert retrieved._purchased_quantity == expected._purchased_quantity
    assert retrieved._allocations == {
        model.OrderLine("order1", "GENERIC-SOFA", 12),
    }
 def __enter__(self):
     self.session = self.session_factory()  # type: Session
     self.products = repository.SqlAlchemyRepository(self.session)
     return super().__enter__()
Exemple #7
0
    def __enter__(self):
        self.session: Session = self.session_factory()
        self.batches = repository.SqlAlchemyRepository(self.session)

        return super().__enter__()