def db_failing_manager(): class FailingDatabase(Database): def store_call(self, call): raise DatabaseError('boom!') database = FailingDatabase() queue_service = QueueService() return WorkflowManager(database, queue_service)
def test_get_call(unbounded_service): service = QueueService() call = 'call 1' call2 = 'call 2' service.put(call) service.put(call2) assert service.get() == call assert service.get() == call2
def test_limited_queue(): limited_service = QueueService(max_calls=1) call = 'a call' limited_service.put(call) with pytest.raises(QueueFullError): limited_service.put(call)
def unbounded_service(): return QueueService()
def full_service(): service = QueueService(max_calls=1) service.put('something') return service
def queue_full_manager(database): full_queue = QueueService(max_calls=1) full_queue.put('cid') return WorkflowManager(database, full_queue)
def workflow_manager(database): queue_service = QueueService() return WorkflowManager(database, queue_service)
from flask import Flask, jsonify, request, logging from callqueue.domain import parse_call from callqueue.handler import WorkflowManager from callqueue.database import InMemoryDatabase from callqueue.queueservice import QueueService app = Flask(__name__) manager = WorkflowManager(InMemoryDatabase(), QueueService(), logger=logging.create_logger(app)) @app.route('/') def index(): return 'Hello World!' @app.route('/queue', methods=['POST']) def queue_call(): body = request.json caller = parse_call(body) response = manager.greet_caller(caller) return jsonify(response)