def bootstrap_test_app():
    return bootstrap.bootstrap(
        start_orm=False,
        uow=FakeUnitOfWork(),
        notifications=FakeNotifications(),
        publish=lambda *args: None,
    )
def main():
    logger.info('Redis pubsub starting')
    bus = bootstrap.bootstrap()
    pubsub = r.pubsub(ignore_subscribe_messages=True)
    pubsub.subscribe('change_batch_quantity')

    for m in pubsub.listen():
        handle_change_batch_quantity(m, bus)
Esempio n. 3
0
def sqlite_bus(sqlite_session_factory):
    bus = bootstrap.bootstrap(
        start_orm=True,
        uow=unit_of_work.SqlAlchemyUnitOfWork(sqlite_session_factory),
        notifications=mock.Mock(),
        publish=lambda *args: None,
    )
    yield bus
    clear_mappers()
 def test_sends_email_on_out_of_stock_error(self):
     fake_notifs = FakeNotifications()
     bus = bootstrap.bootstrap(
         start_orm=False,
         uow=FakeUnitOfWork(),
         notifications=fake_notifs,
         publish=lambda *args: None,
     )
     bus.handle(commands.CreateBatch("b1", "POPULAR-CURTAINS", 9, None))
     bus.handle(commands.Allocate("o1", "POPULAR-CURTAINS", 10))
     assert fake_notifs.sent['*****@*****.**'] == [
         f"Out of stock for POPULAR-CURTAINS",
     ]
Esempio n. 5
0
from datetime import datetime
from flask import Flask, jsonify, request
from src.allocation.domain import commands
from src.allocation.service_layer.handlers import InvalidSku
from src.allocation import bootstrap, views

app = Flask(__name__)
bus = bootstrap.bootstrap()


@app.route("/add_batch", methods=['POST'])
def add_batch():
    eta = request.json['eta']
    if eta is not None:
        eta = datetime.fromisoformat(eta).date()
    cmd = commands.CreateBatch(
        request.json['ref'],
        request.json['sku'],
        request.json['qty'],
        eta,
    )
    bus.handle(cmd)
    return 'OK', 201


@app.route("/allocate", methods=['POST'])
def allocate_endpoint():
    try:
        cmd = commands.Allocate(
            request.json['orderid'],
            request.json['sku'],