def test_add__already_applied(self, *, manager): bp1 = Blueprint("test1") manager.applied = True with pytest.raises(RuntimeError): manager.add("/v1", bp1)
from itertools import count import pytest import faust from faust.web import Blueprint, View DEFAULT_TIMEOUT = 361.363 VIEW_B_TIMEOUT = 64.3 blueprint = Blueprint('test') cache = blueprint.cache(timeout=DEFAULT_TIMEOUT) class ResponseModel(faust.Record): key: str value: int @blueprint.route('/A/', name='a') class ACachedView(View): def __post_init__(self) -> None: self.counter = count() @cache.view() async def get(self, request): return await self._next_response(request) async def _next_response(self, request): cache_key = cache.key_for_request(request, None, request.method) return self.json( ResponseModel(
def test_add(self, *, manager): bp1 = Blueprint("test1") manager.add("/v1/", bp1) assert manager._enabled assert manager._enabled[0] == ("/v1/", bp1)
def test_add(self, *, manager): bp1 = Blueprint('test1') manager.add('/v1/', bp1) assert manager._enabled assert manager._enabled[0] == ('/v1/', bp1)
from itertools import count import aredis import pytest from mode.utils.mocks import Mock import faust from faust.exceptions import ImproperlyConfigured from faust.web import Blueprint, View from faust.web.cache import backends from faust.web.cache.backends import redis DEFAULT_TIMEOUT = 361.363 VIEW_B_TIMEOUT = 64.3 blueprint = Blueprint("test") cache = blueprint.cache(timeout=None) class ResponseModel(faust.Record): key: str value: int @blueprint.route("/A/", name="a") class ACachedView(View): def __post_init__(self) -> None: self.counter = count() @cache.view(timeout=DEFAULT_TIMEOUT) async def get(self, request):
from typing import Any from faust.web import View, Blueprint, Request, Response from faust_app.mifos import agent, MifosEvent hook = Blueprint('hook') @hook.route('/mifos/') class Hooks(View): count: int = 0 async def get(self, request: Request, **kwargs: Any) -> Response: return self.json({'count': self.count}) async def post(self, request: Request, **kwargs: Any) -> Response: payload = await request.json() headers = request.headers entity = headers['X-FINERACT-ENTITY'] action = headers['X-FINERACT-ACTION'] event = MifosEvent(id=payload['resourceId'], entity=entity, action=action, payload=payload) await agent.send(value=event) return self.json({'status': 'success'})
from typing import Any from faust.web import View, Blueprint, Request, Response from faust_app.mpesa import agent, Transaction mpesa_blueprint = Blueprint('mpesa') @mpesa_blueprint.route('/callback/') class M_Pesa(View): async def post(self, request: Request, **kwargs: Any) -> Response: payload = await request.json() transaction = Transaction(id=payload['id']) await agent.send(key=transaction.id, value=transaction) return self.json({'status': 'success'})
from itertools import count import aredis import pytest import faust from faust.exceptions import ImproperlyConfigured from faust.web import Blueprint, View from faust.web.cache import backends from faust.web.cache.backends import redis from mode.utils.mocks import Mock DEFAULT_TIMEOUT = 361.363 VIEW_B_TIMEOUT = 64.3 blueprint = Blueprint('test') cache = blueprint.cache(timeout=None) class ResponseModel(faust.Record): key: str value: int @blueprint.route('/A/', name='a') class ACachedView(View): def __post_init__(self) -> None: self.counter = count() @cache.view(timeout=DEFAULT_TIMEOUT) async def get(self, request): return await self._next_response(request)